aboutsummaryrefslogtreecommitdiff
path: root/coreutils
diff options
context:
space:
mode:
Diffstat (limited to 'coreutils')
-rw-r--r--coreutils/md5_sha1_sum.c14
1 files changed, 10 insertions, 4 deletions
diff --git a/coreutils/md5_sha1_sum.c b/coreutils/md5_sha1_sum.c
index 4506aeb56..ee6bda6fd 100644
--- a/coreutils/md5_sha1_sum.c
+++ b/coreutils/md5_sha1_sum.c
@@ -159,6 +159,7 @@ enum {
159#define FLAG_SILENT 1 159#define FLAG_SILENT 1
160#define FLAG_CHECK 2 160#define FLAG_CHECK 2
161#define FLAG_WARN 4 161#define FLAG_WARN 4
162#define FLAG_BINARY 8
162 163
163/* This might be useful elsewhere */ 164/* This might be useful elsewhere */
164static unsigned char *hash_bin_to_hex(unsigned char *hash_value, 165static unsigned char *hash_bin_to_hex(unsigned char *hash_value,
@@ -281,16 +282,21 @@ int md5_sha1_sum_main(int argc UNUSED_PARAM, char **argv)
281#if ENABLE_SHA3SUM 282#if ENABLE_SHA3SUM
282 unsigned sha3_width = 224; 283 unsigned sha3_width = 224;
283#endif 284#endif
285 const char *fmt = "%s %s\n";
284 286
285 if (ENABLE_FEATURE_MD5_SHA1_SUM_CHECK) { 287 if (ENABLE_FEATURE_MD5_SHA1_SUM_CHECK) {
286 /* -b "binary", -t "text" are ignored (shaNNNsum compat) */ 288 /* -t per se is a no-op (it means "text mode").
289 * -b sets the '*' binary mode indicator in the output.
290 * -t unsets -b (-bt is the same as -t, which is the same as no option) */
287 /* -s and -w require -c */ 291 /* -s and -w require -c */
288#if ENABLE_SHA3SUM 292#if ENABLE_SHA3SUM
289 if (applet_name[3] == HASH_SHA3 && (!ENABLE_SHA384SUM || applet_name[4] != '8')) 293 if (applet_name[3] == HASH_SHA3 && (!ENABLE_SHA384SUM || applet_name[4] != '8'))
290 flags = getopt32(argv, "^" "scwbta:+" "\0" "s?c:w?c", &sha3_width); 294 flags = getopt32(argv, "^" "scwbta:+" "\0" "t-b:s?c:w?c", &sha3_width);
291 else 295 else
292#endif 296#endif
293 flags = getopt32(argv, "^" "scwbt" "\0" "s?c:w?c"); 297 flags = getopt32(argv, "^" "scwbt" "\0" "t-b:s?c:w?c");
298 if (flags & FLAG_BINARY)
299 fmt = "%s *%s\n";
294 } else { 300 } else {
295#if ENABLE_SHA3SUM 301#if ENABLE_SHA3SUM
296 if (applet_name[3] == HASH_SHA3 && (!ENABLE_SHA384SUM || applet_name[4] != '8')) 302 if (applet_name[3] == HASH_SHA3 && (!ENABLE_SHA384SUM || applet_name[4] != '8'))
@@ -375,7 +381,7 @@ int md5_sha1_sum_main(int argc UNUSED_PARAM, char **argv)
375 if (hash_value == NULL) { 381 if (hash_value == NULL) {
376 return_value = EXIT_FAILURE; 382 return_value = EXIT_FAILURE;
377 } else { 383 } else {
378 printf("%s %s\n", hash_value, *argv); 384 printf(fmt, hash_value, *argv);
379 free(hash_value); 385 free(hash_value);
380 } 386 }
381 } 387 }