Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 27 May 2001 23:29:27 -0400
From:      Mike Heffner <mheffner@cowpie.acm.vt.edu>
To:        freebsd-audit@freebsd.org
Subject:   cmp(1) patch
Message-ID:  <20010527232926.A85869@cowpie.acm.vt.edu>

next in thread | raw e-mail | index | archive | help
BDECFLAGS cleanup, respect -s flag in one place, return instead of
exit() at end of main. Please review.

Index: cmp.c
===================================================================
RCS file: /home/ncvs/src/usr.bin/cmp/cmp.c,v
retrieving revision 1.9
diff -u -r1.9 cmp.c
--- cmp.c	2000/07/25 13:01:34	1.9
+++ cmp.c	2001/05/26 21:57:56
@@ -58,6 +58,7 @@
 
 int	lflag, sflag, xflag, zflag;
 
+int main __P((int, char *[]));
 static void usage __P((void));
 
 int
@@ -68,7 +69,7 @@
 	struct stat sb1, sb2;
 	off_t skip1, skip2;
 	int ch, fd1, fd2, special;
-	char *file1, *file2;
+	const char *file1, *file2;
 
 	while ((ch = getopt(argc, argv, "-lsxz")) != -1)
 		switch (ch) {
@@ -117,9 +118,13 @@
 			exit(1);
 	}
 	if (strcmp(file2 = argv[1], "-") == 0) {
-		if (special)
-			errx(ERR_EXIT,
+		if (special) {
+			if (!sflag)
+				errx(ERR_EXIT,
 				"standard input may only be specified once");
+			else
+				exit(1);
+		}
 		special = 1;
 		fd2 = 0;
 		file2 = "stdin";
@@ -160,14 +165,14 @@
 	else {
 		if (zflag && sb1.st_size != sb2.st_size) {
 			if (!sflag)
-				(void) printf("%s %s differ: size\n",
+				(void)printf("%s %s differ: size\n",
 				    file1, file2);
 			exit(DIFF_EXIT);
 		}
 		c_regular(fd1, file1, skip1, sb1.st_size,
 		    fd2, file2, skip2, sb2.st_size);
 	}
-	exit(0);
+	return (0);
 }
 
 static void
Index: extern.h
===================================================================
RCS file: /home/ncvs/src/usr.bin/cmp/extern.h,v
retrieving revision 1.2
diff -u -r1.2 extern.h
--- extern.h	2000/05/15 08:30:43	1.2
+++ extern.h	2001/05/26 21:57:56
@@ -40,9 +40,10 @@
 #define DIFF_EXIT	1
 #define ERR_EXIT	2	/* error exit code */
 
-void	c_regular __P((int, char *, off_t, off_t, int, char *, off_t, off_t));
-void	c_special __P((int, char *, off_t, int, char *, off_t));
-void	diffmsg __P((char *, char *, off_t, off_t));
-void	eofmsg __P((char *));
+void	c_regular __P((int, const char *, off_t, off_t, int,
+	    const char *, off_t, off_t));
+void	c_special __P((int, const char *, off_t, int, const char *, off_t));
+void	diffmsg __P((const char *, const char *, off_t, off_t));
+void	eofmsg __P((const char *));
 
 extern int lflag, sflag, xflag;
Index: misc.c
===================================================================
RCS file: /home/ncvs/src/usr.bin/cmp/misc.c,v
retrieving revision 1.2
diff -u -r1.2 misc.c
--- misc.c	1998/12/06 22:58:15	1.2
+++ misc.c	2001/05/26 21:57:57
@@ -45,7 +45,7 @@
 
 void
 eofmsg(file)
-	char *file;
+	const char *file;
 {
 	if (!sflag)
 		warnx("EOF on %s", file);
@@ -54,11 +54,11 @@
 
 void
 diffmsg(file1, file2, byte, line)
-	char *file1, *file2;
+	const char *file1, *file2;
 	off_t byte, line;
 {
 	if (!sflag)
-		(void)printf("%s %s differ: char %qd, line %qd\n",
-		    file1, file2, byte, line);
+		(void)printf("%s %s differ: char %lld, line %lld\n",
+		    file1, file2, (long long)byte, (long long)line);
 	exit(DIFF_EXIT);
 }
Index: regular.c
===================================================================
RCS file: /home/ncvs/src/usr.bin/cmp/regular.c,v
retrieving revision 1.10
diff -u -r1.10 regular.c
--- regular.c	2000/06/20 20:28:40	1.10
+++ regular.c	2001/05/26 21:57:57
@@ -56,7 +56,7 @@
 void
 c_regular(fd1, file1, skip1, len1, fd2, file2, skip2, len2)
 	int fd1, fd2;
-	char *file1, *file2;
+	const char *file1, *file2;
 	off_t skip1, len1, skip2, len2;
 {
 	u_char ch, *p1, *p2;
@@ -81,8 +81,10 @@
 	off2 = ROUNDPAGE(skip2);
 
 	length = MIN(len1, len2);
-	if (length > SIZE_T_MAX)
-		return (c_special(fd1, file1, skip1, fd2, file2, skip2));
+	if (length > SIZE_T_MAX) {
+		c_special(fd1, file1, skip1, fd2, file2, skip2);
+		return;
+	}
 
 	if ((p1 = (u_char *)mmap(NULL, (size_t)len1 + skip1 % pagesize,
 	    PROT_READ, MAP_SHARED, fd1, off1)) == (u_char *)MAP_FAILED)
@@ -101,10 +103,12 @@
 		if ((ch = *p1) != *p2) {
 			if (xflag) {
 				dfound = 1;
-				(void)printf("%08qx %02x %02x\n", byte - 1, ch, *p2);
+				(void)printf("%08llx %02x %02x\n",
+				    (long long)byte - 1, ch, *p2);
 			} else if (lflag) {
 				dfound = 1;
-				(void)printf("%6qd %3o %3o\n", byte, ch, *p2);
+				(void)printf("%6lld %3o %3o\n", (long long)byte,
+				    ch, *p2);
 			} else
 				diffmsg(file1, file2, byte, line);
 				/* NOTREACHED */
Index: special.c
===================================================================
RCS file: /home/ncvs/src/usr.bin/cmp/special.c,v
retrieving revision 1.4
diff -u -r1.4 special.c
--- special.c	1999/04/25 22:37:57	1.4
+++ special.c	2001/05/26 21:57:57
@@ -47,7 +47,7 @@
 void
 c_special(fd1, file1, skip1, fd2, file2, skip2)
 	int fd1, fd2;
-	char *file1, *file2;
+	const char *file1, *file2;
 	off_t skip1, skip2;
 {
 	int ch1, ch2;
@@ -76,7 +76,8 @@
 		if (ch1 != ch2) {
 			if (lflag) {
 				dfound = 1;
-				(void)printf("%6qd %3o %3o\n", byte, ch1, ch2);
+				(void)printf("%6lld %3o %3o\n",
+				    (long long)byte, ch1, ch2);
 			} else {
 				diffmsg(file1, file2, byte, line);
 				/* NOTREACHED */

Mike

-- 

  Mike Heffner               <mheffner@vt.edu>
  Fredericksburg, VA       <mikeh@FreeBSD.org>
      http://filebox.vt.edu/users/mheffner

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-audit" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20010527232926.A85869>