summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorEric Blake <eblake@redhat.com>2011-04-30 15:40:00 -0600
committerEric Blake <eblake@redhat.com>2011-04-30 16:59:18 -0600
commit096d7e1c450cff94143fd0681439ab42a3a63079 (patch)
treeb4526e99b8fc1a0659f504a5e36c741791c36ee1 /lib
parenta7982f61a1c485f7ea7dd6660b9c87d505ac9c47 (diff)
downloadgnulib-096d7e1c450cff94143fd0681439ab42a3a63079.tar.gz
fclose: don't fail on non-seekable input stream
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>
Diffstat (limited to 'lib')
-rw-r--r--lib/fclose.c6
1 files changed, 5 insertions, 1 deletions
diff --git a/lib/fclose.c b/lib/fclose.c
index 1d7e85b668..bce409c960 100644
--- a/lib/fclose.c
+++ b/lib/fclose.c
@@ -22,6 +22,8 @@
#include <errno.h>
#include <unistd.h>
+#include "freading.h"
+
/* Override fclose() to call the overridden close(). */
int
@@ -30,7 +32,9 @@ rpl_fclose (FILE *fp)
{
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)