[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: paste(1) adds a \377 to files with no final newline.
From: |
Jim Meyering |
Subject: |
Re: paste(1) adds a \377 to files with no final newline. |
Date: |
Wed, 27 Aug 2003 22:20:40 +0200 |
Dan Jacobson <address@hidden> wrote:
> I have discovered paste(1) adds a \377 to files with no final newline.
> Try this:
> echo -e '1\n2\c' >f
> echo -e '1\n2' >g
> paste f g|od -c
Thank you for reporting that bug!
Here's what I've done to fix it:
* src/paste.c (paste_parallel): Don't output `EOF' (aka -1) as a `char'.
This would happen for nonempty files not ending with a newline.
Reported by Dan Jacobson.
* tests/misc/paste-no-nl: New file. Test for above-fixed bug.
* tests/misc/Makefile.am (TESTS): Add paste-no-nl.
Index: src/paste.c
===================================================================
RCS file: /fetish/cu/src/paste.c,v
retrieving revision 1.61
retrieving revision 1.62
diff -u -p -u -r1.61 -r1.62
--- src/paste.c 23 Jul 2003 07:29:54 -0000 1.61
+++ src/paste.c 27 Aug 2003 11:41:49 -0000 1.62
@@ -294,7 +294,7 @@ paste_parallel (int nfiles, char **fnamp
/* 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 **fnamp
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);
+ }
}
}
}