--- mlocate-0.18/gnulib/lib/fwriteerror.c.bak 2007-08-25 01:46:08.000000000 +0300 +++ mlocate-0.18/gnulib/lib/fwriteerror.c 2007-09-04 00:53:08.113464268 +0300 @@ -23,12 +23,14 @@ #include #include +#include static int do_fwriteerror (FILE *fp, bool ignore_ebadf) { /* State to allow multiple calls to fwriteerror (stdout). */ static bool stdout_closed = false; + int saved_errno; if (fp == stdout) { @@ -71,11 +73,23 @@ do_fwriteerror (FILE *fp, bool ignore_eb done on FP. */ if (fflush (fp)) goto close_preserving_errno; /* errno is set here */ + if ((fsync(fileno(fp)) == -1) && (errno != EINVAL)) { + saved_errno = errno; + fclose (fp); + errno = saved_errno; + return -1; + } if (fclose (fp) && errno != EBADF) return -1; /* errno is set here */ } else { + if ((fsync(fileno(fp)) == -1) && (errno != EINVAL)) { + saved_errno = errno; + fclose (fp); + errno = saved_errno; + return -1; + } if (fclose (fp)) return -1; /* errno is set here */ } @@ -85,12 +99,10 @@ do_fwriteerror (FILE *fp, bool ignore_eb close_preserving_errno: /* There's an error. Nevertheless call fclose(fp), for consistency with the other cases. */ - { - int saved_errno = errno; - fclose (fp); - errno = saved_errno; - return -1; - } + saved_errno = errno; + fclose (fp); + errno = saved_errno; + return -1; } int