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 | |
c3afbeb5 | 9 | static char sccsid[] = "@(#)regular.c 8.2 (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 | 15 | |
c3afbeb5 | 16 | #include <err.h> |
cab7d150 | 17 | #include <limits.h> |
e1e1e0bd KB |
18 | #include <stdlib.h> |
19 | #include <stdio.h> | |
20 | #include <string.h> | |
c3afbeb5 | 21 | |
e1e1e0bd KB |
22 | #include "extern.h" |
23 | ||
24 | void | |
25 | c_regular(fd1, file1, skip1, len1, fd2, file2, skip2, len2) | |
26 | int fd1, fd2; | |
27 | char *file1, *file2; | |
28 | off_t skip1, len1, skip2, len2; | |
29 | { | |
c3afbeb5 JSP |
30 | u_char ch, *p1, *p2; |
31 | off_t byte, length, line; | |
e1e1e0bd KB |
32 | int dfound; |
33 | ||
34 | if (sflag && len1 != len2) | |
35 | exit(1); | |
36 | ||
cae8a106 | 37 | if (skip1 > len1) |
e1e1e0bd KB |
38 | eofmsg(file1); |
39 | len1 -= skip1; | |
cae8a106 | 40 | if (skip2 > len2) |
e1e1e0bd KB |
41 | eofmsg(file2); |
42 | len2 -= skip2; | |
43 | ||
44 | length = MIN(len1, len2); | |
cab7d150 KB |
45 | if (length > SIZE_T_MAX) |
46 | return (c_special(fd1, file1, skip1, fd2, file2, skip2)); | |
47 | ||
e1e1e0bd | 48 | if ((p1 = (u_char *)mmap(NULL, |
cab7d150 | 49 | (size_t)length, PROT_READ, 0, fd1, skip1)) == (u_char *)-1) |
c3afbeb5 | 50 | err(ERR_EXIT, "%s", file1); |
e1e1e0bd | 51 | if ((p2 = (u_char *)mmap(NULL, |
cab7d150 | 52 | (size_t)length, PROT_READ, 0, fd2, skip2)) == (u_char *)-1) |
c3afbeb5 | 53 | err(ERR_EXIT, "%s", file2); |
e1e1e0bd KB |
54 | |
55 | dfound = 0; | |
56 | for (byte = line = 1; length--; ++p1, ++p2, ++byte) { | |
57 | if ((ch = *p1) != *p2) | |
58 | if (lflag) { | |
59 | dfound = 1; | |
9e7572e5 | 60 | (void)printf("%6qd %3o %3o\n", byte, ch, *p2); |
e1e1e0bd KB |
61 | } else |
62 | diffmsg(file1, file2, byte, line); | |
63 | /* NOTREACHED */ | |
64 | if (ch == '\n') | |
65 | ++line; | |
66 | } | |
67 | ||
68 | if (len1 != len2) | |
69 | eofmsg (len1 > len2 ? file2 : file1); | |
70 | if (dfound) | |
c3afbeb5 | 71 | exit(DIFF_EXIT); |
e1e1e0bd | 72 | } |