Previously, 'cksum *' would exit early if * contained any
directories or other files causing fread() errors.

Exit status is set to indicate an error has occurred.
---
 cksum.c | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)

diff --git a/cksum.c b/cksum.c
index 3355b4c..179ab05 100644
--- a/cksum.c
+++ b/cksum.c
@@ -59,7 +59,7 @@ static const unsigned long crctab[] = {         0x00000000,
 0xa2f33668, 0xbcb4666d, 0xb8757bda, 0xb5365d03, 0xb1f740b4
 };
 
-static void
+static int
 cksum(FILE *fp, const char *s)
 {
        size_t len = 0, i, n;
@@ -71,8 +71,10 @@ cksum(FILE *fp, const char *s)
                        ck = (ck << 8) ^ crctab[(ck >> 24) ^ buf[i]];
                len += n;
        }
-       if (ferror(fp))
-               eprintf("fread %s:", s ? s : "<stdin>");
+       if (ferror(fp)) {
+               weprintf("fread %s:", s ? s : "<stdin>");
+               return 1;
+       }
 
        for (i = len; i; i >>= 8)
                ck = (ck << 8) ^ crctab[(ck >> 24) ^ (i & 0xFF)];
@@ -83,6 +85,7 @@ cksum(FILE *fp, const char *s)
                fputs(s, stdout);
        }
        putchar('\n');
+       return 0;
 }
 
 int
@@ -105,7 +108,7 @@ main(int argc, char *argv[])
                                ret = 1;
                                continue;
                        }
-                       cksum(fp, *argv);
+                       ret |= cksum(fp, *argv);
                        if (fp != stdin && fshut(fp, *argv))
                                ret = 1;
                }
-- 
2.3.5


Reply via email to