From 4b63e16d20f2c89b39e26a10cb1cdbcbf079df89 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Sun, 24 Oct 2010 14:54:53 +0200 Subject: [PATCH] md5/sha1sum: code shrink function old new delta hash_file 357 279 -78 Signed-off-by: Denys Vlasenko --- coreutils/md5_sha1_sum.c | 41 ++++++++++++++++++++-------------------- 1 file changed, 21 insertions(+), 20 deletions(-) diff --git a/coreutils/md5_sha1_sum.c b/coreutils/md5_sha1_sum.c index e79210c0d..d3d294de9 100644 --- a/coreutils/md5_sha1_sum.c +++ b/coreutils/md5_sha1_sum.c @@ -10,13 +10,13 @@ /* This is a NOEXEC applet. Be very careful! */ -typedef enum { +enum { /* 4th letter of applet_name is... */ HASH_MD5 = 's', /* "md5>s 0) { update(&context, in_buf, count); } @@ -99,27 +101,26 @@ int md5_sha1_sum_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; int md5_sha1_sum_main(int argc UNUSED_PARAM, char **argv) { int return_value = EXIT_SUCCESS; - uint8_t *hash_value; unsigned flags; - /*hash_algo_t hash_algo = applet_name[3];*/ if (ENABLE_FEATURE_MD5_SHA1_SUM_CHECK) { /* -b "binary", -t "text" are ignored (shaNNNsum compat) */ flags = getopt32(argv, "scwbt"); + argv += optind; + //argc -= optind; + } else { + argv += 1; + //argc -= 1; } - else optind = 1; - argv += optind; - //argc -= optind; if (!*argv) *--argv = (char*)"-"; if (ENABLE_FEATURE_MD5_SHA1_SUM_CHECK && !(flags & FLAG_CHECK)) { if (flags & FLAG_SILENT) { - bb_error_msg_and_die - ("-%c is meaningful only when verifying checksums", 's'); - } else if (flags & FLAG_WARN) { - bb_error_msg_and_die - ("-%c is meaningful only when verifying checksums", 'w'); + bb_error_msg_and_die("-%c is meaningful only with -c", 's'); + } + if (flags & FLAG_WARN) { + bb_error_msg_and_die("-%c is meaningful only with -c", 'w'); } } @@ -130,13 +131,13 @@ int md5_sha1_sum_main(int argc UNUSED_PARAM, char **argv) char *line; if (argv[1]) { - bb_error_msg_and_die - ("only one argument may be specified when using -c"); + bb_error_msg_and_die("only one argument may be specified with -c"); } pre_computed_stream = xfopen_stdin(argv[0]); while ((line = xmalloc_fgetline(pre_computed_stream)) != NULL) { + uint8_t *hash_value; char *filename_ptr; count_total++; @@ -157,7 +158,7 @@ int md5_sha1_sum_main(int argc UNUSED_PARAM, char **argv) *filename_ptr = '\0'; filename_ptr += 2; - hash_value = hash_file(filename_ptr /*, hash_algo*/); + hash_value = hash_file(filename_ptr); if (hash_value && (strcmp((char*)hash_value, line) == 0)) { if (!(flags & FLAG_SILENT)) @@ -183,7 +184,7 @@ int md5_sha1_sum_main(int argc UNUSED_PARAM, char **argv) */ } else { do { - hash_value = hash_file(*argv/*, hash_algo*/); + uint8_t *hash_value = hash_file(*argv); if (hash_value == NULL) { return_value = EXIT_FAILURE; } else { -- 2.25.1