diff options
author | Sami Kerola | 2013-06-02 19:51:16 +0200 |
---|---|---|
committer | Karel Zak | 2013-06-07 12:24:46 +0200 |
commit | 7c7061f7713e47b435ce1924b225fb64d1ae56d5 (patch) | |
tree | 790cc3dff7ea7aed2134d77d9c6e6a838e8e14ed | |
parent | docs: add lscpu max mhz to manual and bash completion (diff) | |
download | kernel-qcow2-util-linux-7c7061f7713e47b435ce1924b225fb64d1ae56d5.tar.gz kernel-qcow2-util-linux-7c7061f7713e47b435ce1924b225fb64d1ae56d5.tar.xz kernel-qcow2-util-linux-7c7061f7713e47b435ce1924b225fb64d1ae56d5.zip |
rev: stop adding new line at the end when input does not have it
When the rev(1) is executed twice outcome is expected to be exactly what
it was originally. That includes not adding new line at the end of the
output. The oneliner below demonstrates earlier issue.
$ printf "abc\n123" | rev | rev
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
-rw-r--r-- | tests/expected/misc/rev | 4 | ||||
-rwxr-xr-x | tests/ts/misc/rev | 2 | ||||
-rw-r--r-- | text-utils/rev.c | 3 |
3 files changed, 7 insertions, 2 deletions
diff --git a/tests/expected/misc/rev b/tests/expected/misc/rev index 263923f75..41fdf4c13 100644 --- a/tests/expected/misc/rev +++ b/tests/expected/misc/rev @@ -1,2 +1,4 @@ 53bbf0d98205319cee2ba589e205c68b - -b407c257ed73b43cb992e778f925f7a3 - +35484965b7a2fd45a471c0d80cb9752c - +cba +321
\ No newline at end of file diff --git a/tests/ts/misc/rev b/tests/ts/misc/rev index f36a799b2..035ce8230 100755 --- a/tests/ts/misc/rev +++ b/tests/ts/misc/rev @@ -23,4 +23,6 @@ for I in {0..512}; do printf "%s " {a..z}; done | md5sum >> $TS_OUTPUT 2>&1 for I in {0..512}; do printf "%s " {a..z}; done | \ $TS_CMD_REV | md5sum >> $TS_OUTPUT 2>&1 +printf "abc\n123" | $TS_CMD_REV >> $TS_OUTPUT 2>&1 + ts_finalize diff --git a/text-utils/rev.c b/text-utils/rev.c index 95545064a..0456c2b14 100644 --- a/text-utils/rev.c +++ b/text-utils/rev.c @@ -159,7 +159,8 @@ int main(int argc, char *argv[]) if (*t != 0) putwchar(*t); } - putwchar('\n'); + if (!feof(fp)) + putwchar('\n'); } fflush(fp); |