diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2018-04-29 14:05:43 +0200 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2018-04-29 14:05:43 +0200 |
commit | d80eecb86812c1fbda652f9b995060c26ba0b155 (patch) | |
tree | 90b1282970b7af2e1adcf235702dead15f156bb0 | |
parent | bc2e70b4a25e58264cdc236803c32f5a9a0c7e4c (diff) | |
download | busybox-w32-d80eecb86812c1fbda652f9b995060c26ba0b155.tar.gz busybox-w32-d80eecb86812c1fbda652f9b995060c26ba0b155.tar.bz2 busybox-w32-d80eecb86812c1fbda652f9b995060c26ba0b155.zip |
cat: fix cat -e and cat -v erroneously numbering 1st line
function old new delta
cat_main 418 421 +3
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r-- | coreutils/cat.c | 6 | ||||
-rwxr-xr-x | testsuite/cat.tests | 21 |
2 files changed, 24 insertions, 3 deletions
diff --git a/coreutils/cat.c b/coreutils/cat.c index 5f02233ca..fb735f994 100644 --- a/coreutils/cat.c +++ b/coreutils/cat.c | |||
@@ -112,10 +112,10 @@ static int catv(unsigned opts, char **argv) | |||
112 | int retval = EXIT_SUCCESS; | 112 | int retval = EXIT_SUCCESS; |
113 | int fd; | 113 | int fd; |
114 | #if ENABLE_FEATURE_CATN | 114 | #if ENABLE_FEATURE_CATN |
115 | unsigned lineno = 0; | 115 | bool eol_seen = (opts & (CAT_OPT_n|CAT_OPT_b)); |
116 | unsigned eol_char = (opts & (CAT_OPT_n|CAT_OPT_b)) ? '\n' : 0x100; | 116 | unsigned eol_char = (eol_seen ? '\n' : 0x100); |
117 | unsigned skip_num_on = (opts & CAT_OPT_b) ? '\n' : 0x100; | 117 | unsigned skip_num_on = (opts & CAT_OPT_b) ? '\n' : 0x100; |
118 | bool eol_seen = 1; | 118 | unsigned lineno = 0; |
119 | #endif | 119 | #endif |
120 | 120 | ||
121 | BUILD_BUG_ON(CAT_OPT_e != VISIBLE_ENDLINE); | 121 | BUILD_BUG_ON(CAT_OPT_e != VISIBLE_ENDLINE); |
diff --git a/testsuite/cat.tests b/testsuite/cat.tests new file mode 100755 index 000000000..404ebedeb --- /dev/null +++ b/testsuite/cat.tests | |||
@@ -0,0 +1,21 @@ | |||
1 | #!/bin/sh | ||
2 | |||
3 | # Copyright 2018 by Denys Vlasenko <vda.linux@googlemail.com> | ||
4 | # Licensed under GPLv2, see file LICENSE in this source tree. | ||
5 | |||
6 | . ./testing.sh | ||
7 | |||
8 | # testing "description" "command" "result" "infile" "stdin" | ||
9 | testing 'cat -e' \ | ||
10 | 'cat -e' \ | ||
11 | 'foo$\n' \ | ||
12 | '' \ | ||
13 | 'foo\n' | ||
14 | |||
15 | testing 'cat -v' \ | ||
16 | 'cat -v' \ | ||
17 | 'foo\n' \ | ||
18 | '' \ | ||
19 | 'foo\n' | ||
20 | |||
21 | exit $FAILCOUNT | ||