In a non-GPL project, the last change to fclose dragged in inappropriate modules.
* modules/fclose (Depends-on): Switch from fflush/fseeko to simpler lseek. * lib/fclose.c (rpl_fclose): Likewise. Reported by Simon Josefsson. Signed-off-by: Eric Blake <ebl...@redhat.com> --- > > Would it be equivalent to do > > > > if ((!freading (fp) || ftello (fp) != -1) && fflush (fp)) > > Or even lseek(fileno(fp),0,SEEK_CUR) != -1. This passed my testing of m4 on mingw, so I'm pushing it. I'm also in the middle of writing a test-fclose unit test, as I suspect that a number of implementations disobey the POSIX rule that fclose must set the file position on seekable files to the next unread or unwritten byte, at which point we may want to re-think about whether fclose should depend on fflush (that is, re-visit whether fflush/fpurge should be relicensed). ChangeLog | 8 ++++++++ lib/fclose.c | 6 ++++-- modules/fclose | 3 +-- 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/ChangeLog b/ChangeLog index d6ac179..f884e65 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,11 @@ 2011-05-02 Eric Blake <ebl...@redhat.com> + fclose: reduced dependencies + * modules/fclose (Depends-on): Switch from fflush/fseeko to + simpler lseek. + * lib/fclose.c (rpl_fclose): Likewise. + Reported by Simon Josefsson. + exit: drop remaining clients * modules/argmatch (Depends-on): Replace exit with stdlib. * modules/copy-file (Depends-on): Likewise. diff --git a/lib/fclose.c b/lib/fclose.c index bce409c..c8c2fd8 100644 --- a/lib/fclose.c +++ b/lib/fclose.c @@ -33,8 +33,10 @@ rpl_fclose (FILE *fp) int saved_errno = 0; /* We only need to flush the file if it is not reading or if it is - seekable. */ - if ((!freading (fp) || fseeko (fp, 0, SEEK_CUR) == 0) && fflush (fp)) + seekable. This only guarantees the file position of input files + if the fflush module is also in use. */ + if ((!freading (fp) || lseek (fileno (fp), 0, SEEK_CUR) != -1) + && fflush (fp)) saved_errno = errno; if (close (fileno (fp)) < 0 && saved_errno == 0) diff --git a/modules/fclose b/modules/fclose index d8727c3..434dd73 100644 --- a/modules/fclose +++ b/modules/fclose @@ -8,9 +8,8 @@ m4/fclose.m4 Depends-on: stdio close -fflush freading -fseeko +lseek configure.ac: gl_FUNC_FCLOSE -- 1.7.4.4