summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJim Meyering <jim@meyering.net>2003-08-27 11:41:49 +0000
committerJim Meyering <jim@meyering.net>2003-08-27 11:41:49 +0000
commit5bd780f6a390692682246de54dc222a7898c4233 (patch)
tree6eef2b817b4dccca694a89a478efa00f267c64c9 /src
parent94b763cc88dea5cbef01067ea3eaf0860f027e7e (diff)
downloadcoreutils-5bd780f6a390692682246de54dc222a7898c4233.tar.xz
(paste_parallel): Don't output `EOF' (aka -1) as a `char'.
This would happen for nonempty files not ending with a newline.
Diffstat (limited to 'src')
-rw-r--r--src/paste.c9
1 files changed, 7 insertions, 2 deletions
diff --git a/src/paste.c b/src/paste.c
index dfc46cafc..a41709381 100644
--- a/src/paste.c
+++ b/src/paste.c
@@ -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);
+ }
}
}
}