** Improvements
+ The multi-call binary built with configure --enable-single-binary
+ is reduced in size by 3.2% through the more efficient reuse of the cksum
+ utility by the md5sum and sha*sum utilities.
+
csplit, ls, and sort, now handle a more complete set of terminating signals.
'pinky' will now exit immediately upon receiving a write error, which is
override_single vdir ls
override_single arch uname
override_single chgrp chown
+override_single md5sum cksum
+override_single sha1sum cksum
+override_single sha224sum cksum
+override_single sha256sum cksum
+override_single sha384sum cksum
+override_single sha512sum cksum
for cmd in $ALL_PROGRAMS; do
echo "# Command $cmd"
# include "sum.h"
#endif
#if HASH_ALGO_CKSUM
+# include "cksum.h"
# include "cksum_crc.h"
# include "base64.h"
#endif
return sm3_stream (stream, resstream);
}
-enum Algorithm
-{
- bsd,
- sysv,
- crc,
- crc32b,
- md5,
- sha1,
- sha224,
- sha256,
- sha384,
- sha512,
- sha2,
- sha3,
- blake2b,
- sm3,
-};
-
static char const *const algorithm_args[] =
{
"bsd", "sysv", "crc", "crc32b", "md5", "sha1",
static_assert (countof (algorithm_bits) == countof (algorithm_args));
static bool algorithm_specified = false;
-static enum Algorithm cksum_algorithm = crc;
+static bool legacy_mode = false;
+enum Algorithm cksum_algorithm = crc;
+
static sumfn cksumfns[]=
{
bsd_sum_stream,
BASE64_OPTION,
};
+#if HASH_ALGO_CKSUM
+static struct option const legacy_long_options[] =
+{
+ { "check", no_argument, nullptr, 'c' },
+ { "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' },
+ { "strict", no_argument, nullptr, STRICT_OPTION },
+ { "tag", no_argument, nullptr, TAG_OPTION },
+ { "zero", no_argument, nullptr, 'z' },
+
+ { "binary", no_argument, nullptr, 'b' }, /* Deprecated. */
+ { "text", no_argument, nullptr, 't' }, /* Deprecated. */
+
+ { GETOPT_HELP_OPTION_DECL },
+ { GETOPT_VERSION_OPTION_DECL },
+ { nullptr, 0, nullptr, 0 }
+};
+#endif
+
static struct option const long_options[] =
{
#if HASH_ALGO_BLAKE2 || HASH_ALGO_CKSUM
Usage: %s [OPTION]... [FILE]...\n\
"), program_name);
#if HASH_ALGO_CKSUM
+ if (legacy_mode)
+ printf (_("\
+Print or check %s checksums.\n\
+"), DIGEST_TYPE_STRING);
+ else
fputs (_("\
Print or verify checksums.\n\
By default use the 32 bit CRC algorithm.\n\
emit_mandatory_arg_note ();
#endif
#if HASH_ALGO_CKSUM
+ if (! legacy_mode)
fputs (_("\
-a, --algorithm=TYPE select the digest type to use. See DIGEST below\
\n\
"), stdout);
+ if (! legacy_mode)
fputs (_("\
--base64 emit base64-encoded digests, not hexadecimal\
\n\
"), stdout);
#endif
#if !HASH_ALGO_SUM
-# if !HASH_ALGO_CKSUM
+# if HASH_ALGO_CKSUM
+ if (legacy_mode)
+ {
+# endif
if (O_BINARY)
fputs (_("\
-b, --binary read in binary mode (default unless reading tty stdin)\
fputs (_("\
-b, --binary read in binary mode\n\
"), stdout);
+# if HASH_ALGO_CKSUM
+ }
# endif
fputs (_("\
-c, --check read checksums from the FILEs and check them\n\
"), stdout);
# if HASH_ALGO_BLAKE2 || HASH_ALGO_CKSUM
+# if HASH_ALGO_CKSUM
+ if (! legacy_mode)
+# endif
fputs (_("\
-l, --length=BITS digest length in bits; must not exceed the max size\n\
and must be a multiple of 8 for blake2b;\n\
"), stdout);
# endif
# if HASH_ALGO_CKSUM
+ if (! legacy_mode)
fputs (_("\
--raw emit a raw binary digest, not hexadecimal\
\n\
"), stdout);
+ if (legacy_mode)
+ fputs (_("\
+ --tag create a BSD-style checksum\n\
+"), stdout);
+ else
fputs (_("\
--tag create a BSD-style checksum (the default)\n\
"), stdout);
+ if (! legacy_mode)
fputs (_("\
--untagged create a reversed style checksum, without digest type\n\
"), stdout);
--tag create a BSD-style checksum\n\
"), stdout);
# endif
-# if !HASH_ALGO_CKSUM
+# if HASH_ALGO_CKSUM
+ if (legacy_mode)
+ {
+# endif
if (O_BINARY)
fputs (_("\
-t, --text read in text mode (default if reading tty stdin)\n\
fputs (_("\
-t, --text read in text mode (default)\n\
"), stdout);
+# if HASH_ALGO_CKSUM
+ }
# endif
fputs (_("\
-z, --zero end each output line with NUL, not newline,\n\
"), stdout);
#endif
#if HASH_ALGO_CKSUM
+ if (! legacy_mode)
fputs (_("\
--debug indicate which implementation used\n\
"), stdout);
fputs (HELP_OPTION_DESCRIPTION, stdout);
fputs (VERSION_OPTION_DESCRIPTION, stdout);
#if HASH_ALGO_CKSUM
+ if (! legacy_mode)
fputs (_("\
\n\
DIGEST determines the digest algorithm and default output format:\n\
bool ok = true;
int binary = -1;
int prefix_tag = -1;
+ struct option const *long_opts = long_options;
+
+#if HASH_ALGO_CKSUM
+ if (cksum_algorithm != crc)
+ {
+ legacy_mode = true;
+ prefix_tag = 0;
+ algorithm_specified = true;
+ long_opts = legacy_long_options;
+ }
+#endif
/* Setting values of global variables. */
initialize_main (&argc, &argv);
#if HASH_ALGO_SUM
char const *short_opts = "rs";
#elif HASH_ALGO_CKSUM
- char const *short_opts = "a:l:bctwz";
+ char const *short_opts = legacy_mode ? "bctwz" : "a:l:bctwz";
char const *digest_length_str = "";
#elif HASH_ALGO_BLAKE2
char const *short_opts = "l:bctwz";
char const *short_opts = "bctwz";
#endif
- while ((opt = getopt_long (argc, argv, short_opts, long_options, nullptr))
+ while ((opt = getopt_long (argc, argv, short_opts, long_opts, nullptr))
!= -1)
switch (opt)
{
--- /dev/null
+enum Algorithm
+{
+ bsd,
+ sysv,
+ crc,
+ crc32b,
+ md5,
+ sha1,
+ sha224,
+ sha256,
+ sha384,
+ sha512,
+ sha2,
+ sha3,
+ blake2b,
+ sm3,
+};
+
+extern enum Algorithm cksum_algorithm;
--- /dev/null
+/* md5sum -- wrapper to cksum with the right algorithm.
+ Copyright (C) 2025 Free Software Foundation, Inc.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <https://www.gnu.org/licenses/>. */
+
+#include <config.h>
+#include "system.h"
+#include "cksum.h"
+
+/* Ensure that the main for cksum is declared even if the tool is not built
+ in this single-binary. */
+int single_binary_main_cksum (int argc, char **argv);
+int single_binary_main_md5sum (int argc, char **argv);
+
+int
+single_binary_main_md5sum (int argc, char **argv)
+{
+ cksum_algorithm = md5;
+ return single_binary_main_cksum (argc, argv);
+}
--- /dev/null
+/* sha1sum -- wrapper to cksum with the right algorithm.
+ Copyright (C) 2025 Free Software Foundation, Inc.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <https://www.gnu.org/licenses/>. */
+
+#include <config.h>
+#include "system.h"
+#include "cksum.h"
+
+/* Ensure that the main for cksum is declared even if the tool is not built
+ in this single-binary. */
+int single_binary_main_cksum (int argc, char **argv);
+int single_binary_main_sha1sum (int argc, char **argv);
+
+int
+single_binary_main_sha1sum (int argc, char **argv)
+{
+ cksum_algorithm = sha1;
+ return single_binary_main_cksum (argc, argv);
+}
--- /dev/null
+/* sha224sum -- wrapper to cksum with the right algorithm.
+ Copyright (C) 2025 Free Software Foundation, Inc.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <https://www.gnu.org/licenses/>. */
+
+#include <config.h>
+#include "system.h"
+#include "cksum.h"
+
+/* Ensure that the main for cksum is declared even if the tool is not built
+ in this single-binary. */
+int single_binary_main_cksum (int argc, char **argv);
+int single_binary_main_sha224sum (int argc, char **argv);
+
+int
+single_binary_main_sha224sum (int argc, char **argv)
+{
+ cksum_algorithm = sha224;
+ return single_binary_main_cksum (argc, argv);
+}
--- /dev/null
+/* sha256sum -- wrapper to cksum with the right algorithm.
+ Copyright (C) 2025 Free Software Foundation, Inc.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <https://www.gnu.org/licenses/>. */
+
+#include <config.h>
+#include "system.h"
+#include "cksum.h"
+
+/* Ensure that the main for cksum is declared even if the tool is not built
+ in this single-binary. */
+int single_binary_main_cksum (int argc, char **argv);
+int single_binary_main_sha256sum (int argc, char **argv);
+
+int
+single_binary_main_sha256sum (int argc, char **argv)
+{
+ cksum_algorithm = sha256;
+ return single_binary_main_cksum (argc, argv);
+}
--- /dev/null
+/* sha384sum -- wrapper to cksum with the right algorithm.
+ Copyright (C) 2025 Free Software Foundation, Inc.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <https://www.gnu.org/licenses/>. */
+
+#include <config.h>
+#include "system.h"
+#include "cksum.h"
+
+/* Ensure that the main for cksum is declared even if the tool is not built
+ in this single-binary. */
+int single_binary_main_cksum (int argc, char **argv);
+int single_binary_main_sha384sum (int argc, char **argv);
+
+int
+single_binary_main_sha384sum (int argc, char **argv)
+{
+ cksum_algorithm = sha384;
+ return single_binary_main_cksum (argc, argv);
+}
--- /dev/null
+/* sha512sum -- wrapper to cksum with the right algorithm.
+ Copyright (C) 2025 Free Software Foundation, Inc.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <https://www.gnu.org/licenses/>. */
+
+#include <config.h>
+#include "system.h"
+#include "cksum.h"
+
+/* Ensure that the main for cksum is declared even if the tool is not built
+ in this single-binary. */
+int single_binary_main_cksum (int argc, char **argv);
+int single_binary_main_sha512sum (int argc, char **argv);
+
+int
+single_binary_main_sha512sum (int argc, char **argv)
+{
+ cksum_algorithm = sha512;
+ return single_binary_main_cksum (argc, argv);
+}
src/getlimits
noinst_HEADERS = \
+ src/cksum.h \
src/chown.h \
src/chown-core.h \
src/copy.h \