]> diplodocus.org Git - nmh/commitdiff
Close FILE pointer in anno for -append as well as -delete.
authorRalph Corderoy <ralph@inputplus.co.uk>
Mon, 17 Oct 2016 22:52:00 +0000 (23:52 +0100)
committerRalph Corderoy <ralph@inputplus.co.uk>
Mon, 17 Oct 2016 22:52:00 +0000 (23:52 +0100)
https://savannah.nongnu.org/bugs/?23465 has Peter Maydell pointing out
the assymetric open and close of a FILE pointer.  He's right on that
AFAICS so change the test to be for a non-NULL pointer rather than the
more wordy and prone to error flag-testing.

uip/annosbr.c

index 63d2ee4..a763746 100644 (file)
@@ -395,10 +395,8 @@ annosbr (int fd, char *file, char *comp, char *text, int inplace, int datesw, in
      * copying routine uses the descriptor, not the pointer.
      */
 
-    if (append || delete >= -1) {
-       if (lseek(fd, (off_t)ftell(fp), SEEK_SET) == (off_t)-1)
-           adios(NULL, "can't seek.");
-    }
+    if (fp && lseek(fd, (off_t)ftell(fp), SEEK_SET) == (off_t)-1)
+        adios(NULL, "can't seek.");
 
     cpydata (fd, fileno (tmp), file, tmpfil);
     fclose (tmp);
@@ -446,7 +444,7 @@ annosbr (int fd, char *file, char *comp, char *text, int inplace, int datesw, in
      * lkclose() fail, but that failure is ignored so it's not a problem.
      */
 
-    if (delete >= -1)
+    if (fp)
        (void)fclose(fp);
 
     return 0;