don't display a file name if using standard input (POSIX 1003.2, D11.2)
authorKeith Bostic <bostic@ucbvax.Berkeley.EDU>
Thu, 28 Nov 1991 04:57:54 +0000 (20:57 -0800)
committerKeith Bostic <bostic@ucbvax.Berkeley.EDU>
Thu, 28 Nov 1991 04:57:54 +0000 (20:57 -0800)
SCCS-vsn: usr.bin/cksum/cksum.c 5.6
SCCS-vsn: usr.bin/cksum/print.c 5.2

usr/src/usr.bin/cksum/cksum.c
usr/src/usr.bin/cksum/print.c

index 0c1388b..b44f537 100644 (file)
@@ -15,7 +15,7 @@ char copyright[] =
 #endif /* not lint */
 
 #ifndef lint
 #endif /* not lint */
 
 #ifndef lint
-static char sccsid[] = "@(#)cksum.c    5.5 (Berkeley) %G%";
+static char sccsid[] = "@(#)cksum.c    5.6 (Berkeley) %G%";
 #endif /* not lint */
 
 #include <sys/cdefs.h>
 #endif /* not lint */
 
 #include <sys/cdefs.h>
@@ -67,21 +67,21 @@ main(argc, argv)
        argv += optind;
 
        fd = STDIN_FILENO;
        argv += optind;
 
        fd = STDIN_FILENO;
-       fn = "stdin";
+       fn = NULL;
        rval = 0;
        do {
                if (*argv) {
                        fn = *argv++;
                        if ((fd = open(fn, O_RDONLY, 0)) < 0) {
        rval = 0;
        do {
                if (*argv) {
                        fn = *argv++;
                        if ((fd = open(fn, O_RDONLY, 0)) < 0) {
-                               (void)fprintf(stderr,
-                                   "cksum: %s: %s\n", fn, strerror(errno));
+                               (void)fprintf(stderr, "cksum: %s: %s\n",
+                                   fn, strerror(errno));
                                rval = 1;
                                continue;
                        }
                }
                if (cfncn(fd, &val, &len)) {
                                rval = 1;
                                continue;
                        }
                }
                if (cfncn(fd, &val, &len)) {
-                       (void)fprintf(stderr,
-                           "cksum: %s: %s\n", fn, strerror(errno));
+                       (void)fprintf(stderr, "cksum: %s: %s\n",
+                           fn ? fn : "stdin", strerror(errno));
                        rval = 1;
                } else
                        pfncn(fn, val, len);
                        rval = 1;
                } else
                        pfncn(fn, val, len);
index e2a78f8..74f198c 100644 (file)
@@ -6,7 +6,7 @@
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)print.c    5.1 (Berkeley) %G%";
+static char sccsid[] = "@(#)print.c    5.2 (Berkeley) %G%";
 #endif /* not lint */
 
 #include <sys/types.h>
 #endif /* not lint */
 
 #include <sys/types.h>
@@ -18,7 +18,10 @@ pcrc(fn, val, len)
        char *fn;
        u_long val, len;
 {
        char *fn;
        u_long val, len;
 {
-       (void)printf("%lu %lu %s\n", val, len, fn);
+       (void)printf("%lu %lu", val, len);
+       if (fn)
+               (void)printf(" %s", fn);
+       (void)printf("\n");
 }
 
 void
 }
 
 void
@@ -26,7 +29,10 @@ psum1(fn, val, len)
        char *fn;
        u_long val, len;
 {
        char *fn;
        u_long val, len;
 {
-       (void)printf("%lu %lu %s\n", val, (len + 1023) / 1024, fn);
+       (void)printf("%lu %lu", val, (len + 1023) / 1024);
+       if (fn)
+               (void)printf(" %s", fn);
+       (void)printf("\n");
 }
 
 void
 }
 
 void
@@ -34,5 +40,8 @@ psum2(fn, val, len)
        char *fn;
        u_long val, len;
 {
        char *fn;
        u_long val, len;
 {
-       (void)printf("%lu %lu %s\n", val, (len + 511) / 512, fn);
+       (void)printf("%lu %lu", val, (len + 511) / 512);
+       if (fn)
+               (void)printf(" %s", fn);
+       (void)printf("\n");
 }
 }