]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
(paste_parallel): Don't output `EOF' (aka -1) as a `char'.
authorJim Meyering <jim@meyering.net>
Wed, 27 Aug 2003 11:41:49 +0000 (11:41 +0000)
committerJim Meyering <jim@meyering.net>
Wed, 27 Aug 2003 11:41:49 +0000 (11:41 +0000)
This would happen for nonempty files not ending with a newline.

src/paste.c

index dfc46cafc2fe2af4fa5275452159e9063bcf70ec..a417093811546d006f95533513cfcb8120d69528 100644 (file)
@@ -294,7 +294,7 @@ paste_parallel (int nfiles, char **fnamptr)
              /* Except for last file, replace last newline with delim. */
              if (fileptr[i + 1] != ENDLIST)
                {
-                 if (chr != '\n')
+                 if (chr != '\n' && chr != EOF)
                    putc (chr, stdout);
                  if (*delimptr != EMPTY_DELIM)
                    putc (*delimptr, stdout);
@@ -302,7 +302,12 @@ paste_parallel (int nfiles, char **fnamptr)
                    delimptr = delims;
                }
              else
-               putc (chr, stdout);
+               {
+                 /* If the last line of the last file lacks a newline,
+                    print one anyhow.  POSIX requires this.  */
+                 char c = (chr == EOF ? '\n' : chr);
+                 putc (c, stdout);
+               }
            }
        }
     }