mirror of
https://github.com/freebsd/freebsd-src
synced 2024-09-20 00:33:57 +00:00
Our mmap(2) has a limitation where the `offset' parameter must be
page-aligned. cmp(1) should know about this flaw, and work around it. While i was at it, fixed an uninitialized variable as reported by -Wall.
This commit is contained in:
parent
b8b15e71f7
commit
c28065c606
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=21429
|
@ -44,9 +44,12 @@ static char sccsid[] = "@(#)regular.c 8.3 (Berkeley) 4/2/94";
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
#include "extern.h"
|
#include "extern.h"
|
||||||
|
|
||||||
|
#define ROUNDPAGE(i) ((i) & ~pagemask)
|
||||||
|
|
||||||
void
|
void
|
||||||
c_regular(fd1, file1, skip1, len1, fd2, file2, skip2, len2)
|
c_regular(fd1, file1, skip1, len1, fd2, file2, skip2, len2)
|
||||||
int fd1, fd2;
|
int fd1, fd2;
|
||||||
|
@ -56,6 +59,7 @@ c_regular(fd1, file1, skip1, len1, fd2, file2, skip2, len2)
|
||||||
u_char ch, *p1, *p2;
|
u_char ch, *p1, *p2;
|
||||||
off_t byte, length, line;
|
off_t byte, length, line;
|
||||||
int dfound;
|
int dfound;
|
||||||
|
off_t pagemask, off1, off2;
|
||||||
|
|
||||||
if (sflag && len1 != len2)
|
if (sflag && len1 != len2)
|
||||||
exit(1);
|
exit(1);
|
||||||
|
@ -67,21 +71,27 @@ c_regular(fd1, file1, skip1, len1, fd2, file2, skip2, len2)
|
||||||
eofmsg(file2);
|
eofmsg(file2);
|
||||||
len2 -= skip2;
|
len2 -= skip2;
|
||||||
|
|
||||||
|
pagemask = (off_t)getpagesize() - 1;
|
||||||
|
off1 = ROUNDPAGE(skip1);
|
||||||
|
off2 = ROUNDPAGE(skip2);
|
||||||
|
|
||||||
length = MIN(len1, len2);
|
length = MIN(len1, len2);
|
||||||
if (length > SIZE_T_MAX)
|
if (length > SIZE_T_MAX)
|
||||||
return (c_special(fd1, file1, skip1, fd2, file2, skip2));
|
return (c_special(fd1, file1, skip1, fd2, file2, skip2));
|
||||||
|
|
||||||
if ((p1 = (u_char *)mmap(NULL,
|
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);
|
err(ERR_EXIT, "%s", file1);
|
||||||
|
|
||||||
madvise(p1, length, MADV_SEQUENTIAL);
|
madvise(p1, length, MADV_SEQUENTIAL);
|
||||||
if ((p2 = (u_char *)mmap(NULL,
|
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);
|
err(ERR_EXIT, "%s", file2);
|
||||||
madvise(p2, length, MADV_SEQUENTIAL);
|
madvise(p2, length, MADV_SEQUENTIAL);
|
||||||
|
|
||||||
dfound = 0;
|
dfound = 0;
|
||||||
|
p1 += skip1 - off1;
|
||||||
|
p2 += skip2 - off2;
|
||||||
for (byte = line = 1; length--; ++p1, ++p2, ++byte) {
|
for (byte = line = 1; length--; ++p1, ++p2, ++byte) {
|
||||||
if ((ch = *p1) != *p2)
|
if ((ch = *p1) != *p2)
|
||||||
if (lflag) {
|
if (lflag) {
|
||||||
|
|
|
@ -60,6 +60,7 @@ c_special(fd1, file1, skip1, fd2, file2, skip2)
|
||||||
if ((fp2 = fdopen(fd2, "r")) == NULL)
|
if ((fp2 = fdopen(fd2, "r")) == NULL)
|
||||||
err(ERR_EXIT, "%s", file2);
|
err(ERR_EXIT, "%s", file2);
|
||||||
|
|
||||||
|
dfound = 0;
|
||||||
while (skip1--)
|
while (skip1--)
|
||||||
if (getc(fp1) == EOF)
|
if (getc(fp1) == EOF)
|
||||||
goto eof;
|
goto eof;
|
||||||
|
@ -67,7 +68,6 @@ c_special(fd1, file1, skip1, fd2, file2, skip2)
|
||||||
if (getc(fp2) == EOF)
|
if (getc(fp2) == EOF)
|
||||||
goto eof;
|
goto eof;
|
||||||
|
|
||||||
dfound = 0;
|
|
||||||
for (byte = line = 1;; ++byte) {
|
for (byte = line = 1;; ++byte) {
|
||||||
ch1 = getc(fp1);
|
ch1 = getc(fp1);
|
||||||
ch2 = getc(fp2);
|
ch2 = getc(fp2);
|
||||||
|
|
Loading…
Reference in a new issue