]> git.notmuchmail.org Git - notmuch/blobdiff - notmuch-show.c
show: Handle read and write errors
[notmuch] / notmuch-show.c
index 87a1c906107742f772d6a7d9ae7ec75a054b0832..c674e2506ff73270f4e43cd3937078ad3aa1b38b 100644 (file)
@@ -677,7 +677,7 @@ format_part_content_json (GMimeObject *part)
 
     if (g_mime_content_type_is_type (content_type, "text", "*"))
     {
-       /* For non-HTML text/* parts, we include the content in the
+       /* For non-HTML text parts, we include the content in the
         * JSON. Since JSON must be Unicode, we handle charset
         * decoding here and do not report a charset to the caller.
         * For text/html parts, we do not include the content. If a
@@ -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);