d3320a3d7bfa195d3ab110c85bd0d232d0f96627
* Copyright (c) 1987, 1990, 1993
* The Regents of the University of California. All rights reserved.
* %sccs.include.redist.c%
static char copyright
[] =
"@(#) Copyright (c) 1987, 1990, 1993\n\
The Regents of the University of California. All rights reserved.\n";
static char sccsid
[] = "@(#)cmp.c 8.1 (Berkeley) %G%";
static void usage
__P((void));
int ch
, fd1
, fd2
, special
;
while ((ch
= getopt(argc
, argv
, "-ls")) != EOF
)
case 'l': /* print all differences */
case 's': /* silent run */
case '-': /* stdin (must be after options) */
err("only one of -l and -s may be specified");
if (argc
< 2 || argc
> 4)
/* Backward compatibility -- handle "-" meaning stdin. */
if (strcmp(file1
= argv
[0], "-") == 0) {
else if ((fd1
= open(file1
, O_RDONLY
, 0)) < 0)
err("%s: %s", file1
, strerror(errno
));
if (strcmp(file2
= argv
[1], "-") == 0) {
err("standard input may only be specified once");
else if ((fd2
= open(file2
, O_RDONLY
, 0)) < 0)
err("%s: %s", file2
, strerror(errno
));
skip1
= argc
> 2 ? strtol(argv
[2], NULL
, 10) : 0;
skip2
= argc
== 4 ? strtol(argv
[3], NULL
, 10) : 0;
err("%s: %s", file1
, strerror(errno
));
if (!S_ISREG(sb1
.st_mode
))
err("%s: %s", file2
, strerror(errno
));
if (!S_ISREG(sb2
.st_mode
))
c_special(fd1
, file1
, skip1
, fd2
, file2
, skip2
);
c_regular(fd1
, file1
, skip1
, sb1
.st_size
,
fd2
, file2
, skip2
, sb2
.st_size
);
"usage: cmp [-l | s] file1 file2 [skip1 [skip2]]\n");