From 5bd780f6a390692682246de54dc222a7898c4233 Mon Sep 17 00:00:00 2001 From: Jim Meyering Date: Wed, 27 Aug 2003 11:41:49 +0000 Subject: (paste_parallel): Don't output `EOF' (aka -1) as a `char'. This would happen for nonempty files not ending with a newline. --- src/paste.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'src') 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); + } } } } -- cgit v1.2.3-70-g09d2