]> granicus.if.org Git - mutt/commitdiff
Add error checking to the recode-attachment code. From "Andrew W.
authorThomas Roessler <roessler@does-not-exist.org>
Tue, 29 Feb 2000 22:30:09 +0000 (22:30 +0000)
committerThomas Roessler <roessler@does-not-exist.org>
Tue, 29 Feb 2000 22:30:09 +0000 (22:30 +0000)
Nosenko" <awn@bcs.zp.ua>.

charset.c

index a62115a9189c74477fc1ace174d46ed4441369ac..de2484fc823d81dca515d63ea413cc9f4ec95d0a 100644 (file)
--- a/charset.c
+++ b/charset.c
@@ -1055,6 +1055,7 @@ int mutt_recode_file (const char *fname, const char *src, const char *dest)
   char tmp[1024];
   int c;
   int rv = -1;
+  int source_file_is_unchanged = 1;
 
   size_t lf, lpu, lpo;
   char *t;
@@ -1093,17 +1094,28 @@ int mutt_recode_file (const char *fname, const char *src, const char *dest)
       {
        mutt_decoder_pop (dec, tmp, sizeof (tmp), &lpo);
        if (lpo)
-         fwrite (tmp, lpo, 1, tmpfp);
+       {
+         if (fwrite (tmp, lpo, 1, tmpfp) == EOF)
+           goto bail;
+       }
       } 
       while (lpo);
     }
   }
+  if (lf == EOF && !feof(fp))
+  {
+    goto bail;
+  }
 
   mutt_decoder_push (dec, NULL, 0, NULL);
   do 
   {
     mutt_decoder_pop (dec, tmp, sizeof (tmp), &lpo);
-    if (lpo) fwrite (tmp, lpo, 1, tmpfp);
+    if (lpo)
+    {
+      if (fwrite (tmp, lpo, 1, tmpfp) == EOF)
+       goto bail;
+    }
   }
   while (lpo);
 
@@ -1112,10 +1124,12 @@ int mutt_recode_file (const char *fname, const char *src, const char *dest)
   fclose (fp); fp = NULL;
   rewind (tmpfp);
 
+
+  source_file_is_unchanged = 0;
+
   /* don't use safe_fopen here - we're just going
    * to overwrite the old file.
    */
-
   if ((fp = fopen (fname, "w")) == NULL)
     goto bail;
   
@@ -1128,8 +1142,20 @@ int mutt_recode_file (const char *fname, const char *src, const char *dest)
   
 bail:
   if (rv == -1)
-    mutt_error (_("Error while recoding %s. See %s for recovering your data."),
-               fname, tempfile);
+  {
+    if (source_file_is_unchanged)
+    {
+      mutt_error (_("Error while recoding %s. "
+                   "Leave it unchanged."),
+                 fname);
+    }
+    else
+    {
+      mutt_error (_("Error while recoding %s. "
+                   "See %s for recovering your data."),
+                 fname, tempfile);
+    }
+  }
 
   if (fp) fclose (fp);
   if (tmpfp) fclose (tmpfp);