From: Collin Funk Date: Wed, 29 Apr 2026 01:28:25 +0000 (-0700) Subject: pinky: don't print output in the wrong order when fully buffered X-Git-Url: http://git.ipfire.org/gitweb/?a=commitdiff_plain;ds=inline;p=thirdparty%2Fcoreutils.git pinky: don't print output in the wrong order when fully buffered * NEWS: Mention the bug fix. * src/pinky.c (cat_file): Prefer streams to file descriptors when writing to standard output. --- diff --git a/NEWS b/NEWS index d78317669..8bab3d6a8 100644 --- a/NEWS +++ b/NEWS @@ -8,6 +8,10 @@ GNU coreutils NEWS -*- outline -*- mistakenly exit with a nonzero status. [This bug was present in "the beginning".] + 'pinky -l' no longer no longer prints output in the incorrect order when + standard output is fully buffered, e.g., when redirected to a file. + [bug introduced in coreutils-9.10] + 'uniq -w' no longer overruns the read buffer in multibyte locales. [bug introduced in coreutils-9.5] diff --git a/src/pinky.c b/src/pinky.c index 625c426ba..d336c51c7 100644 --- a/src/pinky.c +++ b/src/pinky.c @@ -318,22 +318,21 @@ static void cat_file (char const *header, char const *home, char const *file) { char *full_name = file_name_concat (home, file, NULL); - int fd = open (full_name, O_RDONLY); + FILE *fp = fopen (full_name, "r"); - if (0 <= fd) + if (fp) { - idx_t header_len = strlen (header); - if (write (STDOUT_FILENO, header, header_len) != header_len) - write_error (); + fputs (header, stdout); - fdadvise (fd, 0, 0, FADVISE_SEQUENTIAL); + fadvise (fp, FADVISE_SEQUENTIAL); - char buf[IO_BUFSIZE]; - for (ssize_t bytes_read; 0 < (bytes_read = read (fd, buf, sizeof buf));) - if (full_write (STDOUT_FILENO, buf, bytes_read) != bytes_read) + char buf[BUFSIZ]; + for (size_t bytes_read; + 0 < (bytes_read = fread (buf, 1, sizeof buf, fp));) + if (fwrite (buf, 1, bytes_read, stdout) != bytes_read) write_error (); - close (fd); + fclose (fp); } free (full_name);