BSD 4_4_Lite1 release
[unix-history] / usr / src / usr.bin / cmp / cmp.c
index 8dd69cb..dc6c64e 100644 (file)
@@ -1,5 +1,5 @@
 /*
 /*
- * Copyright (c) 1987, 1990, 1993
+ * Copyright (c) 1987, 1990, 1993, 1994
  *     The Regents of the University of California.  All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  *     The Regents of the University of California.  All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
 
 #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) 6/6/93";
+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[];
@@ -84,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();
@@ -97,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;
                }
@@ -135,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);
 }
 }