Pádraig Brady <[email protected]> writes:

> Map md5sum and sha{1,224,256,385,512} to use cksum logic,
> which selects appropriate behavior at runtime, rather than
> separate binaries for each closely related utility.
>
> $ size src/coreutils  # before
>    text          data     bss     dec     hex filename
> 1349509          6812  619312 1975633  1e2551 src/coreutils
> $ size src/coreutils  # after
>    text          data     bss     dec     hex filename
> 1306933          6748  619152 1932833  1d7e21 src/coreutils
>
> * build-aux/gen-single-binary.sh: Map sha*sum to use cksum.c
> * src/cksum.c: Adjust to behave more like sha*sum,
> when the algorithm to something other than "crc".
> * src/cksum.h: Expose the cksum_algorithm global and enum.
> * src/coreutils-md5sum.c: Set cksum_algorithm and call cksum logic.
> * src/coreutils-sha1sum.c: Likewise.
> * src/coreutils-sha224sum.c Likewise.
> * src/coreutils-sha256sum.c Likewise.
> * src/coreutils-sha384sum.c Likewise.
> * src/coreutils-sha512sum.c Likewise.
> * NEWS: Mention the improvement.

Size is slightly larger with multiple binaries, here are the results
using './configure' and './configure CFLAGS="-O3 -flto"':

    $ size -G cksum-*
          text       data        bss      total filename
         69898      56742        656     127296 cksum-default-new
         69450      56166        656     126272 cksum-default-old
         62234      49102        544     111880 cksum-O3-flto-new
         61786      48462        512     110760 cksum-O3-flto-old

But that is fine; they are still small.

The tests/misc/getopt_vs_usage.sh test fails with this change. You can
amend the commit with the following diff to fix it, plus a tiny
whitespace cleanup:

diff --git a/src/cksum.c b/src/cksum.c
index 2f1d29060..2b1f7fc1b 100644
--- a/src/cksum.c
+++ b/src/cksum.c
@@ -423,7 +423,7 @@ enum
 static struct option const legacy_long_options[] =
 {
   { "check", no_argument, nullptr, 'c' },
-  { "ignore-missing", no_argument, nullptr, IGNORE_MISSING_OPTION},
+  { "ignore-missing", no_argument, nullptr, IGNORE_MISSING_OPTION },
   { "quiet", no_argument, nullptr, QUIET_OPTION },
   { "status", no_argument, nullptr, STATUS_OPTION },
   { "warn", no_argument, nullptr, 'w' },
@@ -431,8 +431,8 @@ static struct option const legacy_long_options[] =
   { "tag", no_argument, nullptr, TAG_OPTION },
   { "zero", no_argument, nullptr, 'z' },
 
-  { "binary", no_argument, nullptr, 'b' },
-  { "text", no_argument, nullptr, 't' },
+  { "binary", no_argument, nullptr, 'b' }, /* Deprecated.  */
+  { "text", no_argument, nullptr, 't' }, /* Deprecated.  */
 
   { GETOPT_HELP_OPTION_DECL },
   { GETOPT_VERSION_OPTION_DECL },

Collin

Reply via email to