Commit | Line | Data |
---|---|---|
e1e1e0bd | 1 | /*- |
14b2c646 KB |
2 | * Copyright (c) 1991, 1993 |
3 | * The Regents of the University of California. All rights reserved. | |
e1e1e0bd KB |
4 | * |
5 | * %sccs.include.redist.c% | |
6 | */ | |
7 | ||
8 | #ifndef lint | |
14b2c646 | 9 | static char sccsid[] = "@(#)regular.c 8.1 (Berkeley) %G%"; |
e1e1e0bd KB |
10 | #endif /* not lint */ |
11 | ||
12 | #include <sys/param.h> | |
13 | #include <sys/mman.h> | |
14 | #include <sys/stat.h> | |
cab7d150 KB |
15 | |
16 | #include <limits.h> | |
e1e1e0bd KB |
17 | #include <errno.h> |
18 | #include <stdlib.h> | |
19 | #include <stdio.h> | |
20 | #include <string.h> | |
21 | #include "extern.h" | |
22 | ||
23 | void | |
24 | c_regular(fd1, file1, skip1, len1, fd2, file2, skip2, len2) | |
25 | int fd1, fd2; | |
26 | char *file1, *file2; | |
27 | off_t skip1, len1, skip2, len2; | |
28 | { | |
29 | register u_char ch, *p1, *p2; | |
30 | register off_t byte, length, line; | |
31 | int dfound; | |
32 | ||
33 | if (sflag && len1 != len2) | |
34 | exit(1); | |
35 | ||
cae8a106 | 36 | if (skip1 > len1) |
e1e1e0bd KB |
37 | eofmsg(file1); |
38 | len1 -= skip1; | |
cae8a106 | 39 | if (skip2 > len2) |
e1e1e0bd KB |
40 | eofmsg(file2); |
41 | len2 -= skip2; | |
42 | ||
43 | length = MIN(len1, len2); | |
cab7d150 KB |
44 | if (length > SIZE_T_MAX) |
45 | return (c_special(fd1, file1, skip1, fd2, file2, skip2)); | |
46 | ||
e1e1e0bd | 47 | if ((p1 = (u_char *)mmap(NULL, |
cab7d150 | 48 | (size_t)length, PROT_READ, 0, fd1, skip1)) == (u_char *)-1) |
e1e1e0bd KB |
49 | err("%s: %s", file1, strerror(errno)); |
50 | if ((p2 = (u_char *)mmap(NULL, | |
cab7d150 | 51 | (size_t)length, PROT_READ, 0, fd2, skip2)) == (u_char *)-1) |
e1e1e0bd KB |
52 | err("%s: %s", file2, strerror(errno)); |
53 | ||
54 | dfound = 0; | |
55 | for (byte = line = 1; length--; ++p1, ++p2, ++byte) { | |
56 | if ((ch = *p1) != *p2) | |
57 | if (lflag) { | |
58 | dfound = 1; | |
9e7572e5 | 59 | (void)printf("%6qd %3o %3o\n", byte, ch, *p2); |
e1e1e0bd KB |
60 | } else |
61 | diffmsg(file1, file2, byte, line); | |
62 | /* NOTREACHED */ | |
63 | if (ch == '\n') | |
64 | ++line; | |
65 | } | |
66 | ||
67 | if (len1 != len2) | |
68 | eofmsg (len1 > len2 ? file2 : file1); | |
69 | if (dfound) | |
70 | exit(1); | |
71 | } |