151413Sbostic /*- 251413Sbostic * Copyright (c) 1991 The Regents of the University of California. 351413Sbostic * All rights reserved. 451413Sbostic * 551413Sbostic * %sccs.include.redist.c% 651413Sbostic */ 751413Sbostic 851413Sbostic #ifndef lint 9*51733Sbostic static char sccsid[] = "@(#)regular.c 5.2 (Berkeley) 11/16/91"; 1051413Sbostic #endif /* not lint */ 1151413Sbostic 1251413Sbostic #include <sys/param.h> 1351413Sbostic #include <sys/mman.h> 1451413Sbostic #include <sys/stat.h> 1551413Sbostic #include <errno.h> 1651413Sbostic #include <stdlib.h> 1751413Sbostic #include <stdio.h> 1851413Sbostic #include <string.h> 1951413Sbostic #include "extern.h" 2051413Sbostic 2151413Sbostic void 2251413Sbostic c_regular(fd1, file1, skip1, len1, fd2, file2, skip2, len2) 2351413Sbostic int fd1, fd2; 2451413Sbostic char *file1, *file2; 2551413Sbostic off_t skip1, len1, skip2, len2; 2651413Sbostic { 2751413Sbostic register u_char ch, *p1, *p2; 2851413Sbostic register off_t byte, length, line; 2951413Sbostic int dfound; 3051413Sbostic 3151413Sbostic if (sflag && len1 != len2) 3251413Sbostic exit(1); 3351413Sbostic 34*51733Sbostic if (skip1 > len1) 3551413Sbostic eofmsg(file1); 3651413Sbostic len1 -= skip1; 37*51733Sbostic if (skip2 > len2) 3851413Sbostic eofmsg(file2); 3951413Sbostic len2 -= skip2; 4051413Sbostic 4151413Sbostic length = MIN(len1, len2); 4251413Sbostic if ((p1 = (u_char *)mmap(NULL, 4351413Sbostic length, PROT_READ, MAP_FILE, fd1, skip1)) == (u_char *)-1) 4451413Sbostic err("%s: %s", file1, strerror(errno)); 4551413Sbostic if ((p2 = (u_char *)mmap(NULL, 4651413Sbostic length, PROT_READ, MAP_FILE, fd2, skip2)) == (u_char *)-1) 4751413Sbostic err("%s: %s", file2, strerror(errno)); 4851413Sbostic 4951413Sbostic dfound = 0; 5051413Sbostic for (byte = line = 1; length--; ++p1, ++p2, ++byte) { 5151413Sbostic if ((ch = *p1) != *p2) 5251413Sbostic if (lflag) { 5351413Sbostic dfound = 1; 5451413Sbostic (void)printf("%6ld %3o %3o\n", byte, ch, *p2); 5551413Sbostic } else 5651413Sbostic diffmsg(file1, file2, byte, line); 5751413Sbostic /* NOTREACHED */ 5851413Sbostic if (ch == '\n') 5951413Sbostic ++line; 6051413Sbostic } 6151413Sbostic 6251413Sbostic if (len1 != len2) 6351413Sbostic eofmsg (len1 > len2 ? file2 : file1); 6451413Sbostic if (dfound) 6551413Sbostic exit(1); 6651413Sbostic } 67