summaryrefslogtreecommitdiffstats
path: root/src
AgeCommit message (Collapse)AuthorLines
2021-09-24cksum: fix -a crc on 64 bit big endian systemsPádraig Brady-1/+2
* src/cksum.c (crc_sum_stream): On sparc64 for example, a crc of 0 was printed due to mismatch in size of variable copied between generator and output functions. uint_fast32_t is generally 64 bits on 64 bit systems, so we copy through an int to ensure we don't use the wrong end of a 64 bit variable. Reported by Nelson H. F. Beebe
2021-09-21tail: fix detection of closed stdout on macOSPádraig Brady-1/+24
* bootstrap.conf: We only need poll on Linux and AIX where poll is not replaced. Also resinstate dependence on select so we can use it unconditionally. * src/tail.c (check_output_alive): Reinstate use of select() by default as poll was seen to be ineffective for this application on macOS. Fixes https://bugs.gnu.org/50714
2021-09-21maint: clean up c++ style commentsPádraig Brady-11/+2
* src/expand-common.h: Remove commented variables. * src/remove.h: Change to C style comment. * src/tail.c: Likewise.
2021-09-20doc: drop extraneous single quotes in helpJim Meyering-15/+15
* src/digest.c (usage) [cksum --help]: Drop single quotes around each checksum name. * src/tee.c (usage) [tee --help]: Likewise.
2021-09-20cksum: list Pádraig as coauthorJim Meyering-1/+3
* src/digest.c (AUTHORS) [HASH_ALGO_CKSUM]: Add Pádraig as cksum coauthor. * AUTHORS: Likewise.
2021-09-20doc: fix --help formatting for checksum utilsPádraig Brady-19/+22
* src/digest.c (usage): Indicate that --length and --algorithm require arguments. Emit corresponding emit_mandatory_arg_note(). Use consistent alignment.
2021-09-20cksum: support more transparent emulation of older utilsPádraig Brady-11/+6
* src/digest.c: Allow using the --untagged option with --check, so that `cksum -a md5 --untagged` used to emulate md5sum for example, may be augmented with the --check option. Also support the --tag option with cksum, to allow overriding a previous --untagged setting. * doc/coreutils.texi: Adjust accordingly. * tests/misc/cksum-a.sh: Likewise.
2021-09-16rmdir: fix uninitialized memory causing incorrect errorPádraig Brady-1/+2
* src/rmdir.c (main): Only inspect the returned stat structure, when stat(2) returns success.
2021-09-16build: avoid new chmod.c warnings from upcoming GCC12Jim Meyering-1/+1
Here are the warnings: src/chmod.c:175:3: error: 'ch.new_mode' may be used uninitialized in\ this function [-Werror=maybe-uninitialized] 175 | strmode (ch->new_mode, perms); src/chmod.c:178:3: error: 'ch.old_mode' may be used uninitialized in\ this function [-Werror=maybe-uninitialized] 178 | strmode (ch->old_mode, old_perms); * src/chmod.c (process_file): Initialize ch. Its new_mode and old_mode fields could indeed be used uninitialized to form mode strings, but those are used only when built from initialized members.
2021-09-16digest: ignore empty lines when checkingPádraig Brady-0/+5
* src/digest.c (digest_check): Treat empty lines like comments, as commented checksum files very often have empty lines. * tests/misc/md5sum.pl: Adjust accordingly.
2021-09-16factor: sync longlong.h adjustments from upstreamPádraig Brady-31/+28
* src/longlong.h: Sync changes from: https://gmplib.org/repo/gmp/log/tip/longlong.h
2021-09-16stat,tail: add support for the secretmem file systemPádraig Brady-0/+2
* src/stat.c (human_fstype): Add case for the 'secretmem' file system type. * NEWS: Mention the Improvement.
2021-09-16cksum: fix --check with non tagged format checksumsPádraig Brady-1/+1
* src/digest.c: Always set the digest_length, so that we check the correct number of hex digits when parsing non tagged format checksums. * tests/misc/cksum-a.sh: Add a test case. Also fix up this test which was ineffective due to fail=1 being set in a subshell and ignored.
2021-09-16cksum: fix off-by-1 bug with \r strippingPaul Eggert-4/+3
Problem reported by Jim Meyering (Bug#50611). * src/digest.c (digest_check): When stripping trailing \r, avoid subscript error before start of line.
2021-09-15maint: prefer rawmemchr to memchr when easyPaul Eggert-24/+26
* bootstrap.conf (gnulib_modules): Add rawmemchr. * src/csplit.c: Include idx.h. * src/csplit.c (record_line_starts): * src/head.c (elide_tail_lines_pipe): * src/shuf.c (next_line): * src/split.c (lines_split): * src/tail.c (pipe_lines): * src/wc.c (wc_lines): Prefer rawmemchr to memchr when rawmemchr is easy. * src/csplit.c (load_buffer): * src/head.c (struct linebuffer): Make room for a 1-byte sentinel.
2021-09-15split: avoid NULL + 1Paul Eggert-2/+5
* src/split.c (lines_chunk_split): Don’t add to a null pointer. It’s undefined behavior, and it’s unnecessarily confusing regardless.
2021-09-15digest: support windows format checksum filesPádraig Brady-20/+25
Support checksum files with CRLF line endings, which is a common gotcha for using --check on windows, or with checksum files generated on windows. Note we escape \r here to support the original coreutils format (with file name at EOL), and file names with literal \r characters as the last character of their name. * src/digest.c (filename_unescape): Convert \\r -> \r. (print_filename): Escape \r -> \\r. (output_file): Detect \r chars in file names. (digest_check): Ignore literal \r char at EOL. * tests/misc/md5sum.pl: Add a test case. * tests/misc/sha1sum.pl: Likewise. * NEWS: Mention the improvement.
2021-09-15doc: improve --help indenting in checksum utilsPádraig Brady-2/+2
* src/digest.c (usage): Indent multi-line descriptions for clarity.
2021-09-15cksum: operate in binary mode onlyPádraig Brady-14/+28
This only practically matters on windows. But given there are separate text handling options in cygwin, keep the interface simple, and avoid exposing the confusing binary/text difference here. * doc/coreutils.texi (md5sum invocation): Mention that --binary and --text are not supported by the cksum command. * src/digest.c: Set flag to use binary mode by default. (output_file): Don't distinguish text and binary modes with ' ' and '*', and just use ' ' always.
2021-09-15cksum: use --tag format by defaultPádraig Brady-4/+30
This format is a better default, since it results in simpler usage, as you don't need to specify --tag on generation or -a on checking invocations. Also it's a more general format supporting mixed and length adjusted digests. * doc/coreutils.texi (cksum invocation): Document a new --untagged option, to use the older coreutils format. (md5sum invocation): Mention that cksum doesn't support --tag. * src/digest.c: Adjust cksum(1) to default to --tag, and accept the new --untagged option. * tests/misc/b2sum.sh: Adjust accordingly. * tests/misc/cksum-a.sh: Likewise. * tests/misc/cksum-c.sh: Likewise.
2021-09-15cksum: support --zero in default modePádraig Brady-19/+24
* src/cksum.h: Thread DELIM through the output functions. * src/digest.c: Likewise. * src/sum.c: Likewise. * src/sum.h: Likewise. * src/cksum.c: Likewise. Also adjust check to allow -z with traditional output modes. Also ajust the global variable name to avoid shadowing warnings. * tests/misc/cksum-a.sh: Adjust accordingly.
2021-09-15digest: support -length specifiers on all digest tagsPádraig Brady-41/+31
This will be generally useful going forward, for sha3-256 etc. * src/digest.c: Rename b2_length to digest_length, and adjust/simplify the code to operate on this for both b2sum and cksum -a blake2b.
2021-09-15cksum: support digest detection for tagged formatPádraig Brady-3/+66
Support `cksum --check FILE` without having to specify a digest algorithm, allowing for more generic file check instructions. This also supports mixed digest checksum files, supporting more robust multi digest checks. * src/digest.c (algorithm_from_tag): A new function to identify the digest algorithm from a tagged format line. (split3): Set the algorithm depending on tag, and update the expected digest length accordingly. * tests/misc/cksum-c.sh: Add a new test. * tests/local.mk: Reference the new test. * tests/misc/md5sum.pl: Adjust to more generic error. * tests/misc/sha1sum.pl: Likewise. * doc/coreutils.texi (md5sum invocation): Mention the new -c feature. * NEWS: Mention the new feature.
2021-09-15maint: simplify b2sum to only handle BLAKE2bPádraig Brady-41/+14
Any further variants will use the cksum -a table driven mechanism. * src/digest.c: Remove BLAKE2 specific table driven code.
2021-09-15digest: add support for sm3Pádraig Brady-4/+16
Add message digest sm3, which uses the OSCCA SM3 secure hash (OSCCA GM/T 0004-2012 SM3) generic hash transformation. * bootstrap.conf: Add the sm3 module. * doc/coreutils.texi: Mention the cksum -a option. * src/digest.c: Provide support for --algorithm='sm3'. * tests/misc/sm3sum.pl: Add a new test (from Tianjia Zhang) * tests/local.mk: Reference the new test. * NEWS: Mention the new feature. Tested-by: Tianjia Zhang <tianjia.zhang@linux.alibaba.com>
2021-09-15cksum: add --algorithm option to select digest modePádraig Brady-60/+269
* src/digest.c: Organize HASH_ALGO_CKSUM to be table driven, and amalgamate all digest algorithms. (main): Parse all options if HASH_ALGO_CKSUM, and disallow --tag, --zero, and --check with the traditional bsd, sysv, and crc checksums for now. * src/local.mk: Reorganize to include all digest modules in cksum. * tests/misc/cksum-a.sh: Add a new test. * tests/misc/b2sum.sh: Update to default to checking with cksum, as b2sum's implementation diverges a bit from the others. * tests/local.mk: Reference the new test. * doc/coreutils.texi (cksum invocation): Adjust the summary to identify the new mode, and document the new --algorithm option. * man/cksum.x: Adjust description to be more general. * man/*sum.x: Add [See Also] section referencing cksum(1). * NEWS: Mention the new feature.
2021-09-15digest: refactor cksum(1) into digest.cPádraig Brady-627/+556
* cfg.mk: Adjust cksum.c to not require config.h and support a main (for crctab) without calling bindtextdomain(). * po/POTFILES.in: Remove cksum_pclmul.c since it no longer concerns itself with diagnostics. * src/cksum.c: Refactor to just providing stream digest, and digest printing functionality. * src/cksum.h: Adjust to the new interface. * src/cksum_pclmul.c: Remove diagnostics, and determine errors internally. * src/crctab.c: Separate from cksum.h since that's now included multiple times. * src/digest.c: Provide cksum(1) functionality if -DHASH_ALGO_CKSUM * src/local.mk: Adjust to new crctab.c and HASH_ALGO_CKSUM define.
2021-09-15cksum: document the --debug optionPádraig Brady-0/+6
This should have been part of commit v8.32-113-gb73b9fcb1 * doc/coreutils.texi (cksum invocation): Add the --debug description. * src/cksum.c (usage): Likewise. (main): Also give explicit indication when using generic hardware.
2021-09-15sum: handle EOVERFLOW for too large inputsPádraig Brady-0/+20
* src/sum.c (bsd_sum_stream): Detect overflow when updating length. (sysv_sum_stream): Likewise.
2021-09-15digest: refactor sum(1) into digest.cPádraig Brady-253/+272
Since digest will be providing all digest functionality, refactor sum.c into it. * po/POTFILES.in: sum.c no longer has translatable strings so remove. * src/digest.c: Call out to new stream interfaces in sum.c * src/local.mk: Adjust sources for the sum binary. * src/sum.c: Provide a stream interface for BSD and SYSV digests. * src/sum.h: A new file to declare the exported functions in sum.c
2021-09-15digest: add LENGTH parameter to digest to support cksumPádraig Brady-3/+3
* src/digest.c (digest_file): Add a LENGTH param, to support cksum(1), and sum(1) which output the length as part of their output.
2021-09-15maint: rename md5sum.c to more general digest.cPádraig Brady-6/+7
md5sum.c will be the base for all digest functions, so rename accordingly. * src/md5sum.c: Rename to ... * src/digest.c: ... renamed from md5sum.c * scripts/git-hooks/commit-msg: Allow digest: commit prefix. * po.POTFILES.in: Adjust to new name. * src/local.mk: Likewise.
2021-09-15doc: fix ambiguities in logname(1) and whoami(1)Pádraig Brady-1/+1
* doc/coreutils.texi (whoami invocation): Clarify it prints names, not numeric IDs. * man/whoami.x: Likewise. * man/logname.x: Reference getlogin(3). * src/logname.c: Clarify that it prints the login name, rather than the name of the effective user ID. Fixes https://bugs.gnu.org/48894
2021-09-15dircolors: add *direct* to TERM matchingnl6720-0/+1
Search for "direct color" at: https://invisible-island.net/xterm/terminfo.html * src/dircolors.hin: Add *direct* to match terminals that support direct colors (24-bit color / TrueColor). The trailing * will match entries like xterm-direct2. Addresses https://bugs.gnu.org/39827
2021-08-31doc: indicate the default algorithm in the sum(1) man pagePádraig Brady-1/+1
* src/sum.c (usage): Indicate that -r (BSD algorithm) is the default.
2021-08-31sum: always output a file name if one passedPádraig Brady-2/+2
Adjust to output the file name if any name parameter is passed. This is consistent with sum -s, cksum, and sum implementations on other platforms. This should not cause significant compat issues, as multiple fields are already output, and so already need to be parsed. * src/sum.c (bsd_sum_file): Output the file name if any name parameter is passed. * tests/misc/sum.pl: Adjust accordingly. * doc/coreutils.texi (sum invocation): Likewise. * NEWS: Mention the change in behavior.
2021-08-29basenc: fix bug49741: using wrong decoding buffer lengthAssaf Gordon-1/+3
Emil Lundberg <lundberg.emil@gmail.com> reports in https://bugs.gnu.org/49741 about a 'basenc --base64 -d' decoding bug. The input buffer length was not divisible by 3, resulting in decoding errors. * NEWS: Mention fix. * src/basenc.c (DEC_BLOCKSIZE): Change from 1024*5 to 4200 (35*3*5*8) which is divisible by 3,4,5,8 - satisfying both base32 and base64; Use compile-time verify() macro to enforce the above. * tests/misc/basenc.pl: Add test.
2021-08-27basenc: prefer signed to unsigned integersPaul Eggert-101/+87
This patch modifies basenc to prefer signed integers to unsigned, as signed are less error-prone. This patch also updates Gnulib to to latest, which updates Gnulib’s base32 and base64 modules to prefer signed to unsigned integers. * src/basenc.c: Include idx.h. (struct base2_decode_context): Use unsigned char, not unsigned for an octet that must fit in an unsigned char. (base_encode, struct base_decode_context) (base64_decode_ctx_wrapper, prepare_inbuf, base64url_encode) (base64url_decode_ctx_wrapper, base32_decode_ctx_wrapper) (base32hex_encode, base32hex_decode_ctx_wrapper, base16_encode) (base16_decode_ctx, z85_encode, Z85_HI_CTX_TO_32BIT_VAL) (z85_decoding, z85_decode_ctx, base2msbf_encode) (base2lsbf_encode, base2lsbf_decode_ctx, base2msbf_decode_ctx) (wrap_write, do_encode, do_decode, main): Prefer signed integers to unsigned. (main): Treat extremely large wrap columns as if they were infinite; that’s good enough. Since we’re now using xstrtoimax, this allows ‘-w -0’ (same as ‘-w 0’). * tests/misc/base64.pl (gen_tests): -w-0 is no longer an error.
2021-08-22df: pacify -Wsuggest-attribute=mallocPaul Eggert-1/+4
Problem found with latest Gnulib and GCC 11.2.1. * src/find-mount-point.h (find_mount_point): Add _GL_ATTRIBUTE_MALLOC and _GL_ATTRIBUTE_DEALLOC_FREE.
2021-08-22maint: use clearerr on stdin when appropriatePaul Eggert-107/+129
This is so that commands like ‘fmt - -’ read from stdin both times, even when it is a tty. Fix some other minor issues that are related. * src/blake2/b2sum.c (main): * src/cksum.c (cksum): * src/cut.c (cut_file): * src/expand-common.c (next_file): * src/fmt.c (fmt): * src/fold.c (fold_file): * src/md5sum.c (digest_file, digest_check): * src/nl.c (nl_file): * src/od.c (check_and_close): * src/paste.c (paste_parallel, paste_serial): * src/pr.c (close_file): * src/sum.c (bsd_sum_file): Use clearerr on stdin so that stdin can be read multiple times even if it is a tty. Do not assume that ferror preserves errno as POSIX does not guarantee this. Coalesce duplicate diagnostic calls. * src/blake2/b2sum.c (main): * src/fmt.c (main, fmt): Report read error, even if it's merely fclose failure. * src/fmt.c: Include die.h. (fmt): New arg FILE. Close input (reporting error) if not stdin. All callers changed. * src/ptx.c (swallow_file_in_memory): Clear stdin's EOF flag. * src/sort.c (xfclose): Remove unnecessary feof call.
2021-08-15chmod: fix use of uninitialized var if -vPaul Eggert-63/+64
Problem reported by Michael Debertol (Bug#50070). * NEWS: Mention the fix. * src/chmod.c (struct change_status): New struct, replacing the old enum Change_status. All uses changed. (describe_change): Distinguish between cases depending on whether 'stat' or its equivalent succeeded. Report a line of output even if 'stat' failed, as that matches the documentation. Rework to avoid casts. (process_file): Do not output nonsense modes computed from uninitialized storage, removing a couple of IF_LINTs. Simplify by defaulting to CH_NO_STAT.
2021-08-11df: fix bug with automountedPaul Eggert-9/+25
If the command-line argument is automounted, df would use stat info that became wrong after the following open. * NEWS: Mention the fix (bug#50012). * src/df.c (automount_stat_err): New function. This fixes the hang on fifos in a better way, by using O_NONBLOCK. (main): Use it.
2021-08-08cat: with -E fix handling of \r\n spanning buffersPádraig Brady-6/+33
We must delay handling when \r is the last character of the buffer being processed, as the next character may or may not be \n. * src/cat.c (pending_cr): A new global to record whether the last character processed (in -E mode) is '\r'. (cat): Honor pending_cr when processing the start of the buffer. (main): Honor pending_cr if no more files to process. * tests/misc/cat-E.sh: Add test cases. Fixes https://bugs.gnu.org/49925
2021-07-31uniq: pacify GCC -fanalyzerPaul Eggert-2/+2
Pacify GCC 11.1 -fanalyzer. * src/uniq.c (check_file): Use simpler test to check whether this is the first time through the loop. Although the old test was correct, the new one is easier to understand and perhaps a tiny bit more efficient.
2021-07-31numfmt: omit unnecessary pointer testPaul Eggert-1/+1
Caught by GCC 11.1 -fanalyzer. * src/numfmt.c (simple_strtod_int): Remove unnecessary test of *endptr vs NULL. Presumably this was a typo and **endptr was intended instead of *endptr, but an **endptr test is also unnecessary since c_isdigit (0) returns false.
2021-07-28maint: avoid syntax-check failures in recent ls changesPádraig Brady-8/+9
* src/ls.c: Fix ifdef indenting and long line.
2021-07-28doc: modernize usage of “disk” and “core”Paul Eggert-54/+55
In documentation and comments, don’t assume that secondary storage devices are disk devices. Similarly, don’t assume that main memory uses magnetic cores, which became obsolete in the 1970s. * src/du.c (usage): * src/ls.c (usage): * src/shred.c (usage): Reword to avoid “disk” in usage messages.
2021-07-28doc: improve ls documentationPaul Eggert-8/+7
* doc/coreutils.texi (ls invocation): Document implementation more closely. Be more consistent about style. Omit some needless words. * src/ls.c (usage): Don’t overdocument -f, as the details were wrong. Omit -1 advice as it’s a bit obsolete now that we have --zero and is a bit much for --usage output anyway.
2021-07-27ls: rename --null to --zero (Bug#49716)Paul Eggert-28/+29
* NEWS, doc/coreutils.texi (General output formatting): * src/ls.c (usage): Document this. * src/ls.c (ZERO_OPTION): Rename from NULL_OPTION. All uses changed. (long_options): Rename --null to --zero. (dired_dump_obstack, main, print_dir): Use '\n' instead of eolbyte where eolbyte must equal '\n'. (decode_switches): Decode --zero instead of --null. --zero also implies -1, -N, --color=none, --show-control-chars. Use easier-to-decipher code to set ‘format’ and ‘dired’. Reject attempts to combine --dired and --zero. * tests/local.mk: Adjust to test script renaming. * tests/ls/zero-option.sh: Rename from tests/ls/null-option.sh, and test --zero instead of --null.
2021-07-27ls: compute defaults more lazilyPaul Eggert-195/+200
* src/ls.c (enum time_type, enum sort_type, enum indicator_style) (enum Dereference_symlink, ignore_mode): Put ‘= 0’ after default values, since the code relies on static storage defaulting to zero. (enum sort_type): Reorder so that -1 can be used to represent unset. (main): Test print_with_color after parse_ls_color may have reset it. (decode_line_length): Return the line length instead of setting static storage. All uses changed. Treat line lengths exceeding PTRDIFF_MAX as infinite, to avoid pointer-subtraction glitches. (stdout_isatty): New function, to avoid calling isatty twice. (decode_switches): Calculate defaults more lazily, to avoid using syscalls or getenv during startup unless the results are more likely to be needed. Use -1 to indicate options that haven’t been set on the command line yet. Move print_with_color test from here to ‘main’. Suppress bogus GCC warning. (getenv_quoting_style): Return the quoting style instead of setting static storage. (init_column_info): New arg MAX_COLS, to avoid recalculating it. Caller changed.