mirror of
https://git.notmuchmail.org/git/notmuch
synced 2024-11-24 20:08:10 +01:00
show: Handle read and write errors
For showing a message in raw format, rather than silently succeeding when a read or a write fails (or, probably, looping if a read fails), try to print an error message and exit with a non-zero status. This silences one of the buildbot warnings about unused results. While my libc lacks the declarations that trigger these warnings, this can be tested by adding the following to notmuch.h: __attribute__((warn_unused_result)) size_t fwrite(const void *ptr, size_t size, size_t nmemb, FILE *stream);
This commit is contained in:
parent
3a602dc27a
commit
18947b95cd
1 changed files with 11 additions and 1 deletions
|
@ -883,7 +883,17 @@ do_show_single (void *ctx,
|
||||||
|
|
||||||
while (!feof (file)) {
|
while (!feof (file)) {
|
||||||
size = fread (buf, 1, sizeof (buf), file);
|
size = fread (buf, 1, sizeof (buf), file);
|
||||||
(void) fwrite (buf, size, 1, stdout);
|
if (ferror (file)) {
|
||||||
|
fprintf (stderr, "Error: Read failed from %s\n", filename);
|
||||||
|
fclose (file);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (fwrite (buf, size, 1, stdout) != 1) {
|
||||||
|
fprintf (stderr, "Error: Write failed\n");
|
||||||
|
fclose (file);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fclose (file);
|
fclose (file);
|
||||||
|
|
Loading…
Reference in a new issue