Page MenuHomeFreeBSD

D32071.diff
No OneTemporary

D32071.diff

diff --git a/usr.bin/cmp/Makefile b/usr.bin/cmp/Makefile
--- 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
--- 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 @@
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 @@
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
--- a/usr.bin/cmp/cmp.c
+++ b/usr.bin/cmp/cmp.c
@@ -58,6 +58,8 @@
#include <string.h>
#include <unistd.h>
+#include <libutil.h>
+
#include "extern.h"
bool lflag, sflag, xflag, zflag;
@@ -81,6 +83,7 @@
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 @@
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
--- a/usr.bin/cmp/tests/cmp_test2.sh
+++ b/usr.bin/cmp/tests/cmp_test2.sh
@@ -75,9 +75,26 @@
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
}

File Metadata

Mime Type
text/plain
Expires
Thu, Jan 16, 4:10 PM (21 h, 11 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
15827074
Default Alt Text
D32071.diff (2 KB)

Event Timeline