aboutsummaryrefslogtreecommitdiff
path: root/coreutils
diff options
context:
space:
mode:
authorMartin Storsjö <martin@martin.st>2025-12-06 00:40:57 +0200
committerDenys Vlasenko <vda.linux@googlemail.com>2026-01-18 03:09:52 +0100
commit993d416d02442da1c33d8b26d706e24134b3d018 (patch)
treeb2f76f20c59f8e8bd369e97fa4e575fbae4e1e21 /coreutils
parentfc9d352b4cae7bd962723480d1323fb1b5f46e32 (diff)
downloadbusybox-w32-993d416d02442da1c33d8b26d706e24134b3d018.tar.gz
busybox-w32-993d416d02442da1c33d8b26d706e24134b3d018.tar.bz2
busybox-w32-993d416d02442da1c33d8b26d706e24134b3d018.zip
md5/sha1sum: Honor the -b flag in the output
The output of md5sum/sha1sum contains a character to indicate what mode was used to read the file - '*' for binary, and ' ' for text or where binary is insignificant. This flag character makes a difference for the ffmpeg testsuite. This testsuite contains a number of reference files (e.g. [1]), containing the expected md5sum output for those files, which is checked verbatim. By making busybox's md5sum honor this flag in the output, ffmpeg's testsuite can run successfully on top of busybox. The flag is only partially implemented; in coreutils md5sum, a later "-t" option overrides an earlier "-b" option. Here, just check if a "-b" option was specified or not. Neither flag affects how the files actually are read. [1] https://code.ffmpeg.org/FFmpeg/FFmpeg/src/commit/894da5ca7d742e4429ffb2af534fcda0103ef593/tests/ref/acodec/flac Signed-off-by: Martin Storsjö <martin@martin.st> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
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 }