summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJim Meyering <jim@meyering.net>1995-06-13 04:46:12 +0000
committerJim Meyering <jim@meyering.net>1995-06-13 04:46:12 +0000
commit1aa5954b420948565a5e5bf1167255aead1c0f47 (patch)
tree7f2be79b7d25a902a3666077da16cb9bdd150cf2
parent46a1fec4a50d461810c008d6bcf60bfb8dd13d91 (diff)
downloadcoreutils-1aa5954b420948565a5e5bf1167255aead1c0f47.tar.xz
(xfclose): Don't try to flush stdin, only stdout.
Otherwise, at least Ultrix-4.3's fflush would return EOF. Reported by Jim Blandy (jimb@cyclic.com).
-rw-r--r--src/sort.c23
1 files changed, 13 insertions, 10 deletions
diff --git a/src/sort.c b/src/sort.c
index da7e0034b..a216e6bba 100644
--- a/src/sort.c
+++ b/src/sort.c
@@ -266,26 +266,29 @@ static void
xfclose (fp)
FILE *fp;
{
- if (fflush (fp) != 0)
+ if (fp == stdin)
{
- error (0, errno, "flushing file");
- cleanup ();
- exit (2);
+ /* Allow reading stdin from tty more than once. */
+ if (feof (fp))
+ clearerr (fp);
}
-
- if (fp != stdin && fp != stdout)
+ else if (fp == stdout)
{
- if (fclose (fp) != 0)
+ if (fflush (fp) != 0)
{
- error (0, errno, "error closing file");
+ error (0, errno, "flushing file");
cleanup ();
exit (2);
}
}
else
{
- /* Allow reading stdin from tty more than once. */
- clearerr (fp);
+ if (fclose (fp) != 0)
+ {
+ error (0, errno, "error closing file");
+ cleanup ();
+ exit (2);
+ }
}
}