]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
seq: use full_write instead of fwrite
authorPaul Eggert <eggert@cs.ucla.edu>
Sat, 9 Nov 2024 04:17:54 +0000 (20:17 -0800)
committerPaul Eggert <eggert@cs.ucla.edu>
Sat, 9 Nov 2024 07:41:18 +0000 (23:41 -0800)
* src/seq.c: Include full-write.h.
(seq_fast): Since we’re doing all the buffering work anyway,
we might as well use syscalls instead of stdio to write.
Use full_write instead of fwrite.

src/seq.c

index 2049c7803f02d9ce3e150e49aa40fae7c3fb16c3..da64d185a43a3c05d4c1838656f0cf2da0754035 100644 (file)
--- a/src/seq.c
+++ b/src/seq.c
@@ -24,6 +24,7 @@
 
 #include "system.h"
 #include "cl-strtod.h"
+#include "full-write.h"
 #include "quote.h"
 #include "xstrtod.h"
 
@@ -481,8 +482,8 @@ seq_fast (char const *a, char const *b, uintmax_t step)
   bool ok = inf || cmp (p, p_len, b, b_len) <= 0;
   if (ok)
     {
-      /* Reduce number of fwrite calls which is seen to
-         give a speed-up of more than 2x over the unbuffered code
+      /* Reduce number of write calls which is seen to
+         give a speed-up of more than 2x over naive stdio code
          when printing the first 10^9 integers.  */
       char buf[BUFSIZ];
       char *buf_end = buf + sizeof buf;
@@ -496,7 +497,7 @@ seq_fast (char const *a, char const *b, uintmax_t step)
             {
               memcpy (bufp, pp, buf_end - bufp);
               pp += buf_end - bufp;
-              if (fwrite (buf, sizeof buf, 1, stdout) != 1)
+              if (full_write (STDOUT_FILENO, buf, sizeof buf) != sizeof buf)
                 write_error ();
               bufp = buf;
             }
@@ -524,7 +525,7 @@ seq_fast (char const *a, char const *b, uintmax_t step)
 
       /* Write any remaining buffered output, and the terminator.  */
       *bufp++ = *terminator;
-      if (fwrite (buf, bufp - buf, 1, stdout) != 1)
+      if (full_write (STDOUT_FILENO, buf, bufp - buf) != bufp - buf)
         write_error ();
     }