diff options
author | peter <peter@FreeBSD.org> | 1996-09-05 07:33:24 +0000 |
---|---|---|
committer | peter <peter@FreeBSD.org> | 1996-09-05 07:33:24 +0000 |
commit | f30b313a634163a62fa4e1a89651af521196e9b3 (patch) | |
tree | f52050cecccca128fae026f812219725c1552beb /usr.bin | |
parent | 46847c4cdf07a7b2e9a09aa8380d6fb848301ff9 (diff) | |
download | FreeBSD-src-f30b313a634163a62fa4e1a89651af521196e9b3.zip FreeBSD-src-f30b313a634163a62fa4e1a89651af521196e9b3.tar.gz |
accidently removed the "dont compare > 8MB files hack".
didn't rewind the files after the read()s in the non-mmap compare.
Diffstat (limited to 'usr.bin')
-rw-r--r-- | usr.bin/xinstall/xinstall.c | 72 |
1 files changed, 39 insertions, 33 deletions
diff --git a/usr.bin/xinstall/xinstall.c b/usr.bin/xinstall/xinstall.c index 61d57d7..b083a40 100644 --- a/usr.bin/xinstall/xinstall.c +++ b/usr.bin/xinstall/xinstall.c @@ -40,7 +40,7 @@ static const char copyright[] = #ifndef lint /*static char sccsid[] = "From: @(#)xinstall.c 8.1 (Berkeley) 7/21/93";*/ static const char rcsid[] = - "$Id: xinstall.c,v 1.9 1996/08/12 17:03:30 peter Exp $"; + "$Id: xinstall.c,v 1.10 1996/09/05 07:27:43 peter Exp $"; #endif /* not lint */ /*- @@ -490,39 +490,45 @@ compare(int from_fd, const char *from_name, int to_fd, const char *to_name, tsize = (size_t)from_sb->st_size; - if (tsize <= 8 * 1024 * 1024 && trymmap(from_fd) && trymmap(to_fd)) { - p = mmap(NULL, tsize, PROT_READ, 0, from_fd, (off_t)0); - if ((long)p == -1) - err(EX_OSERR, "mmap %s", from_name); - q = mmap(NULL, tsize, PROT_READ, 0, to_fd, (off_t)0); - if ((long)q == -1) - err(EX_OSERR, "mmap %s", to_name); - - rv = memcmp(p, q, tsize); - munmap(p, tsize); - munmap(q, tsize); - } else { - char buf1[16384]; - char buf2[16384]; - int n1, n2; - - rv = 0; - lseek(from_fd, 0, SEEK_SET); - lseek(to_fd, 0, SEEK_SET); - while (rv == 0) { - n1 = read(from_fd, buf1, sizeof(buf1)); - if (n1 == 0) - break; - else if (n1 > 0) { - n2 = read(to_fd, buf2, n1); - if (n2 == n1) - rv = memcmp(buf1, buf2, n1); - else - rv = 1; - } else - rv = 1; + if (tsize <= 8 * 1024 * 1024) { + if (trymmap(from_fd) && trymmap(to_fd)) { + p = mmap(NULL, tsize, PROT_READ, 0, from_fd, (off_t)0); + if ((long)p == -1) + err(EX_OSERR, "mmap %s", from_name); + q = mmap(NULL, tsize, PROT_READ, 0, to_fd, (off_t)0); + if ((long)q == -1) + err(EX_OSERR, "mmap %s", to_name); + + rv = memcmp(p, q, tsize); + munmap(p, tsize); + munmap(q, tsize); + } else { + char buf1[16384]; + char buf2[16384]; + int n1, n2; + + rv = 0; + lseek(from_fd, 0, SEEK_SET); + lseek(to_fd, 0, SEEK_SET); + while (rv == 0) { + n1 = read(from_fd, buf1, sizeof(buf1)); + if (n1 == 0) + break; /* EOF */ + else if (n1 > 0) { + n2 = read(to_fd, buf2, n1); + if (n2 == n1) + rv = memcmp(buf1, buf2, n1); + else + rv = 1; /* out of sync */ + } else + rv = 1; /* read failure */ + } + lseek(from_fd, 0, SEEK_SET); + lseek(to_fd, 0, SEEK_SET); } - } + } else + rv = 1; /* don't bother in this case */ + return rv; } |