diff options
Diffstat (limited to 'usr.bin')
-rw-r--r-- | usr.bin/cmp/cmp.c | 18 | ||||
-rw-r--r-- | usr.bin/cmp/regular.c | 15 | ||||
-rw-r--r-- | usr.bin/cmp/special.c | 9 |
3 files changed, 24 insertions, 18 deletions
diff --git a/usr.bin/cmp/cmp.c b/usr.bin/cmp/cmp.c index 44eb7d1af02..324ac2721bc 100644 --- a/usr.bin/cmp/cmp.c +++ b/usr.bin/cmp/cmp.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cmp.c,v 1.7 1998/01/21 22:16:32 deraadt Exp $ */ +/* $OpenBSD: cmp.c,v 1.8 1999/08/03 16:02:44 mickey Exp $ */ /* $NetBSD: cmp.c,v 1.7 1995/09/08 03:22:56 tls Exp $ */ /* @@ -44,7 +44,7 @@ static char copyright[] = #if 0 static char sccsid[] = "@(#)cmp.c 8.3 (Berkeley) 4/2/94"; #else -static char rcsid[] = "$OpenBSD: cmp.c,v 1.7 1998/01/21 22:16:32 deraadt Exp $"; +static char rcsid[] = "$OpenBSD: cmp.c,v 1.8 1999/08/03 16:02:44 mickey Exp $"; #endif #endif /* not lint */ @@ -89,7 +89,7 @@ main(argc, argv) default: usage(); } -endargs: + argv += optind; argc -= optind; @@ -113,39 +113,43 @@ endargs: err(ERR_EXIT, "%s", file1); } if (strcmp(file2 = argv[1], "-") == 0) { - if (special) + if (special) { if (sflag) exit(ERR_EXIT); else errx(ERR_EXIT, "standard input may only be specified once"); + } special = 1; fd2 = 0; file2 = "stdin"; } - else if ((fd2 = open(file2, O_RDONLY, 0)) < 0) + else if ((fd2 = open(file2, O_RDONLY, 0)) < 0) { if (sflag) exit(ERR_EXIT); else err(ERR_EXIT, "%s", file2); + } skip1 = argc > 2 ? strtoq(argv[2], NULL, 0) : 0; skip2 = argc == 4 ? strtoq(argv[3], NULL, 0) : 0; if (!special) { - if (fstat(fd1, &sb1)) + if (fstat(fd1, &sb1)) { if (sflag) exit(ERR_EXIT); else err(ERR_EXIT, "%s", file1); + } if (!S_ISREG(sb1.st_mode)) special = 1; else { - if (fstat(fd2, &sb2)) + if (fstat(fd2, &sb2)) { if (sflag) exit(ERR_EXIT); else err(ERR_EXIT, "%s", file2); + } if (!S_ISREG(sb2.st_mode)) special = 1; } diff --git a/usr.bin/cmp/regular.c b/usr.bin/cmp/regular.c index 68dd087dcf5..49c6c38695a 100644 --- a/usr.bin/cmp/regular.c +++ b/usr.bin/cmp/regular.c @@ -1,4 +1,4 @@ -/* $OpenBSD: regular.c,v 1.2 1996/06/26 05:32:06 deraadt Exp $ */ +/* $OpenBSD: regular.c,v 1.3 1999/08/03 16:02:44 mickey Exp $ */ /* $NetBSD: regular.c,v 1.2 1995/09/08 03:22:59 tls Exp $ */ /*- @@ -38,7 +38,7 @@ #if 0 static char sccsid[] = "@(#)regular.c 8.3 (Berkeley) 4/2/94"; #else -static char rcsid[] = "$OpenBSD: regular.c,v 1.2 1996/06/26 05:32:06 deraadt Exp $"; +static char rcsid[] = "$OpenBSD: regular.c,v 1.3 1999/08/03 16:02:44 mickey Exp $"; #endif #endif /* not lint */ @@ -78,22 +78,23 @@ c_regular(fd1, file1, skip1, len1, fd2, file2, skip2, 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) + if ((p1 = mmap(NULL, (size_t)length, PROT_READ, + MAP_PRIVATE, fd1, skip1)) == (u_char *)-1) err(ERR_EXIT, "%s", file1); - if ((p2 = (u_char *)mmap(NULL, - (size_t)length, PROT_READ, 0, fd2, skip2)) == (u_char *)-1) + if ((p2 = mmap(NULL, (size_t)length, PROT_READ, + MAP_PRIVATE, fd2, skip2)) == (u_char *)-1) err(ERR_EXIT, "%s", file2); dfound = 0; for (byte = line = 1; length--; ++p1, ++p2, ++byte) { - if ((ch = *p1) != *p2) + if ((ch = *p1) != *p2) { if (lflag) { dfound = 1; (void)printf("%6qd %3o %3o\n", byte, ch, *p2); } else diffmsg(file1, file2, byte, line); /* NOTREACHED */ + } if (ch == '\n') ++line; } diff --git a/usr.bin/cmp/special.c b/usr.bin/cmp/special.c index 399072daa74..a6f01dc9a03 100644 --- a/usr.bin/cmp/special.c +++ b/usr.bin/cmp/special.c @@ -1,4 +1,4 @@ -/* $OpenBSD: special.c,v 1.2 1996/06/26 05:32:07 deraadt Exp $ */ +/* $OpenBSD: special.c,v 1.3 1999/08/03 16:02:44 mickey Exp $ */ /* $NetBSD: special.c,v 1.2 1995/09/08 03:23:00 tls Exp $ */ /*- @@ -38,7 +38,7 @@ #if 0 static char sccsid[] = "@(#)special.c 8.3 (Berkeley) 4/2/94"; #else -static char rcsid[] = "$OpenBSD: special.c,v 1.2 1996/06/26 05:32:07 deraadt Exp $"; +static char rcsid[] = "$OpenBSD: special.c,v 1.3 1999/08/03 16:02:44 mickey Exp $"; #endif #endif /* not lint */ @@ -67,6 +67,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; @@ -74,19 +75,19 @@ 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); if (ch1 == EOF || ch2 == EOF) break; - if (ch1 != ch2) + if (ch1 != ch2) { if (lflag) { dfound = 1; (void)printf("%6qd %3o %3o\n", byte, ch1, ch2); } else diffmsg(file1, file2, byte, line); /* NOTREACHED */ + } if (ch1 == '\n') ++line; } |