From owner-dev-commits-src-all@freebsd.org Sun Oct 3 05:15:48 2021 Return-Path: Delivered-To: dev-commits-src-all@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 047436B0B73; Sun, 3 Oct 2021 05:15:48 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4HMX9v3tdBz4Rk7; Sun, 3 Oct 2021 05:15:47 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 6465420738; Sun, 3 Oct 2021 05:15:47 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 1935Flcd008887; Sun, 3 Oct 2021 05:15:47 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 1935FlGa008886; Sun, 3 Oct 2021 05:15:47 GMT (envelope-from git) Date: Sun, 3 Oct 2021 05:15:47 GMT Message-Id: <202110030515.1935FlGa008886@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Kyle Evans Subject: git: 5d3ac4ddf9db - stable/13 - cmp: accept SI suffixes for skip1 and skip2 MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: kevans X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: 5d3ac4ddf9db8a42968d31f11a8b18cdc198b4ff Auto-Submitted: auto-generated X-BeenThere: dev-commits-src-all@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Commit messages for all branches of the src repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 03 Oct 2021 05:15:48 -0000 The branch stable/13 has been updated by kevans: URL: https://cgit.FreeBSD.org/src/commit/?id=5d3ac4ddf9db8a42968d31f11a8b18cdc198b4ff commit 5d3ac4ddf9db8a42968d31f11a8b18cdc198b4ff Author: Kyle Evans AuthorDate: 2021-09-23 05:17:07 +0000 Commit: Kyle Evans CommitDate: 2021-10-03 05:15:01 +0000 cmp: accept SI suffixes for skip1 and skip2 This is compatible with GNU cmp. Reviewed by: bapt (earlier version), markj, imp Sponsored by: Klara, Inc. (cherry picked from commit f6787614fd4db2a9d5e649af0e819852ebd5a19d) --- usr.bin/cmp/Makefile | 2 ++ usr.bin/cmp/cmp.1 | 16 +++++++++++++++- usr.bin/cmp/cmp.c | 14 ++++++++++++-- usr.bin/cmp/tests/cmp_test2.sh | 17 +++++++++++++++++ 4 files changed, 46 insertions(+), 3 deletions(-) diff --git a/usr.bin/cmp/Makefile b/usr.bin/cmp/Makefile index bcde84f0255a..0392fd368503 100644 --- a/usr.bin/cmp/Makefile +++ b/usr.bin/cmp/Makefile @@ -6,6 +6,8 @@ PROG= cmp SRCS= cmp.c link.c misc.c regular.c special.c +LIBADD= util + HAS_TESTS= SUBDIR.${MK_TESTS}+= tests diff --git a/usr.bin/cmp/cmp.1 b/usr.bin/cmp/cmp.1 index fc05fb893147..6980f73e7be5 100644 --- a/usr.bin/cmp/cmp.1 +++ b/usr.bin/cmp/cmp.1 @@ -31,7 +31,7 @@ .\" @(#)cmp.1 8.1 (Berkeley) 6/6/93 .\" $FreeBSD$ .\" -.Dd June 20, 2020 +.Dd September 23, 2021 .Dt CMP 1 .Os .Sh NAME @@ -86,6 +86,11 @@ and respectively, where the comparison will begin. The offset is decimal by default, but may be expressed as a hexadecimal or octal value by preceding it with a leading ``0x'' or ``0''. +.Pp +.Ar skip1 +and +.Ar skip2 +may also be specified with SI size suffixes. .Sh EXIT STATUS The .Nm @@ -164,8 +169,17 @@ The and .Fl z options are extensions to the standard. +.Ar skip1 +and +.Ar skip2 +arguments are extensions to the standard. .Sh HISTORY A .Nm command appeared in .At v1 . +.Sh BUGS +The phrase +.Dq SI size suffixes +above refers to the traditional power of two convention, as described in +.Xr expand_number 3 . diff --git a/usr.bin/cmp/cmp.c b/usr.bin/cmp/cmp.c index 47f9b671985c..bab69125e83e 100644 --- a/usr.bin/cmp/cmp.c +++ b/usr.bin/cmp/cmp.c @@ -58,6 +58,8 @@ __FBSDID("$FreeBSD$"); #include #include +#include + #include "extern.h" bool lflag, sflag, xflag, zflag; @@ -81,6 +83,7 @@ main(int argc, char *argv[]) bool special; const char *file1, *file2; + skip1 = skip2 = 0; oflag = O_RDONLY; while ((ch = getopt_long(argc, argv, "+hlsxz", long_opts, NULL)) != -1) switch (ch) { @@ -145,8 +148,15 @@ main(int argc, char *argv[]) exit(ERR_EXIT); } - skip1 = argc > 2 ? strtol(argv[2], NULL, 0) : 0; - skip2 = argc == 4 ? strtol(argv[3], NULL, 0) : 0; + if (argc > 2 && expand_number(argv[2], &skip1) < 0) { + fprintf(stderr, "Invalid skip1: %s\n", argv[2]); + usage(); + } + + if (argc == 4 && expand_number(argv[3], &skip2) < 0) { + fprintf(stderr, "Invalid skip2: %s\n", argv[3]); + usage(); + } if (sflag && skip1 == 0 && skip2 == 0) zflag = true; diff --git a/usr.bin/cmp/tests/cmp_test2.sh b/usr.bin/cmp/tests/cmp_test2.sh index 7f9801fc92bd..334e9f357730 100755 --- a/usr.bin/cmp/tests/cmp_test2.sh +++ b/usr.bin/cmp/tests/cmp_test2.sh @@ -75,9 +75,26 @@ pr252542_body() atf_check -s exit:1 -o ignore cmp -z a b 4 3 } +atf_test_case skipsuff +skipsuff_head() +{ + atf_set "descr" "Test cmp(1) accepting SI suffixes on skips" +} +skipsuff_body() +{ + + jot -nb a -s '' 1028 > a + jot -nb b -s '' 1024 > b + jot -nb a -s '' 4 >> b + + atf_check -s exit:1 -o ignore cmp -s a b + atf_check -s exit:0 cmp -s a b 1k 1k +} + atf_init_test_cases() { atf_add_test_case special atf_add_test_case symlink atf_add_test_case pr252542 + atf_add_test_case skipsuff }