BSD 4_4_Lite1 release
[unix-history] / usr / src / usr.bin / cmp / cmp.c
index d3320a3..dc6c64e 100644 (file)
@@ -1,34 +1,63 @@
 /*
 /*
- * Copyright (c) 1987, 1990, 1993
+ * Copyright (c) 1987, 1990, 1993, 1994
  *     The Regents of the University of California.  All rights reserved.
  *
  *     The Regents of the University of California.  All rights reserved.
  *
- * %sccs.include.redist.c%
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ *    must display the following acknowledgement:
+ *     This product includes software developed by the University of
+ *     California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
  */
 
 #ifndef lint
 static char copyright[] =
  */
 
 #ifndef lint
 static char copyright[] =
-"@(#) Copyright (c) 1987, 1990, 1993\n\
+"@(#) Copyright (c) 1987, 1990, 1993, 1994\n\
        The Regents of the University of California.  All rights reserved.\n";
 #endif /* not lint */
 
 #ifndef lint
        The Regents of the University of California.  All rights reserved.\n";
 #endif /* not lint */
 
 #ifndef lint
-static char sccsid[] = "@(#)cmp.c      8.1 (Berkeley) %G%";
+static char sccsid[] = "@(#)cmp.c      8.3 (Berkeley) 4/2/94";
 #endif /* not lint */
 
 #include <sys/types.h>
 #include <sys/stat.h>
 #endif /* not lint */
 
 #include <sys/types.h>
 #include <sys/stat.h>
+
+#include <err.h>
 #include <fcntl.h>
 #include <fcntl.h>
-#include <errno.h>
-#include <unistd.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
+#include <unistd.h>
+
 #include "extern.h"
 
 int    lflag, sflag;
 
 static void usage __P((void));
 
 #include "extern.h"
 
 int    lflag, sflag;
 
 static void usage __P((void));
 
+int
 main(argc, argv)
        int argc;
        char *argv[];
 main(argc, argv)
        int argc;
        char *argv[];
@@ -58,7 +87,7 @@ endargs:
        argc -= optind;
 
        if (lflag && sflag)
        argc -= optind;
 
        if (lflag && sflag)
-               err("only one of -l and -s may be specified");
+               errx(ERR_EXIT, "only one of -l and -s may be specified");
 
        if (argc < 2 || argc > 4)
                usage();
 
        if (argc < 2 || argc > 4)
                usage();
@@ -71,28 +100,29 @@ endargs:
                file1 = "stdin";
        }
        else if ((fd1 = open(file1, O_RDONLY, 0)) < 0)
                file1 = "stdin";
        }
        else if ((fd1 = open(file1, O_RDONLY, 0)) < 0)
-               err("%s: %s", file1, strerror(errno));
+               err(ERR_EXIT, "%s", file1);
        if (strcmp(file2 = argv[1], "-") == 0) {
                if (special)
        if (strcmp(file2 = argv[1], "-") == 0) {
                if (special)
-                       err("standard input may only be specified once");
+                       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)
                special = 1;
                fd2 = 0;
                file2 = "stdin";
        }
        else if ((fd2 = open(file2, O_RDONLY, 0)) < 0)
-               err("%s: %s", file2, strerror(errno));
+               err(ERR_EXIT, "%s", file2);
 
        skip1 = argc > 2 ? strtol(argv[2], NULL, 10) : 0;
        skip2 = argc == 4 ? strtol(argv[3], NULL, 10) : 0;
 
        if (!special) {
                if (fstat(fd1, &sb1))
 
        skip1 = argc > 2 ? strtol(argv[2], NULL, 10) : 0;
        skip2 = argc == 4 ? strtol(argv[3], NULL, 10) : 0;
 
        if (!special) {
                if (fstat(fd1, &sb1))
-                       err("%s: %s", file1, strerror(errno));
+                       err(ERR_EXIT, "%s", file1);
                if (!S_ISREG(sb1.st_mode))
                        special = 1;
                else {
                        if (fstat(fd2, &sb2))
                if (!S_ISREG(sb1.st_mode))
                        special = 1;
                else {
                        if (fstat(fd2, &sb2))
-                               err("%s: %s", file2, strerror(errno));
+                               err(ERR_EXIT, "%s", file2);
                        if (!S_ISREG(sb2.st_mode))
                                special = 1;
                }
                        if (!S_ISREG(sb2.st_mode))
                                special = 1;
                }
@@ -109,7 +139,8 @@ endargs:
 static void
 usage()
 {
 static void
 usage()
 {
+
        (void)fprintf(stderr,
            "usage: cmp [-l | s] file1 file2 [skip1 [skip2]]\n");
        (void)fprintf(stderr,
            "usage: cmp [-l | s] file1 file2 [skip1 [skip2]]\n");
-       exit(2);
+       exit(ERR_EXIT);
 }
 }