From 7c72fc10713a4e4fd85e2554d69fd11a71bef9d2 Mon Sep 17 00:00:00 2001 From: Jakob Kaivo Date: Thu, 21 Nov 2019 15:15:27 -0500 Subject: output invoked name in errors --- cksum.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/cksum.c b/cksum.c index ccf32bb..b70582a 100644 --- a/cksum.c +++ b/cksum.c @@ -27,18 +27,20 @@ #include #include -enum algorithm { UNSPECIFIED, ALTERNATIVE, CRC32 }; - #define MAX_SUM_WIDTH (32) #define UINT32_BIT (32) #define UINT16_BIT (16) #define BLOCK_SIZE (512) +enum algorithm { UNSPECIFIED, ALTERNATIVE, CRC32 }; + struct sum { uintmax_t size; uintmax_t sum; }; +static char *progname = NULL; + static uint32_t reverse(uint32_t n, int width) { uint32_t r = 0; @@ -124,7 +126,7 @@ int cksum(const char *path, enum algorithm alg) } if (f == NULL) { - fprintf(stderr, "cksum: %s: %s\n", path, strerror(errno)); + fprintf(stderr, "%s: %s: %s\n", progname, path, strerror(errno)); return 1; } @@ -159,7 +161,6 @@ int cksum(const char *path, enum algorithm alg) static int sum(int argc, char *argv[]) { - setlocale(LC_ALL, ""); fprintf(stderr, "sum: utility is obsolete; use cksum\n"); enum algorithm alg = UNSPECIFIED; @@ -187,8 +188,8 @@ int main(int argc, char *argv[]) { setlocale(LC_ALL, ""); - char *base = basename(argv[0]); - if (!strcmp(base, "sum")) { + progname = basename(argv[0]); + if (!strcmp(progname, "sum")) { return sum(argc, argv); } -- cgit v1.2.1