From: Paul Eggert Date: Sat, 9 Nov 2024 04:17:54 +0000 (-0800) Subject: seq: use full_write instead of fwrite X-Git-Tag: v9.6~85 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=807c51e4fbd8ebfcd5e1c0ecd6f8f50360728869;p=thirdparty%2Fcoreutils.git seq: use full_write instead of fwrite * 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. --- diff --git a/src/seq.c b/src/seq.c index 2049c7803f..da64d185a4 100644 --- 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 (); }