From: Ralph Corderoy Date: Mon, 17 Oct 2016 22:52:00 +0000 (+0100) Subject: Close FILE pointer in anno for -append as well as -delete. X-Git-Url: https://diplodocus.org/git/nmh/commitdiff_plain/bca60df6fa13f9418daf3b5442704ad1abf6018a Close FILE pointer in anno for -append as well as -delete. 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. --- diff --git a/uip/annosbr.c b/uip/annosbr.c index 63d2ee44..a763746d 100644 --- a/uip/annosbr.c +++ b/uip/annosbr.c @@ -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;