* 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.2 (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) */
errx(ERR_EXIT
, "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(ERR_EXIT
, "%s", file1
);
if (strcmp(file2
= argv
[1], "-") == 0) {
"standard input may only be specified once");
else if ((fd2
= open(file2
, O_RDONLY
, 0)) < 0)
err(ERR_EXIT
, "%s", file2
);
skip1
= argc
> 2 ? strtol(argv
[2], NULL
, 10) : 0;
skip2
= argc
== 4 ? strtol(argv
[3], NULL
, 10) : 0;
err(ERR_EXIT
, "%s", file1
);
if (!S_ISREG(sb1
.st_mode
))
err(ERR_EXIT
, "%s", file2
);
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");