summaryrefslogtreecommitdiff
path: root/sum.c
diff options
context:
space:
mode:
authorJakob Kaivo <jkk@ung.org>2022-04-17 21:48:14 -0400
committerJakob Kaivo <jkk@ung.org>2022-04-17 21:48:14 -0400
commit73d6489ee4eb973f95dbe0f941ef89668a21d882 (patch)
tree62187dccc7d31d5ef9aae989792c543c128f9f4c /sum.c
parent02d1614c7263ba547df253e7e7885174b843a5c9 (diff)
clean up some more
Diffstat (limited to 'sum.c')
-rw-r--r--sum.c35
1 files changed, 5 insertions, 30 deletions
diff --git a/sum.c b/sum.c
index ec38012..3b5c57c 100644
--- a/sum.c
+++ b/sum.c
@@ -20,7 +20,6 @@
#define _POSIX_C_SOURCE 200809L
#include <errno.h>
#include <inttypes.h>
-#include <libgen.h>
#include <limits.h>
#include <locale.h>
#include <stdio.h>
@@ -30,8 +29,6 @@
#define UINT16_BIT (16)
#define BLOCK_SIZE (512)
-enum algorithm { UNSPECIFIED, ALTERNATIVE };
-
struct sum {
uintmax_t size;
uintmax_t sum;
@@ -68,17 +65,7 @@ static struct sum sum_obsolete(FILE *f, int alt)
return sum;
}
-static struct sum sum_unspecified(FILE *f)
-{
- return sum_obsolete(f, 0);
-}
-
-static struct sum sum_alternative(FILE *f)
-{
- return sum_obsolete(f, 1);
-}
-
-int cksum(const char *path, enum algorithm alg)
+static int cksum(const char *path, int alt)
{
FILE *f = stdin;
if (path && strcmp(path, "-")) {
@@ -90,19 +77,7 @@ int cksum(const char *path, enum algorithm alg)
return 1;
}
- struct sum sum;
- switch (alg) {
- case UNSPECIFIED:
- sum = sum_unspecified(f);
- break;
-
- case ALTERNATIVE:
- sum = sum_alternative(f);
- break;
-
- default:
- break;
- }
+ struct sum sum = sum_obsolete(f, alt);
printf("%"PRIuMAX" %"PRIuMAX"", sum.sum, sum.size);
@@ -121,13 +96,13 @@ int main(int argc, char *argv[])
fprintf(stderr, "sum: utility is obsolete; use cksum\n");
- enum algorithm alg = UNSPECIFIED;
+ int alt = 0;
int c;
while ((c = getopt(argc, argv, "r")) != -1) {
switch (c) {
case 'r':
- alg = ALTERNATIVE;
+ alt = 1;
break;
default:
@@ -137,7 +112,7 @@ int main(int argc, char *argv[])
int r = 0;
do {
- r |= cksum(argv[optind++], alg);
+ r |= cksum(argv[optind++], alt);
} while (optind < argc);
return r;
}