diff options
| author | Joerg Wunsch <joerg@FreeBSD.org> | 1997-01-08 12:00:55 +0000 | 
|---|---|---|
| committer | Joerg Wunsch <joerg@FreeBSD.org> | 1997-01-08 12:00:55 +0000 | 
| commit | c28065c606fcaaf574eb9adfa8ddc32b7885e0cc (patch) | |
| tree | 7edd4b5974c91e0aee7a6cb25e43aa5d8d4284e9 | |
| parent | b8b15e71f7755d568f393c8ab5c870efbf7a660a (diff) | |
Notes
| -rw-r--r-- | usr.bin/cmp/regular.c | 14 | ||||
| -rw-r--r-- | usr.bin/cmp/special.c | 2 | 
2 files changed, 13 insertions, 3 deletions
| diff --git a/usr.bin/cmp/regular.c b/usr.bin/cmp/regular.c index 76f23874a77f..5d301fad6bb9 100644 --- a/usr.bin/cmp/regular.c +++ b/usr.bin/cmp/regular.c @@ -44,9 +44,12 @@ static char sccsid[] = "@(#)regular.c	8.3 (Berkeley) 4/2/94";  #include <stdlib.h>  #include <stdio.h>  #include <string.h> +#include <unistd.h>  #include "extern.h" +#define ROUNDPAGE(i) ((i) & ~pagemask) +  void  c_regular(fd1, file1, skip1, len1, fd2, file2, skip2, len2)  	int fd1, fd2; @@ -56,6 +59,7 @@ c_regular(fd1, file1, skip1, len1, fd2, file2, skip2, len2)  	u_char ch, *p1, *p2;  	off_t byte, length, line;  	int dfound; +	off_t pagemask, off1, off2;  	if (sflag && len1 != len2)  		exit(1); @@ -67,21 +71,27 @@ c_regular(fd1, file1, skip1, len1, fd2, file2, skip2, len2)  		eofmsg(file2);  	len2 -= skip2; +	pagemask = (off_t)getpagesize() - 1; +	off1 = ROUNDPAGE(skip1); +	off2 = ROUNDPAGE(skip2); +  	length = MIN(len1, len2);  	if (length > SIZE_T_MAX)  		return (c_special(fd1, file1, skip1, fd2, file2, skip2));  	if ((p1 = (u_char *)mmap(NULL, -	    (size_t)length, PROT_READ, 0, fd1, skip1)) == (u_char *)-1) +	    (size_t)length, PROT_READ, 0, fd1, off1)) == (u_char *)-1)  		err(ERR_EXIT, "%s", file1);  	madvise(p1, length, MADV_SEQUENTIAL);  	if ((p2 = (u_char *)mmap(NULL, -	    (size_t)length, PROT_READ, 0, fd2, skip2)) == (u_char *)-1) +	    (size_t)length, PROT_READ, 0, fd2, off2)) == (u_char *)-1)  		err(ERR_EXIT, "%s", file2);  	madvise(p2, length, MADV_SEQUENTIAL);  	dfound = 0; +	p1 += skip1 - off1; +	p2 += skip2 - off2;  	for (byte = line = 1; length--; ++p1, ++p2, ++byte) {  		if ((ch = *p1) != *p2)  			if (lflag) { diff --git a/usr.bin/cmp/special.c b/usr.bin/cmp/special.c index 0dcd0c5dfe25..0a15fa1b28f4 100644 --- a/usr.bin/cmp/special.c +++ b/usr.bin/cmp/special.c @@ -60,6 +60,7 @@ c_special(fd1, file1, skip1, fd2, file2, skip2)  	if ((fp2 = fdopen(fd2, "r")) == NULL)  		err(ERR_EXIT, "%s", file2); +	dfound = 0;  	while (skip1--)  		if (getc(fp1) == EOF)  			goto eof; @@ -67,7 +68,6 @@ c_special(fd1, file1, skip1, fd2, file2, skip2)  		if (getc(fp2) == EOF)  			goto eof; -	dfound = 0;  	for (byte = line = 1;; ++byte) {  		ch1 = getc(fp1);  		ch2 = getc(fp2); | 
