]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
pinky: don't print output in the wrong order when fully buffered master
authorCollin Funk <collin.funk1@gmail.com>
Wed, 29 Apr 2026 01:28:25 +0000 (18:28 -0700)
committerCollin Funk <collin.funk1@gmail.com>
Wed, 29 Apr 2026 01:28:25 +0000 (18:28 -0700)
* NEWS: Mention the bug fix.
* src/pinky.c (cat_file): Prefer streams to file descriptors when
writing to standard output.

NEWS
src/pinky.c

diff --git a/NEWS b/NEWS
index d783176691294f41ff2838d8fec351fe1a823bd3..8bab3d6a8ebfd01c8494582615dbf4592723544f 100644 (file)
--- 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]
 
index 625c426ba296195413a05f21ee3152cc46b3a072..d336c51c7487de2302ebafe49e7cd3f731a50f15 100644 (file)
@@ -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);