]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
(xfclose): Don't try to flush stdin, only stdout.
authorJim Meyering <jim@meyering.net>
Tue, 13 Jun 1995 04:46:12 +0000 (04:46 +0000)
committerJim Meyering <jim@meyering.net>
Tue, 13 Jun 1995 04:46:12 +0000 (04:46 +0000)
Otherwise, at least Ultrix-4.3's fflush would return EOF.
Reported by Jim Blandy (jimb@cyclic.com).

src/sort.c

index da7e0034b6f3c7673f8f1235d686ef50a4fe459e..a216e6bbaf73cc88b1fae485a036a0d09a91784a 100644 (file)
@@ -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);
+       }
     }
 }