Page MenuHomeFreeBSD

D32074.id95576.diff
No OneTemporary

D32074.id95576.diff

Index: usr.bin/cmp/cmp.1
===================================================================
--- usr.bin/cmp/cmp.1
+++ usr.bin/cmp/cmp.1
@@ -40,7 +40,7 @@
.Sh SYNOPSIS
.Nm
.Op Fl l | s | x
-.Op Fl hz
+.Op Fl bhz
.Op Fl -ignore-initial Ns Cm = Ns Ar num1 Ns Op :num2
.Op Fl -bytes Ns Cm = Ns Ar num
.Ar file1 file2
@@ -59,6 +59,8 @@
.Pp
The following options are available:
.Bl -tag -width indent
+.It Fl b , Fl -print-bytes
+Print each byte when a difference is found.
.It Fl h
Do not follow symbolic links.
.It Fl i Ar num1 Ns Oo :num2 Oc , Fl -ignore-initial= Ns Ar num1 Ns Op :num2
@@ -187,6 +189,7 @@
.St -p1003.2
compatible.
The
+.Fl b ,
.Fl h ,
.Fl i ,
.Fl n ,
Index: usr.bin/cmp/cmp.c
===================================================================
--- usr.bin/cmp/cmp.c
+++ usr.bin/cmp/cmp.c
@@ -62,10 +62,11 @@
#include "extern.h"
-bool lflag, sflag, xflag, zflag;
+bool bflag, lflag, sflag, xflag, zflag;
static const struct option long_opts[] =
{
+ {"print-bytes", no_argument, NULL, 'b'},
{"ignore-initial", required_argument, NULL, 'i'},
{"verbose", no_argument, NULL, 'l'},
{"bytes", required_argument, NULL, 'n'},
@@ -106,8 +107,11 @@
skip1 = skip2 = 0;
oflag = O_RDONLY;
- while ((ch = getopt_long(argc, argv, "+hi:ln:sxz", long_opts, NULL)) != -1)
+ while ((ch = getopt_long(argc, argv, "+bhi:ln:sxz", long_opts, NULL)) != -1)
switch (ch) {
+ case 'b': /* Print bytes */
+ bflag = true;
+ break;
case 'h': /* Don't follow symlinks */
oflag |= O_NOFOLLOW;
break;
Index: usr.bin/cmp/extern.h
===================================================================
--- usr.bin/cmp/extern.h
+++ usr.bin/cmp/extern.h
@@ -42,7 +42,7 @@
void c_regular(int, const char *, off_t, off_t, int, const char *, off_t,
off_t, off_t);
void c_special(int, const char *, off_t, int, const char *, off_t, off_t);
-void diffmsg(const char *, const char *, off_t, off_t);
+void diffmsg(const char *, const char *, off_t, off_t, int, int);
void eofmsg(const char *);
-extern bool lflag, sflag, xflag, zflag;
+extern bool bflag, lflag, sflag, xflag, zflag;
Index: usr.bin/cmp/link.c
===================================================================
--- usr.bin/cmp/link.c
+++ usr.bin/cmp/link.c
@@ -82,10 +82,14 @@
(long long)byte - 1, ch, *p2);
} else if (lflag) {
dfound = 1;
- (void)printf("%6lld %3o %3o\n",
- (long long)byte, ch, *p2);
+ if (bflag)
+ (void)printf("%6lld %3o %c %3o %c\n",
+ (long long)byte, ch, ch, *p2, *p2);
+ else
+ (void)printf("%6lld %3o %3o\n",
+ (long long)byte, ch, *p2);
} else
- diffmsg(file1, file2, byte, 1);
+ diffmsg(file1, file2, byte, 1, ch, *p2);
/* NOTREACHED */
}
byte++;
Index: usr.bin/cmp/misc.c
===================================================================
--- usr.bin/cmp/misc.c
+++ usr.bin/cmp/misc.c
@@ -56,10 +56,20 @@
}
void
-diffmsg(const char *file1, const char *file2, off_t byte, off_t line)
+diffmsg(const char *file1, const char *file2, off_t byte, off_t line,
+ int b1, int b2)
{
- if (!sflag)
+ if (sflag)
+ goto out;
+
+ if (bflag) {
+ (void)printf("%s %s differ: char %lld, line %lld is %3o %c %3o %c\n",
+ file1, file2, (long long)byte, (long long)line, b1, b1,
+ b2, b2);
+ } else {
(void)printf("%s %s differ: char %lld, line %lld\n",
file1, file2, (long long)byte, (long long)line);
+ }
+out:
exit(DIFF_EXIT);
}
Index: usr.bin/cmp/regular.c
===================================================================
--- usr.bin/cmp/regular.c
+++ usr.bin/cmp/regular.c
@@ -127,10 +127,14 @@
(long long)byte - 1, ch, *p2);
} else if (lflag) {
dfound = 1;
- (void)printf("%6lld %3o %3o\n",
- (long long)byte, ch, *p2);
+ if (bflag)
+ (void)printf("%6lld %3o %c %3o %c\n",
+ (long long)byte, ch, ch, *p2, *p2);
+ else
+ (void)printf("%6lld %3o %3o\n",
+ (long long)byte, ch, *p2);
} else
- diffmsg(file1, file2, byte, line);
+ diffmsg(file1, file2, byte, line, ch, *p2);
/* NOTREACHED */
}
if (ch == '\n')
Index: usr.bin/cmp/special.c
===================================================================
--- usr.bin/cmp/special.c
+++ usr.bin/cmp/special.c
@@ -88,10 +88,15 @@
(long long)byte - 1, ch1, ch2);
} else if (lflag) {
dfound = 1;
- (void)printf("%6lld %3o %3o\n",
- (long long)byte, ch1, ch2);
+ if (bflag)
+ (void)printf("%6lld %3o %c %3o %c\n",
+ (long long)byte, ch1, ch1, ch2,
+ ch2);
+ else
+ (void)printf("%6lld %3o %3o\n",
+ (long long)byte, ch1, ch2);
} else {
- diffmsg(file1, file2, byte, line);
+ diffmsg(file1, file2, byte, line, ch1, ch2);
/* NOTREACHED */
}
}
Index: usr.bin/cmp/tests/Makefile
===================================================================
--- usr.bin/cmp/tests/Makefile
+++ usr.bin/cmp/tests/Makefile
@@ -2,9 +2,14 @@
.include <bsd.own.mk>
+PACKAGE= tests
+
ATF_TESTS_SH+= cmp_test2
NETBSD_ATF_TESTS_SH= cmp_test
+${PACKAGE}FILES+= b_flag.out
+${PACKAGE}FILES+= bl_flag.out
+
.include <netbsd-tests.test.mk>
.include <bsd.test.mk>
Index: usr.bin/cmp/tests/b_flag.out
===================================================================
--- /dev/null
+++ usr.bin/cmp/tests/b_flag.out
@@ -0,0 +1 @@
+a b differ: char 3, line 1 is 143 c 144 d
Index: usr.bin/cmp/tests/bl_flag.out
===================================================================
--- /dev/null
+++ usr.bin/cmp/tests/bl_flag.out
@@ -0,0 +1 @@
+ 3 143 c 144 d
Index: usr.bin/cmp/tests/cmp_test2.sh
===================================================================
--- usr.bin/cmp/tests/cmp_test2.sh
+++ usr.bin/cmp/tests/cmp_test2.sh
@@ -118,6 +118,22 @@
atf_check -s exit:1 -o ignore -x "cat a | cmp -sn 5 b -"
}
+atf_test_case bflag
+bflag_head()
+{
+ atf_set "descr" "Test cmp(1) -b (print bytes)"
+}
+bflag_body()
+{
+ echo -n "abcd" > a
+ echo -n "abdd" > b
+
+ atf_check -s exit:1 -o file:$(atf_get_srcdir)/b_flag.out \
+ cmp -b a b
+ atf_check -s exit:1 -o file:$(atf_get_srcdir)/bl_flag.out \
+ cmp -bl a b
+}
+
atf_init_test_cases()
{
atf_add_test_case special
@@ -125,4 +141,5 @@
atf_add_test_case pr252542
atf_add_test_case skipsuff
atf_add_test_case limit
+ atf_add_test_case bflag
}

File Metadata

Mime Type
text/plain
Expires
Wed, Nov 12, 4:25 PM (9 h, 54 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
25190058
Default Alt Text
D32074.id95576.diff (6 KB)

Event Timeline