-cmp()
-{
- register u_char *p1, *p2;
- register int cnt, len1, len2;
- register long byte, line;
- int dfound = 0;
-
- 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);
- /* NOTREACHED */
- case 0:
- exit(dfound ? EXITDIFF : EXITNODIFF);
- /* NOTREACHED */
- default:
- endoffile(file1);
- break;
- }
- }
- /*
- * 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(EXITDIFF);
- if (all) {
- dfound = 1;
- for (p1 = buf1, p2 = buf2, cnt = len2; cnt--;
- ++p1, ++p2) {
- ++byte;
- if (*p1 != *p2)
- printf("%6ld %3o %3o\n",
- byte, *p1, *p2);
- }
- } else for (p1 = buf1, p2 = buf2; ; ++p1, ++p2) {
- ++byte;
- if (*p1 != *p2) {
- printf("%s %s differ: char %ld, line %ld\n", file1, file2, byte, line);
- exit(EXITDIFF);
- }
- if (*p1 == '\n')
- ++line;
- }
- } else {
- byte += len2;
- /*
- * here's the real performance problem, we've got to
- * count the stupid lines, which means that -l is a
- * *much* faster version, i.e., unless you really
- * *want* to know the line number, run -s or -l.
- */
- if (!silent && !all)
- for (p1 = buf1, cnt = len2; cnt--; )
- if (*p1++ == '\n')
- ++line;
- }
- /*
- * couldn't read as much from file2 as from file1; checked
- * here because there might be a difference before we got
- * to this point, which would have precedence.
- */
- if (len2 < len1)
- endoffile(file2);
- }
+ if (special)
+ c_special(fd1, file1, skip1, fd2, file2, skip2);
+ else
+ c_regular(fd1, file1, skip1, sb1.st_size,
+ fd2, file2, skip2, sb2.st_size);
+ exit(0);