On mingw, for a project that uses both sockets and streams,
then fclose(stdin) when getting input from a terminal or pipe
was spuriously failing.
* modules/fclose (Depends-on): Add freading, fflush, fseeko.
* lib/fclose.c (rpl_fclose): Skip fflush for non-seekable input,
since fflush is allowed to fail in that case.
Signed-off-by: Eric Blake <eblake@redhat.com>
+2011-04-30 Eric Blake <eblake@redhat.com>
+
+ fclose: don't fail on non-seekable input stream
+ * modules/fclose (Depends-on): Add freading, fflush, fseeko.
+ * lib/fclose.c (rpl_fclose): Skip fflush for non-seekable input,
+ since fflush is allowed to fail in that case.
+
2011-04-30 Bruno Haible <bruno@clisp.org>
dup3: cleanup
#include <errno.h>
#include <unistd.h>
+#include "freading.h"
+
/* Override fclose() to call the overridden close(). */
int
{
int saved_errno = 0;
- if (fflush (fp))
+ /* 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))
saved_errno = errno;
if (close (fileno (fp)) < 0 && saved_errno == 0)
Depends-on:
stdio
close
+fflush
+freading
+fseeko
configure.ac:
gl_FUNC_FCLOSE