31063 Commits

Author SHA1 Message Date
Pádraig Brady
8d791ada1e build: update gnulib submodule to latest 2026-01-17 12:45:08 +00:00
Collin Funk
289278eee2 maint: pacify another gcc -Wzero-as-null-pointer-constant warning
* src/uptime.c (print_uptime): Add a timezone_t cast to zero. Don't use
nullptr since timezone_t is not a standardized and may be defined to
something other than a pointer.
2026-01-16 22:56:15 -08:00
Paul Eggert
23e696b0b2 maint: spelling fixes 2026-01-16 13:22:28 -08:00
Paul Eggert
676c3bb397 build: update gnulib submodule to latest 2026-01-16 13:06:45 -08:00
Paul Eggert
1202fac2dc maint: pacify gcc -Wzero-as-null-pointer-constant
* src/basenc.c (long_options):
* src/chcon.c (change_file_context):
* src/copy.c (is_ancestor):
* src/env.c (build_argv):
* src/expr.c (nomoreargs):
* src/factor.c (mp_no_factors):
* src/ls.c (long_options, main):
* src/selinux.c (defaultcon, restorecon_private):
* src/shred.c (dopass):
* src/shuf.c (long_opts):
* src/tac.c (output):
* src/test.c (term):
* src/uniq.c (check_file): Do not use ‘0’ as a null pointer
constant.  Although it is typically valid C, there are exceptions
(e.g., stdarg) and it a bit cleaner to be consistent.  This patch
uses NULL, not nullptr, as I have second thoughts about nullptr;
see <https://bugs.gnu.org/66221#53>.
2026-01-15 22:36:16 -08:00
Collin Funk
2d45a671a0 build: fix link errors with multi-call binary and 'cksum' excluded
* src/local.mk (src_ls_LDADD, src_seq_LDADD, src_md5sum_LDADD)
(src_sha1sum_LDADD, src_sha224sum_LDADD, src_sha256sum_LDADD)
(src_sha384sum_LDADD, src_sha512sum_LDADD): Set to
$(src_cksum_LDADD).
Reported at https://github.com/coreutils/coreutils/issues/172
2026-01-15 18:21:01 -08:00
Pádraig Brady
6b32a0bbde all: with multi-call binary, only process options for known names
Setup
  $ ln -nsf src/coreutils foo

Before
  $ ./foo; echo $?
  foo: unknown program ‘foo’
  Try './foo --help' for more information.
  1
  ./foo --version; echo $?
  coreutils (GNU coreutils) 9.9.172-01993
  0

After
  $ ./foo; echo $?
  coreutils: unknown program 'foo'
  1
  $ ./foo --version; echo $?
  coreutils: unknown program 'foo'
  1

* src/coreutils.c (main): Don't process options if
we don't know they're intended for the multi-call binary.
Otherwise `foo --version` would return true, even though
foo was symlinked to the multi-call binary, but not supported.
* tests/misc/coreutils.sh: Add test cases.
* NEWS: Mention the change in behavior.
2026-01-15 15:54:29 +00:00
Pádraig Brady
36d6cb2774 doc: paste: give a CSV generation example
* doc/coreutils.texi (paste invocation): Provide an example
to comma separate data.
2026-01-15 15:54:18 +00:00
Pádraig Brady
a0119d5982 build: paste: fix build failure with C99
GCC 10.2 gave the following error:
"error: a label can only be part of a statement
 and a declaration is not a statement"

* src/fold.c (fold_file): Add a ";" to avoid C2X specific syntax.
2026-01-14 11:38:59 +00:00
Collin Funk
418d4084b4 maint: avoid syntax-check failure from previous commit
* src/copy-file-data.c (sparse_copy): Use nullptr instead of NULL.
2026-01-13 20:45:32 -08:00
Paul Eggert
cf36efedc0 cat: don’t treat copy_file_range EFBIG as fatal
* src/cat.c (copy_cat):
* src/copy-file-data.c (sparse_copy):
Don’t treat EFBIG as a reportable error from copy_file_range.
If the input is at EOF and the output position is 2**63 - 1,
copy_file_range (ifd, NULL, ofd, NULL, 2146435072, 0)
incorrectly fails with EFBIG.  Problem observed on Ubuntu 25.10
x86-64 with Linux kernel 6.17.0-8-generic #8-Ubuntu.
I am too lazy to report this kernel bug or add a coreutils test case.
2026-01-13 10:12:39 -08:00
Paul Eggert
0dd30755ab build: update gnulib submodule to latest 2026-01-13 10:12:39 -08:00
Paul Eggert
15be3c6307 cp: copy-file-data.c commentary fixes
* src/copy-file-data.c: Update commentary to match code better.
2026-01-13 10:12:39 -08:00
Pádraig Brady
92d80b67cf tests: ensure utilities correctly diagnose read errors
* tests/misc/read-errors.sh: Ensure each utility calls a
read system call as requested.  Not doing so (say by avoiding
reading from a directory) is a layering violation.
Also ensure we diagnose the particular error encountered.
2026-01-13 15:08:04 +00:00
Pádraig Brady
495e3528d7 fmt: correctly diagnose read errors
* src/fmt.c (fmt): Pass errno to error() so that
the particular error is diagnosed.
* NEWS: Mention the improvement.
2026-01-13 15:08:03 +00:00
Pádraig Brady
06d228043f paste: support multi-byte delimiters
* src/paste.c (collapse_escapes): This is the central --delimiters
parsing function, so adjust to handle multi-byte chars with
mcel_scanz().  Populate a delimiters length array to support
characters of differing lengths.
(paste_serial): Use the delimiters length array to output
the appropriate delimiter.
(paste_parallel): Likewise.
* tests/paste/multi-byte.sh: A new test.
* tests/local.mk: Reference the new test.
* NEWS: Mention the improvement.
2026-01-13 14:32:01 +00:00
oech3
e326d0df65 tests: nice: ensure large values are clamped
* tests/nice/nice.sh: Ensure integers > UINTMAX_MAX are supported.
From https://github.com/coreutils/coreutils/pull/170
2026-01-13 14:20:13 +00:00
Collin Funk
87898a6a94 maint: ptx: place long options without short options after CHAR_MAX
* src/ptx.c (FORMAT_OPTION): New constant.
(long_options): Use FORMAT_OPTION instead of 10.
(main): Likewise.
2026-01-12 17:42:16 -08:00
Dmitry V. Levin
2739fab817 tests: cksum: use more general strace syscall injection
* tests/cksum/cksum-c.sh: Match "read" with a regex
to match any of the read syscall variants.
2026-01-12 15:13:57 +00:00
Pádraig Brady
49788a4510 tests: paste -d: test supported escape sequences
* tests/misc/paste.pl: Test all supported POSIX and GNU
backslash escape sequences.
2026-01-12 14:13:26 +00:00
Pádraig Brady
9a8b09f025 doc: paste: add more detail on operation and options
* src/paste.c (usage): Mention how lines are processed
with and without the -s option.  Also mention that -d
supports backslash escapes.
* doc/coreutils.texi (paste invocation): Likewise.
Also detail the backslash escapes, noting which are non-POSIX.
2026-01-12 14:13:20 +00:00
Collin Funk
3e9f4ad5b9 maint: ptx: reuse octhexdigits macros instead of redefining them
* src/ptx.c: Include octhexdigits.h.
(HEXTOBIN, ISODIGIT, OCTTOBIN): Remove macros.
(unescape_string): Use the macros from octhexdigits.h instead of the
removed macros.
2026-01-11 20:22:52 -08:00
Pádraig Brady
210c000b8c tests: date: test nested parenthesis comment handling
* tests/date/date.pl: Add test cases.
Suggested by Sylvestre Ledru.
2026-01-11 18:51:19 +00:00
Pádraig Brady
5c238fcadd doc: runcon: use more accurate synopsis format
* src/runcon.c (usage): Align synopsis with format
used in other commands.
* doc/coreutils.texi (runcon invocation): Likewise.
2026-01-11 18:43:32 +00:00
oech3
3a9777bdb0 tests: cksum: ensure --check handles I/O errors
* tests/cksum/cksum-c.sh: Use strace to inject EIO upon read(),
and verify it's handled appropriately.
From https://github.com/coreutils/coreutils/pull/167
2026-01-11 18:16:18 +00:00
Pádraig Brady
135dff3ad3 tests: cksum: ensure --check diagnoses read errors
* tests/misc/read-errors.sh: Add a test case.
Discussed in https://github.com/coreutils/coreutils/pull/167
2026-01-11 13:42:19 +00:00
Pádraig Brady
01993d76bc build: support 'dist' and 'syntax-check' targets without libselinux
Following on from commit v9.8-60-g8ba47d09a ...
Without libselinux installed, runcon and chcon stub binaries
will not be built by default.  We separate these utilities out
to a separate "not built unless appropriate" class, so that
we can add these to EXTRA_MANS so that the 'check-x-vs-1'
target doesn't fail, and the 'dist' target includes
these man pages.

* build-aux/gen-lists-of-programs.sh: Separate out
build_if_appropriate_progs, and propagate that through
to no_install_progs_default which populates EXTRA_MANS.
* src/local.mk: Separate out build_if_appropriate__progs
for clarity and consistency.
2026-01-11 12:56:22 +00:00
Pádraig Brady
204dc3bce4 build: update gnulib submodule to latest
* gnulib: Update to latest mainly to pull in selinux module fixes.
* NEWS: Mention the build fix to honor --with-selinux building
stub chcon and runcon binaries on systems without libselinux.
2026-01-11 12:54:17 +00:00
Collin Funk
3621ad2f71 cksum: promptly diagnose write errors
* src/cksum.c (output_file, digest_check): Check if standard output has
it's error flag set after printing.
* tests/misc/write-errors.sh: Add a test case that would previously run
forever.
* NEWS: Mention the improvement. Reorder alphabetically.
2026-01-10 12:42:13 -08:00
Pádraig Brady
a9aad49f26 maint: remove redundant processing in a test
* tests/misc/write-errors.sh: This was a no-op anyway
due to inadequate escaping.  Also document the escaping requirement.
2026-01-10 01:04:33 +00:00
Pádraig Brady
19d2d707f7 du: promptly diagnose write errors
* src/du.c (print_size): Call write_error() if can't flush.
* tests/misc/write-errors.sh: Add a test case.
* NEWS: Mention the improvement.
2026-01-10 01:04:33 +00:00
Pádraig Brady
83f274feaa wc: promptly diagnose write errors
* src/wc.c (write_counts): Call write_error() if any pending errors.
* tests/misc/write-errors.sh: Add a test case.
* NEWS: Mention the improvement.
2026-01-10 01:04:33 +00:00
Collin Funk
b34e329f75 readlink,realpath: promptly diagnose write errors
The 'readlink' and 'realpath' programs have an uncommon case where they
can run for a very long time. When canonicalizing file names longer than
PATH_MAX, we have to call 'openat' for each directory up the tree until
we reach root which takes a long time. Here is an example of the current
behavior:

    $ mkdir -p $(yes a/ | head -n $((32 * 1024)) | tr -d '\n')
    $ while cd $(yes a/ | head -n 1024 | tr -d '\n'); do :; \
        done 2>/dev/null
    $ pwd | tr '/' '\n' | wc -l
    32771
    $ env time --format=%E readlink -f $(yes . | head -n 5) > /dev/full
    readlink: write error: No space left on device
    Command exited with non-zero status 1
    0:59.72
    $ env time --format=%E realpath $(yes . | head -n 5) > /dev/full
    realpath: write error: No space left on device
    Command exited with non-zero status 1
    1:00.32

It is better to exit as soon as there is an error writing to standard
output:

    $ env time --format=%E readlink -f $(yes . | head -n 5) > /dev/full
    readlink: write error: No space left on device
    Command exited with non-zero status 1
    0:11.88
    $ env time --format=%E realpath $(yes . | head -n 5) > /dev/full
    realpath: write error: No space left on device
    Command exited with non-zero status 1
    0:12.04

* src/readlink.c (main): Check if standard output has it's error flag
set after printing a file name.
* src/realpath.c (process_path): Likewise.
* NEWS: Mention the improvement.
2026-01-08 23:16:06 -08:00
Pádraig Brady
9200747f65 cksum: validate options more consistently
We disallow `cksum --tag --check` which is fine,
but the error should be consistent with md5sum,
and less confusing, as it currently mentions
"--binary" and "--text" which weren't specified.

We disallow `cksum --tag --text` which is fine,
but we should also disallow `cksum --text --tag`.

We should honor an explicit --binary (output *)
with this combination of options:
cksum --binary --tag --untagged -a md5 /dev/null

Note this also makes both of `cksum -a md5` and
`cksum --tag -a md5` consistently use binary mode
when reading from a tty on systems like MinGW
where O_BINARY is set.

* src/cksum.c (main): Adjust --text,--binary
and --tag,--untagged option processing.
* tests/cksum/cksum-a.sh: Add test cases.
* tests/cksum/cksum-c.sh: Likewise.
* NEWS: Mention the improvement.
Fixes https://github.com/coreutils/coreutils/issues/163
2026-01-08 16:14:57 +00:00
Pádraig Brady
9a38863885 tests: chmod: fix false failure in recent test
* tests/chmod/partial-fail.sh: Test readablility of mode 0 files
independently, to avoid false failure, e.g., when run as root.
Reported by Bruno Haible.
2026-01-08 12:08:14 +00:00
Pádraig Brady
e1cbe82cc6 tests: tail/overlay-headers.sh: fix various issues
* tests/tail/overlay-headers.sh (cleanup_): Ensure we send SIGCONT
to the tail process, otherwise we would hang if the test is terminated
while the tail process is in stopped state.
(wait4stopped_): A new function to ensure tail is in the stopped state
before we start writing to the monitored files.
Also remove "---disable-inotify" from $fastpoll so we actually
test the inotify code (where supported).
Also remove the timeout(1) wrapper, so we actually suspend tail(1).

Reported by Bruno Haible on macOS 26
2026-01-08 12:08:14 +00:00
Pádraig Brady
30d296dcb8 fmt: interpret -w as an inclusive maximum
This aligns with `fold -w` and BSD `fmt` implementations.

* src/fmt.c (fmt_paragraph): Check len <= max_width.
* tests/fmt/width.sh: Add a new test.
* tests/local.mk: Reference the new test.
* NEWS: Mention the change in behavior.
Addresses part of https://bugs.gnu.org/79497
2026-01-08 12:08:14 +00:00
Sylvestre Ledru
b7613ac8ff tests: date: test parenthesis comment handling
* tests/date/date.pl: Add the check.
2026-01-07 19:58:55 -08:00
Collin Funk
0fcdd37fbd maint: organize mktemp tests in a subdirectory
* tests/misc/mktemp.pl: Moved to tests/mktemp/mktemp.pl.
* tests/local.mk (all_tests): Adjust the file name.
2026-01-06 18:52:48 -08:00
Collin Funk
1f1bce27d7 tests: mktemp: add tests for invalid Unicode options
* init.cfg (bad_unicode): New function, copied from
tests/fold/fold-characters.sh with the NUL removed.
* tests/fold/fold-characters.sh (bad_unicode): Rename to
bad_unicode_with_nul. Reformat long line.
* tests/mktemp/bad-unicode.sh: New test.
* tests/local.mk (all_tests): Add the new test.
2026-01-06 18:52:48 -08:00
Pádraig Brady
33bc44e1ba copy: protect against infinite loop due to pathological race
Consider:

1. In infer_scantype():
    - SEEK_DATA returns 0
      - hole punched at 0
    - SEEK_HOLE returns 0 (now a hole)
    - Cache scan_inference->hole_start = 0
2. In lseek_copy():
      - data written at 0
    - ext_start = 0, use cached hole_start = 0
    - ext_len = 0
    - now loop doesn't progress

* src/copy-file-data.c (lseek_copy): Apply a more defensive check
to ensure we only use the cached offsets in SCAN_INFERENCE once.
This protects against an infinite loop where an extent (at SRC_POS)
flip flops between data and hole extent while infer_scantype()
and lseek_copy() are inspecting it.  I.e. ensure we use SEEK_HOLE
to progress the copy.
2026-01-06 20:41:15 +00:00
Pádraig Brady
c43f517e2a tests: cp: fix always skipped nfs-removal-race.sh
* tests/cp/nfs-removal-race.sh: This test was invalid since v8.32
as we now use fstatat() rather than stat().  Also since commit
v9.0-66-ge2daa8f79 we leverage the errno from open(O_DIRECTORY)
to avoid a stat, so pass --no-target-directory to ensure fstatat()
is called.
Discussed in https://github.com/coreutils/coreutils/pull/161
2026-01-06 20:35:44 +00:00
Christopher Illarionova
1afe4109f2 tests: cp: support glibc 2.33+ in nfs-removal-race test
glibc 2.33 removed __xstat, making stat() a direct symbol. This test
previously only intercepted __xstat, causing it to skip on modern glibc
with 'LD_PRELOAD was ineffective'.

Changes:
- Intercept both __xstat (glibc < 2.33) and stat (glibc >= 2.33)
- Only mark 'preloaded' when stat is called on destination 'd',
  ensuring the test verifies cp actually stats the destination
2026-01-06 18:55:47 +00:00
Pádraig Brady
a3ae4123f9 doc: tr: warn about shell quoting [:classes:]
* src/tr.c (usage): Warn about avoiding shell globbing.
* doc/coreutils.texi (character arrays): Likewise.
Suggested by Daniel Dallos.
2026-01-06 18:41:00 +00:00
Pádraig Brady
7531d3a205 ptx: implement -t to change default width to 100
Align the -t implementation with the Heirloom project.

* src/ptx.c (usage): Describe -t, and also mention
the default width is 72 when not used.
* doc/coreutils.texi (ptx invocation): Likewise.
(main): Override the default width if -t is specified.
* tests/ptx/ptx.pl: Add test cases.
* NEWS: Mention the change in behavior.
2026-01-05 23:37:49 +00:00
Christopher Illarionova
e1994cd9ac tests: stty: add require_controlling_input_terminal_ to bad-speed test
The bad-speed test runs 'stty ispeed 9600' without a --file argument,
which requires a controlling terminal. Without it, stty fails early with
'Inappropriate ioctl for device' before reaching cfsetispeed, causing
the test to skip with a misleading 'LD_PRELOAD interception failed'
message.

* tests/stty/bad-speed.sh: Add require_controlling_input_terminal_
to match the other stty tests (stty.sh, stty-pairs.sh, stty-row-col.sh,
stty-invalid.sh) which all require a controlling terminal.
From https://github.com/coreutils/coreutils/pull/160
2026-01-05 17:20:54 +00:00
Collin Funk
2e0c328a3b maint: mknod: reduce variable scope
* src/mknod.c (main): Declare variables where they are used instead of
at the start of a block. Prefer signed integers to unsigned integers.
2026-01-04 13:47:01 -08:00
Collin Funk
e4e40b7df6 maint: mkfifo: reduce variable scope
* src/mkfifo.c (main): Declare variables where they are used instead of
at the start of a block.
2026-01-04 13:46:41 -08:00
Pádraig Brady
bd528f9234 copy: fix possible infinite loop with SEEK_HOLE
Commit v9.8-95-g4c0cf3864 intended to initialize
ext_start to src_pos, as was described at:
https://lists.gnu.org/r/coreutils/2025-11/msg00035.html
However ipos was inadvertently used, which is only
valid the first time through the loop.

* src/copy-file-data.c (lseek_copy): Use scan_inference->hole_start
only with the initial offset passed to lseek_copy().
* NEWS: Mention the bug fix.
Reported at https://github.com/coreutils/coreutils/issues/159
2026-01-04 20:20:04 +00:00
Pádraig Brady
71e0be29f1 tests: chmod: ensure failure upon partial success
* tests/chmod/partial-fail.sh: Add new test.
* tests/local.mk: Reference new test.
Discussed at https://github.com/uutils/coreutils/issues/9790
2026-01-03 14:45:07 +00:00