]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
Use fwrite insted of write.
authorJim Meyering <jim@meyering.net>
Tue, 11 Jan 1994 05:50:45 +0000 (05:50 +0000)
committerJim Meyering <jim@meyering.net>
Tue, 11 Jan 1994 05:50:45 +0000 (05:50 +0000)
src/tac.c

index c295de444f0ca89f570420d325c78f467b9022b9..38008acd8f125d9612e3f370ad9de4e734ce1361 100644 (file)
--- a/src/tac.c
+++ b/src/tac.c
@@ -75,7 +75,6 @@ static char *xmalloc ();
 static char *xrealloc ();
 static void output ();
 static void save_stdin ();
-static void xwrite ();
 
 void error ();
 int full_write ();
@@ -251,13 +250,12 @@ main (argc, argv)
          errors |= tac_file (argv[optind]);
       }
 
-  /* Flush the output buffer. */
-  output ((char *) NULL, (char *) NULL);
+  if (ferror (stdout) || fclose (stdout) == EOF)
+    error (1, errno, "write error");
 
   if (have_read_stdin && close (0) < 0)
     error (1, errno, "-");
-  if (close (1) < 0)
-    error (1, errno, "write error");
+
   exit (errors);
 }
 
@@ -602,31 +600,11 @@ output (start, past_end)
      char *start;
      char *past_end;
 {
-  static char buffer[WRITESIZE];
-  static int bytes_in_buffer = 0;
-  int bytes_to_add = past_end - start;
-  int bytes_available = WRITESIZE - bytes_in_buffer;
-
-  if (start == 0)
-    {
-      xwrite (1, buffer, bytes_in_buffer);
-      bytes_in_buffer = 0;
-      return;
-    }
-
-  /* Write out as many full buffers as possible. */
-  while (bytes_to_add >= bytes_available)
-    {
-      bcopy (start, buffer + bytes_in_buffer, bytes_available);
-      bytes_to_add -= bytes_available;
-      start += bytes_available;
-      xwrite (1, buffer, WRITESIZE);
-      bytes_in_buffer = 0;
-      bytes_available = WRITESIZE;
-    }
+  int n_bytes;
 
-  bcopy (start, buffer + bytes_in_buffer, bytes_to_add);
-  bytes_in_buffer += bytes_to_add;
+  n_bytes = past_end - start;
+  
+  fwrite (start, 1, n_bytes, stdout);
 }
 
 static RETSIGTYPE
@@ -636,19 +614,6 @@ cleanup ()
   exit (1);
 }
 
-static void
-xwrite (desc, buffer, size)
-     int desc;
-     char *buffer;
-     int size;
-{
-  if (full_write (desc, buffer, size) < 0)
-    {
-      error (0, errno, "write error");
-      cleanup ();
-    }
-}
-
 /* Allocate N bytes of memory dynamically, with error checking.  */
 
 static char *