From 85c95036256427f5cab8ab50654fe81a5449d09a Mon Sep 17 00:00:00 2001 From: Rob Landley Date: Sun, 19 Jun 2022 03:49:36 -0500 Subject: [PATCH] Make cmp's TEST_HOST pass on current debin, adjusting command behavior to match. --- tests/cmp.test | 9 ++++++--- toys/posix/cmp.c | 18 ++++++++++-------- 2 files changed, 16 insertions(+), 11 deletions(-) diff --git a/tests/cmp.test b/tests/cmp.test index ce776e8e..9a3da335 100755 --- a/tests/cmp.test +++ b/tests/cmp.test @@ -22,7 +22,8 @@ c" > input2 testcmd "identical files, stdout" "input input2" "" "ab\nc\n" "" testcmd "identical files, return code" "input input2 && echo yes" "yes\n" "ab\nc\n" "" -testcmd "EOF, stderr" "input input2 2>&1" "cmp: EOF on input2\n" "ab\nc\nx" "" +testcmd "EOF, stderr" "input input2 2>&1" \ + "cmp: EOF on input2 after byte 5, line 2\n" "ab\nc\nx" "" testcmd "EOF, return code" "input input2 2>/dev/null || echo yes" "yes\n" "ab\nc\nx" "" # The gnu/dammit version fails this because posix says "char" and they don't. testcmd "diff, stdout" "input input2 | sed s/byte/char/" \ @@ -32,8 +33,10 @@ testcmd "diff, return code" "input input2 > /dev/null || echo yes" "yes\n" "ab\n testcmd "-s EOF, return code" "-s input input2 2>&1 || echo yes" "yes\n" "ab\nc\nx" "" testcmd "-s diff, return code" "-s input input2 2>&1 || echo yes" "yes\n" "ab\nx\nx" "" -testcmd "-l EOF, stderr" "-l input input2 2>&1" "cmp: EOF on input2\n" "ab\nc\nx" "" -testcmd "-l diff and EOF, stdout and stderr" "-l input input2 2>&1 | sort" "4 170 143\ncmp: EOF on input2\n" "ab\nx\nx" "" +testcmd "-l EOF, stderr" "-l input input2 2>&1" \ + "cmp: EOF on input2 after byte 5\n" "ab\nc\nx" "" +testcmd "-l diff and EOF, stdout and stderr" "-l input input2 2>&1 | sort" \ + "4 170 143\ncmp: EOF on input2 after byte 5\n" "ab\nx\nx" "" testcmd "-s not exist" "-s input doesnotexist 2>&1 || echo yes" "yes\n" "x" "" diff --git a/toys/posix/cmp.c b/toys/posix/cmp.c index 8e33c92d..003e6dfe 100644 --- a/toys/posix/cmp.c +++ b/toys/posix/cmp.c @@ -34,11 +34,10 @@ GLOBALS( static void do_cmp(int fd, char *name) { int i, len1, len2, min_len, size = sizeof(toybuf)/2; - long byte_no = 1, line_no = 1; + long long byte_no = 1, line_no = 1; char *buf2 = toybuf+size; - if (toys.optc>(i = 2+!!TT.fd) && lskip(fd, atolx(toys.optargs[i]))) - error_exit("EOF on %s", name); + if (toys.optc>(i = 2+!!TT.fd)) lskip(fd, atolx(toys.optargs[i])); // First time through, cache the data and return. if (!TT.fd) { @@ -56,12 +55,12 @@ static void do_cmp(int fd, char *name) len1 = readall(TT.fd, toybuf, size); len2 = readall(fd, buf2, size); min_len = minof(len1, len2); - for (i=0; i