-static
-cmp()
-{
- register u_char *C1, *C2; /* traveling pointers */
- register int cnt, /* counter */
- len1, len2; /* read lengths */
- register long byte, /* byte count */
- line; /* line count */
- short dfound = NO; /* if difference found */
-
- for (byte = 0, line = 1;;) {
- switch(len1 = read(fd1, buf1, MAXBSIZE)) {
- case -1:
- error(file1);
- case 0:
- /*
- * read of file 1 just failed, find out
- * if there's anything left in file 2
- */
- switch(read(fd2, buf2, 1)) {
- case -1:
- error(file2);
- case 0:
- exit(dfound ? DIFF : OK);
- default:
- endoffile(file1);
- }
- }
- /*
- * file1 might be stdio, which means that a read of less than
- * MAXBSIZE might not mean an EOF. So, read whatever we read
- * from file1 from file2.
- */
- if ((len2 = read(fd2, buf2, len1)) == -1)
- error(file2);
- if (bcmp(buf1, buf2, len2)) {
- if (silent)
- exit(DIFF);
- if (all) {
- dfound = YES;
- for (C1 = buf1, C2 = buf2, cnt = len2; cnt--; ++C1, ++C2) {
- ++byte;
- if (*C1 != *C2)
- printf("%6ld %3o %3o\n", byte, *C1, *C2);
- }
- }
- else for (C1 = buf1, C2 = buf2;; ++C1, ++C2) {
- ++byte;
- if (*C1 != *C2) {
- printf("%s %s differ: char %ld, line %ld\n", file1, file2, byte, line);
- exit(DIFF);
- }
- if (*C1 == '\n')
- ++line;
- }
- }
+ skip1 = argc > 2 ? strtol(argv[2], NULL, 10) : 0;
+ skip2 = argc == 4 ? strtol(argv[3], NULL, 10) : 0;
+
+ if (!special) {
+ if (fstat(fd1, &sb1))
+ err(ERR_EXIT, "%s", file1);
+ if (!S_ISREG(sb1.st_mode))
+ special = 1;