aboutsummaryrefslogtreecommitdiff
path: root/notmuch-show.c
diff options
context:
space:
mode:
authorAustin Clements <amdragon@MIT.EDU>2012-01-19 17:29:18 -0500
committerDavid Bremner <bremner@debian.org>2012-01-21 08:47:08 -0400
commit18947b95cd1668d1b98f7ea4196e97b050599f7d (patch)
treefe8a1e9eaa31529e7f59133db3a9043bd78a9bb0 /notmuch-show.c
parent3a602dc27aa7a830c0bf00838dfdbb70165858d5 (diff)
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);
Diffstat (limited to 'notmuch-show.c')
-rw-r--r--notmuch-show.c12
1 files changed, 11 insertions, 1 deletions
diff --git a/notmuch-show.c b/notmuch-show.c
index d14dac9..c674e25 100644
--- a/notmuch-show.c
+++ b/notmuch-show.c
@@ -883,7 +883,17 @@ do_show_single (void *ctx,
while (!feof (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);