]> sjero.net Git - wget/blobdiff - src/ftp.c
[svn] Committed my patch from <dpd7mj3sap.fsf@mraz.iskon.hr>.
[wget] / src / ftp.c
index 9a7f33d81a13627d4c6135355a64bc09c21a174e..ef611d32df7c936a76577fdaf930100bdcb65d00 100644 (file)
--- a/src/ftp.c
+++ b/src/ftp.c
@@ -711,10 +711,18 @@ Error in server response, closing control connection.\n"));
   /* Close data connection socket.  */
   closeport (dtsock);
   /* Close the local file.  */
-  if (!opt.dfp || con->cmd & DO_LIST)
-    fclose (fp);
-  else
-    fflush (fp);
+  {
+    /* Close or flush the file.  We have to be careful to check for
+       error here.  Checking the result of fwrite() is not enough --
+       errors could go unnoticed!  */
+    int flush_res;
+    if (!opt.dfp || con->cmd & DO_LIST)
+      flush_res = fclose (fp);
+    else
+      flush_res = fflush (fp);
+    if (flush_res == EOF)
+      res = -2;
+  }
   /* If get_contents couldn't write to fp, bail out.  */
   if (res == -2)
     {