diff options
author | brian <brian@FreeBSD.org> | 2000-07-14 16:54:59 +0000 |
---|---|---|
committer | brian <brian@FreeBSD.org> | 2000-07-14 16:54:59 +0000 |
commit | 55485e0103d7b63665f16e41d400e306498c92a8 (patch) | |
tree | 4e3548ebbcb3a10e411d5377fb39547c6ffae7dc /usr.bin/cmp | |
parent | 9fcd42ea635d4165101b83693fb0be506fc85b93 (diff) | |
download | FreeBSD-src-55485e0103d7b63665f16e41d400e306498c92a8.zip FreeBSD-src-55485e0103d7b63665f16e41d400e306498c92a8.tar.gz |
Add the -z flag to check file sizes first
Correct the cmp.1 usage message
Correct the -l/-s incompatibility message
Submitted by: Mark Knight <markk@knigma.org>
Diffstat (limited to 'usr.bin/cmp')
-rw-r--r-- | usr.bin/cmp/cmp.1 | 6 | ||||
-rw-r--r-- | usr.bin/cmp/cmp.c | 18 |
2 files changed, 19 insertions, 5 deletions
diff --git a/usr.bin/cmp/cmp.1 b/usr.bin/cmp/cmp.1 index 60baf92..c8a5f25 100644 --- a/usr.bin/cmp/cmp.1 +++ b/usr.bin/cmp/cmp.1 @@ -43,7 +43,8 @@ .Nd compare two files .Sh SYNOPSIS .Nm cmp -.Op Fl l | Fl s +.Op Fl l | Fl s | Fl x +.Op Fl z .Ar file1 file2 .Op Ar skip1 Op Ar skip2 .Sh DESCRIPTION @@ -71,6 +72,9 @@ Like .Fl l but prints in hexadecimal and using zero as index for the first byte in the files. +.It Fl z +For regular files compare file sizes first, and fail the comparison if they +are not equal. .El .Pp The optional arguments diff --git a/usr.bin/cmp/cmp.c b/usr.bin/cmp/cmp.c index 2e1d798..cfa43fe 100644 --- a/usr.bin/cmp/cmp.c +++ b/usr.bin/cmp/cmp.c @@ -56,7 +56,7 @@ static const char sccsid[] = "@(#)cmp.c 8.3 (Berkeley) 4/2/94"; #include "extern.h" -int lflag, sflag, xflag; +int lflag, sflag, xflag, zflag; static void usage __P((void)); @@ -70,18 +70,22 @@ main(argc, argv) int ch, fd1, fd2, special; char *file1, *file2; - while ((ch = getopt(argc, argv, "-lsx")) != -1) + while ((ch = getopt(argc, argv, "-lsxz")) != -1) switch (ch) { case 'l': /* print all differences */ lflag = 1; break; case 's': /* silent run */ sflag = 1; + zflag = 1; break; case 'x': /* hex output */ lflag = 1; xflag = 1; break; + case 'z': /* compare size first */ + zflag = 1; + break; case '-': /* stdin (must be after options) */ --optind; goto endargs; @@ -94,7 +98,7 @@ endargs: argc -= optind; if (lflag && sflag) - errx(ERR_EXIT, "only one of -l and -s may be specified"); + errx(ERR_EXIT, "specifying -s with -l or -x is not permitted"); if (argc < 2 || argc > 4) usage(); @@ -154,6 +158,12 @@ endargs: if (special) c_special(fd1, file1, skip1, fd2, file2, skip2); else + if (zflag && sb1.st_size != sb2.st_size) { + if (!sflag) + (void) printf("%s %s differ: size\n", + file1, file2); + exit(DIFF_EXIT); + } c_regular(fd1, file1, skip1, sb1.st_size, fd2, file2, skip2, sb2.st_size); exit(0); @@ -164,6 +174,6 @@ usage() { (void)fprintf(stderr, - "usage: cmp [-l | -s] file1 file2 [skip1 [skip2]]\n"); + "usage: cmp [-l | -s | -x] [-z] file1 file2 [skip1 [skip2]]\n"); exit(ERR_EXIT); } |