]> git.ipfire.org Git - thirdparty/coreutils.git/log
thirdparty/coreutils.git
33 hours agomaint: remove now-unused include of 'safe-read.h' master
Bernhard Voelker [Mon, 4 Aug 2025 06:36:53 +0000 (08:36 +0200)] 
maint: remove now-unused include of 'safe-read.h'

'make syntax-check' complains:
  src/tail.c
  maint.mk: the above files include safe-read.h but don't use it
  make: *** [maint.mk:737: sc_prohibit_safe_read_without_use] Error 1

The removal was missed for tail.c in recent commit d3c7072a0950.

* src/tail.c (safe-read.h): Remove include.

40 hours agomaint: prefer same-inode.h
Paul Eggert [Sun, 3 Aug 2025 22:04:01 +0000 (15:04 -0700)] 
maint: prefer same-inode.h

This does not change behavior on POSIX platforms; it’s mostly to
make it clearer when we’re looking for file identity.
* src/cat.c (main):
* src/copy.c (struct dir_list, is_ancestor, copy_internal):
* src/tail.c (struct File_spec, record_open_fd, recheck)
(tail_forever_inotify, tail_file):
* src/test.c (binary_operator):
Use psame_inode, PSAME_INODE, or SAME_INODE instead of comparing
device and inode numbers by hand.

40 hours agotail: refactor ‘failable’
Paul Eggert [Sun, 3 Aug 2025 15:29:52 +0000 (08:29 -0700)] 
tail: refactor ‘failable’

* src/tail.c (recheck, tail_file): Do not mark a file as tailable
merely because --retry is not in effect.  Simplify internal logic.
This should not change behavior; it’s just for clarity and to
make the code match the comments better.

40 hours agotail: fix race between read and fstat
Paul Eggert [Sun, 3 Aug 2025 15:19:53 +0000 (08:19 -0700)] 
tail: fix race between read and fstat

* src/tail.c (get_file_status): Remove, since after the changes
described below it would be called in just one place and it’s a
bit clearer to inline by hand.
(tail_file): Don’t call fstat after reading the file, as that
misses changes arriving between read and fstat.  Instead, reuse
the fstat done before reading the file.

40 hours agotail: track errno more accurately
Paul Eggert [Sat, 2 Aug 2025 23:55:09 +0000 (16:55 -0700)] 
tail: track errno more accurately

This matters only in some obscure cases hard to test for.
* src/tail.c (file_lines, pipe_lines, pipe_bytes, start_bytes)
(start_lines, tail_bytes, tail_lines, tail): New return
convention, which reports errno.  All callers changed.
(recheck): Don’t lose track of errno if a regular file is
replaced by a symlink.
(get_file_status): Set errno to 0 on success.
(tail_file): Be more careful about f->errnum.
It is now -1 only if the failure was not due to
a system call failing.

40 hours agotail: omit redundant assignment
Paul Eggert [Sat, 2 Aug 2025 20:49:48 +0000 (13:49 -0700)] 
tail: omit redundant assignment

* src/tail.c (recheck): f->remote must be true already,
so don’t set it to true.

40 hours agotail: prefer readlink to lstat+S_ISLNK
Paul Eggert [Sat, 2 Aug 2025 19:58:06 +0000 (12:58 -0700)] 
tail: prefer readlink to lstat+S_ISLNK

When not already calling lstat for some other reason,
prefer readlink to lstat+S_ISLNK,
as readlink does not suffer from EOVERFLOW issues.
* src/rmdir.c (main):
* src/tail.c (recheck, any_symlinks):
* src/test.c (unary_operator):

40 hours agotail: fix unlikely races with >=2 --pids
Paul Eggert [Fri, 1 Aug 2025 20:46:33 +0000 (13:46 -0700)] 
tail: fix unlikely races with >=2 --pids

Also, fix commentary to talk about “nonexistent” rather than
“dead” processes, since the code looks for the former not the
latter and the difference matters for zombies.
* src/tail.c (some_writers_exist): Rename from writers_are_dead,
negate the sense, don’t have a special and counterintuitive case
for !nbpids, remove PIDs found not to exist, and avoid some
though not all unlikely races when kernels reuse PIDs.
(tail_forever): Optimize via blocking I/O even if --pid was used,
so long as all the writers no longer exist.
(tail_forever, tail_forever_inotify): Simplify the writers_dead
logic; there is no need to have a local var to track this, since
we can use pids and nbpids now.
(parse_options): Also free and clear pids if !forever.

40 hours agotail: prefer < 0 to == -1
Paul Eggert [Fri, 1 Aug 2025 14:58:08 +0000 (07:58 -0700)] 
tail: prefer < 0 to == -1

* src/tail.c (valid_file_spec, recheck, writers_are_dead)
(tail_forever, check_fspec, tail_forever_inotify, tail_file)
(parse_options, main): Be a bit more systematic about checking
for sign, rather than for exact equality or inequality,
when the sign is enough.  Makes the code a bit clearer
now that -2 sometimes means success.

40 hours agotail: record file offset more carefully
Paul Eggert [Fri, 1 Aug 2025 01:45:12 +0000 (18:45 -0700)] 
tail: record file offset more carefully

* src/tail.c (struct File_spec): New member read_pos, replacing
size, since the value was really a read position not a size.
All uses changed.
(xlseek): Move defn up.
(record_open_fd): If the read_pos (formerly) size arg is unknown,
compute it here if it is a regular file.
(file_lines): Return the resulting read pos (or -1 on failure)
instead of storing it via a pointer.  Caller changed.
Simplify by using SEEK_CUR instead of SEEK_SET when that is easy.
Avoid reading the same data twice when there are not enough
lines in the file.
(pipe_lines): Return -2 on success, -1 on failure, rather than
updating a read pos via a pointer (which was weird for pipes anyway).
Caller changed.
(pipe_bytes, tail_bytes, tail_lines, tail):
Return -1 on failure, a file offset if known, and < -1 otherwise,
instead of storing a file offset via a pointer.  Caller changed.
(pipe_bytes): Take initial file offset as an arg, or -1 if unknown.
(start_bytes, start_lines): Return -1 (not 1) on error, -2 (not
-1) on EOF, and do not accept pointer to read pos as an arg since
neither we nor our caller know the read pos.  Callers changed.
(recheck): Do not assume a newly-opened file is at offset zero,
as this is not always true on Solaris.
(tail_forever, check_fspec): Use dump_remainder result only
on regular files, to prevent (very unlikely) overflow.
(tail_file): Remove no-longer-needed TAIL_TEST_SLEEP code.

40 hours agomaint: prefer 'read' to 'safe_read'
Paul Eggert [Thu, 31 Jul 2025 19:31:58 +0000 (12:31 -0700)] 
maint: prefer 'read' to 'safe_read'

In the old days, safe_read acted more like what full_read does now.
When that went away, some code that invoked safe_read should
have gone back to plain 'read' but I guess we never got around to it.
Simplify this code by going back to plain 'read'.
Use safe_read only in csplit.c, which has a signal handler
and where 'read' can therefore fail with EINTR.
Although safe_read also checks for oversize buffers,
that is better done via io_blksize.
* src/cat.c (simple_cat, cat):
* src/head.c (copy_fd, elide_tail_lines_pipe)
* src/tac.c (tac_seekable, copy_to_temp):
(elide_tail_lines_seekable, head_lines):
* src/tail.c (dump_remainder, file_lines, pipe_lines)
(pipe_bytes, start_bytes, start_lines, tail_forever_inotify):
* src/tr.c (plain_read):
Use plain 'read', not safe_read, since there is no
need to worry about signals or oversize requests.
Also, there is no longer a need to include safe-read.h.
* src/ioblksize.h: Include sys-limits.h, for SYS_BUFSIZE_MAX.
(io_blksize): Max out at SYS_BUFSIZE_MAX.

40 hours agotail: prefer signed types to size_t, blksize_t
Paul Eggert [Wed, 30 Jul 2025 22:11:31 +0000 (15:11 -0700)] 
tail: prefer signed types to size_t, blksize_t

* src/tail.c (struct File_spec, xwrite_stdout, file_lines)
(pipe_lines, pipe_bytes, start_bytes, any_live_files)
(tail_forever, any_remote_file, any_non_remote_file)
(any_symlinks, any_non_regular_fifo, tailable_stdin)
(tail_forever_inotify, ignore_fifo_and_pipe, main):
Prefer a signed type to size_t, if possible.
Ordinarily this is idx_t, but use int when the value
must fit in int anyway.
(file_lines): Similarly for blksize_t, which had no business
being here anyway.
(main): Check for overflow in the oddball case where ptrdiff_t is
narrower than int.

40 hours agotail: prefer intmax_t to uintmax_t
Paul Eggert [Wed, 30 Jul 2025 15:46:04 +0000 (08:46 -0700)] 
tail: prefer intmax_t to uintmax_t

Signed types let us debug better, by using -fsanitize=undefined.
* doc/local.mk (doc/constants.texi):
Adjust change from macro to enum.
* src/tail.c (COPY_TO_EOF, COPY_A_BUFFER)
(DEFAULT_MAX_N_UNCHANGED_STATS_BETWEEN_OPENS):
Now enum constants, not macros.
(COPY_TO_EOF, COPY_A_BUFFER): Now negative, not positive.
(count_t): New typedef.  Use it instead of uintmax_t.
(COUNT_MAX): New macro; use it instead of UINTMAX_MAX.
(struct File_spec, max_n_unchanged_stats_between_opens)
(dump_remainder, file_lines, pipe_lines, pipe_bytes)
(start_bytes, start_lines, tail_forever, check_fspec)
(tail_forever_inotify, tail_bytes, tail_lines, tail, tail_file)
(parse_obsolete_option, parse_options, main):
Prefer count_t to uintmax_t.

40 hours agotail: don’t output more lines than requested
Paul Eggert [Wed, 30 Jul 2025 14:49:14 +0000 (07:49 -0700)] 
tail: don’t output more lines than requested

* src/tail.c (file_lines): Fix an unlikely bug where ‘tail -n N’
could output more than N lines if standard input is a largish
regular file with large initial offset that starts with (say) N-1
lines after the initial offset, but grows to N+1 lines between the
fstat and read calls.  In this case ‘tail -n N’ now outputs N-1
lines, not N+1; that is, it pretends the file grew after ‘tail’
read it.  That is better than outputting more than N lines.

40 hours agotail: xlseek switch → table
Paul Eggert [Tue, 29 Jul 2025 20:23:58 +0000 (13:23 -0700)] 
tail: xlseek switch → table

* src/tail.c (xlseek): Turn a switch statement into a table.

40 hours agotail: prettyname cleanup
Paul Eggert [Tue, 29 Jul 2025 20:22:41 +0000 (13:22 -0700)] 
tail: prettyname cleanup

* src/tail.c: Use ‘prettyname’ consistently as the identifier
for a prettified file name, as opposed to ‘pretty_filename’,
‘pretty_name’, and ‘name’.  This makes the code easier to follow.
(struct File_spec): New member prettyname.
(pretty_name): Remove.
All uses of pretty_name (f) replaced by f->prettyname.
(close_fd, fremote): Accept struct File_spec, not name.
All callers changed.
(main): Initialize the new prettyname member.
This is simpler/smaller than calling pretty_name everywhere.

40 hours agotail: optimize tail -n +2**63
Paul Eggert [Tue, 29 Jul 2025 16:37:44 +0000 (09:37 -0700)] 
tail: optimize tail -n +2**63

* src/tail.c (tail_lines): Also optimize ‘tail -n +N’
on a seekable file, where OFF_T_MAX <= N < UINTMAX_MAX.
Of course this is very unlikely.

40 hours agotail: refactor SEEK_END and lines
Paul Eggert [Tue, 29 Jul 2025 16:14:37 +0000 (09:14 -0700)] 
tail: refactor SEEK_END and lines

* src/tail.c (tail_lines): Refactor to simplify the confusing
code for using SEEK_END when counting lines.  The old code
had a ‘end_pos != 0’ expression that was always true.

40 hours agotail: refactor to skip stat call on failure
Paul Eggert [Tue, 29 Jul 2025 15:24:58 +0000 (08:24 -0700)] 
tail: refactor to skip stat call on failure

* src/tail.c (tail_bytes): New function.
(tail_bytes, tail_lines, tail): Accept struct stat pointer from
caller instead of calling fstat ourselves.  All callers changed.
(tail_file): Skip a call to fstat if fstat already failed.
* tests/tail/follow-stdin.sh: Adjust to match new behavior
on failure, which omits a redundant diagnostic.

40 hours agotail: speed up -c N for huge N
Paul Eggert [Tue, 29 Jul 2025 06:39:30 +0000 (23:39 -0700)] 
tail: speed up -c N for huge N

When the user specifies -c N where 2**63 <= N, don’t give
up and use the slow method (which will exhaust memory if
the file is large).  Instead, treat it as N = 2**63 - 1,
since that has equivalent effect.
* src/tail.c (tail_bytes): With -c N and large N, adjust
the code so that lseeks can still be used without
affecting correctness.  Formerly the code gave up and
did a sequential pass through the whole input, which
could easily exhaust memory.

40 hours agotail: allow >=2**64 in traditional form
Paul Eggert [Mon, 28 Jul 2025 18:24:38 +0000 (11:24 -0700)] 
tail: allow >=2**64 in traditional form

This better matches the treatment of POSIX form,
e.g., ‘tail +Nc’ is now like ‘tail -c +N’ even when N is large.
* src/tail.c: Don’t include xstrtol.h.
(parse_obsolete_option): Treat numbers greater than UINTMAX_MAX as
if they are UINTMAX_MAX.  Parse the number by hand with saturating
arithmetic; nowadays that’s simpler than using xstrtoumax.  There
is no need for a diagnostic now, as the error cannot happen any more.
* tests/tail/tail.pl (obs-plus-c3): New test.

40 hours agotail: check OFF_T_MAX vs COPY_A_BUFFER
Paul Eggert [Sun, 27 Jul 2025 19:36:53 +0000 (12:36 -0700)] 
tail: check OFF_T_MAX vs COPY_A_BUFFER

* src/tail.c: Document an otherwise-unstated assumption.

40 hours agotail: fix SEEK_END typo
Paul Eggert [Wed, 23 Jul 2025 15:31:38 +0000 (08:31 -0700)] 
tail: fix SEEK_END typo

* src/tail.c (tail_lines): Fix embarrassing SEEK_END typo.
Luckily this matters only in never-used (though valid) invocations.

40 hours agotail: simplify -c+ on regular files
Paul Eggert [Wed, 23 Jul 2025 05:05:17 +0000 (22:05 -0700)] 
tail: simplify -c+ on regular files

* src/tail.c (tail_bytes): Simplify the -c+N case by treating
regular files like other files; if the lseek fails for whatever
reason, fall back on the unoptimized version instead of reporting
a fatal error.

40 hours agomaint: don’t lseek memory objects
Paul Eggert [Mon, 14 Jul 2025 23:41:05 +0000 (16:41 -0700)] 
maint: don’t lseek memory objects

This affects behavior only on memory objects, which are not in Linux.
Formerly the code would use lseek on these objects,
but POSIX says the result of lseek is unspecified on them,
and in QNX lseek has undefined behavior on typed memory objects.
* src/head.c (elide_tail_bytes_file, elide_tail_lines_file):
Omit unnecessary uses of presume_input_pipe.
Improve some out-of-date comments.
(head): Do not assume a file is seekable merely because its
st_size is usable.  Instead, seek only on regular files.
* src/od.c (skip): Do not seek on memory objects.

40 hours agowc: don’t assume opening a file puts you at start
Paul Eggert [Mon, 14 Jul 2025 20:32:27 +0000 (13:32 -0700)] 
wc: don’t assume opening a file puts you at start

This is not true on Solaris when opening /dev/stdin; it could be
at a nonzero file offset.  Arguably Linux should do likewise.
* src/wc.c (wc): Omit last arg, and act as if it is always -1.
All uses changed.

40 hours agohead: simplify head_bytes
Paul Eggert [Mon, 14 Jul 2025 18:40:33 +0000 (11:40 -0700)] 
head: simplify head_bytes

* src/head.c (diagnose_read_failure): New function.
Use it when possible, to simplify callers.
(head_bytes): Use copy_fd and diagnose_copy_fd_failure instead of
reinventing the wheel.

40 hours agohead: omit unnecessary lseek
Paul Eggert [Mon, 14 Jul 2025 18:07:21 +0000 (11:07 -0700)] 
head: omit unnecessary lseek

* src/head.c (elseek_diagnostic): New function.
(elseek): Use it.
(head_lines): Use it to avoid an unnecessary lseek.

47 hours agoreadlink: improve documentation for POSIXLY_CORRECT in --help
Collin Funk [Sun, 3 Aug 2025 19:33:55 +0000 (12:33 -0700)] 
readlink: improve documentation for POSIXLY_CORRECT in --help

* NEWS: Improve wording to not imply POSIXLY_CORRECT=1 readlink -q will
be verbose.
* src/readlink.c (usage): Mention the affect of POSIXLY_CORRECT on
-s (--silent), -q (--quiet), and -v (--verbose) in the help message.
(main): Remove spurious newline added by previous commit.
* doc/coreutils.texi (readlink invocation): Mention that -s (--silent)
and -q (--quiet) are not the default when POSIXLY_CORRECT is set.

2 days agoreadlink: emit errors when POSIXLY_CORRECT is set
Collin Funk [Sun, 3 Aug 2025 03:51:30 +0000 (20:51 -0700)] 
readlink: emit errors when POSIXLY_CORRECT is set

* src/readlink.c (main): Set verbose if the POSIXLY_CORRECT environment
variable is set.
* tests/readlink/readlink-posix.sh: New file.
* tests/local.mk (all_tests): Add it.
* NEWS: Mention the change.
* doc/coreutils.texi (readlink invocation): Document the behavior of
POSIXLY_CORRECT.

3 days agodoc: mention copy_file_range data corruption avoidance
Pádraig Brady [Sat, 2 Aug 2025 08:52:17 +0000 (09:52 +0100)] 
doc: mention copy_file_range data corruption avoidance

* NEWS: Mention this important data corruption issue.

3 days agobuild: update gnulib submodule to latest
Paul Eggert [Fri, 1 Aug 2025 23:55:31 +0000 (16:55 -0700)] 
build: update gnulib submodule to latest

4 days agomaint: date: refactor to be entirely bottom-up
Bruno Haible [Thu, 31 Jul 2025 16:45:45 +0000 (18:45 +0200)] 
maint: date: refactor to be entirely bottom-up

* src/date.c (show_date_helper): Move function. Remove forward
declaration.

4 days agodate: fix calendar-related test failures on macOS and OpenBSD
Bruno Haible [Thu, 31 Jul 2025 16:42:02 +0000 (18:42 +0200)] 
date: fix calendar-related test failures on macOS and OpenBSD

* bootstrap.conf (gnulib_modules): Add xsetenv.
* src/date.c: Include xsetenv.h.
(set_LC_TIME): New function.
(show_date_helper): Call set_LC_TIME instead of setlocale.
* po/POTFILES.in: Add lib/xsetenv.c.
Fixes https://bugs.gnu.org/79118

4 days agobuild: update gnulib submodule to latest
Collin Funk [Fri, 1 Aug 2025 04:43:55 +0000 (21:43 -0700)] 
build: update gnulib submodule to latest

4 days agobuild: fix previous commit
Collin Funk [Fri, 1 Aug 2025 00:57:59 +0000 (17:57 -0700)] 
build: fix previous commit

* src/local.mk (src/speedlist.h): Pass correct arguments $(COMPILE). Use
tabs consistently.

5 days agobuild: don't use '$<' in non-suffix rules
Collin Funk [Wed, 30 Jul 2025 23:33:24 +0000 (16:33 -0700)] 
build: don't use '$<' in non-suffix rules

* src/local.mk (src/speedlist.h): Use the file name instead of '$<'
which is not supported by OpenBSD make.

7 days agodu: improve diagnostics for --time-style
Pádraig Brady [Mon, 28 Jul 2025 22:05:49 +0000 (23:05 +0100)] 
du: improve diagnostics for --time-style

* src/system.h (x_timestyle_args): A new function refactored from ...
* src/ls.c (decode_switches): ... here.
* src/du.c: Use refactored x_timestyle_args() to output a custom error.
Addresses https://bugs.gnu.org/79113

7 days agodoc: use consistent references to standard files
Pádraig Brady [Mon, 28 Jul 2025 10:05:25 +0000 (11:05 +0100)] 
doc: use consistent references to standard files

* cfg.mk (sc_standard_outputs): A new syntax check to
enforce standard references.
* doc/coreutils.texi: s/stderr/standard error/ etc.
* src/date.c: Likewise.
* src/dd.c: Likewise.
* src/env.c: Likewise.
* src/sort.c: Likewise.
* src/split.c: Likewise.
* src/stty.c: Likewise.
* src/timeout.c: Likewise.
* src/who.c: Likewise.

9 days agodoc: update git version documented in HACKING
Collin Funk [Sun, 27 Jul 2025 18:53:42 +0000 (11:53 -0700)] 
doc: update git version documented in HACKING

* HACKING: Mention that git version 1.6.4 or later is required since
'./bootstrap' will fail otherwise.

9 days agodoc: mention 2025 speedup on large composites
Paul Eggert [Sun, 27 Jul 2025 14:30:29 +0000 (07:30 -0700)] 
doc: mention 2025 speedup on large composites

10 days agomaint: avoid :> pattern in tests
Pádraig Brady [Sat, 26 Jul 2025 19:06:42 +0000 (20:06 +0100)] 
maint: avoid :> pattern in tests

This was seen to trigger the EXIT trap on cygwin

* cfg.mk (sc_prohibit_colon_redirection): Disallow all
cases of :> in tests/
* tests/cksum/md5sum-bsd.sh: Adjust to avoid more
stringent syntax check.

10 days agotests: avoid a false failure on Cygwin
Collin Funk [Sat, 26 Jul 2025 18:29:02 +0000 (11:29 -0700)] 
tests: avoid a false failure on Cygwin

* tests/cksum/md5sum-bsd.sh: Use 'echo' instead of ':' to redirect to
the file. Otherwise 'Exit $fail' is not called on Cygwin.

10 days agomaint: avoid syntax-check failure from previous commit
Collin Funk [Sat, 26 Jul 2025 07:17:16 +0000 (00:17 -0700)] 
maint: avoid syntax-check failure from previous commit

* src/test.c (binary_operator): Place string argument on a separate line
to avoid sc_error_quotes syntax-check failure.

10 days agotest: simplify for clarity
Paul Eggert [Fri, 25 Jul 2025 18:56:00 +0000 (11:56 -0700)] 
test: simplify for clarity

This should help avoid further audit confusion,
such as was just fixed by removing a FIXME.
* src/test.c (enum binop): New type.
(get_mtime): Return a struct timespec instead of returning
a bool and storing a struct timespec.  All callers changed.
(binop): Return an int recording either success (an enum binop)
or failure (-1).  All callers changed.
(binary_operator): Accept an enum binop, so that we need
not recompute the op type.  All callers changed.  Simplify.

10 days agotest: removed dead code for unrecognised binary operators
Harry Fellowes [Fri, 25 Jul 2025 13:26:38 +0000 (14:26 +0100)] 
test: removed dead code for unrecognised binary operators

the fallback error in binary_operator() was unreachable, since invalid
binary operators are rejected in three_arguments() via binop() which
returns false and prevents entry into binary_operator().

this dead code was unreachable and safe to remove

ref: line 636 where "binary operator expected" is generated.

Signed-off-by: Harry Fellowes <harryfellowes1@gmail.com>
Copyright-paperwork-exempt: Yes

13 days agotests: date: add tests for the Ethiopian calendar
Collin Funk [Wed, 23 Jul 2025 03:30:49 +0000 (20:30 -0700)] 
tests: date: add tests for the Ethiopian calendar

* tests/date/date-ethiopia.sh: New file.
* tests/local.mk (all_tests): Add the test.

13 days agotests: date: add tests for the Solar Hijri calendar
Collin Funk [Wed, 23 Jul 2025 03:14:35 +0000 (20:14 -0700)] 
tests: date: add tests for the Solar Hijri calendar

* tests/date/date-iran.sh: New file.
* tests/local.mk (all_tests): Add the test.

13 days agoinstall: with -d, use more accurate diagnostics
Pádraig Brady [Tue, 22 Jul 2025 19:34:50 +0000 (20:34 +0100)] 
install: with -d, use more accurate diagnostics

* gnulib: Update to latest to get the fix to
propagate the appropriate error message.
* tests/install/basic-1.sh: Add a test case.
* NEWS: Mention the bug fix.
Addresses https://bugs.gnu.org/79072

2 weeks agotests: date: add tests for the Thai solar calendar
Collin Funk [Fri, 18 Jul 2025 02:42:30 +0000 (19:42 -0700)] 
tests: date: add tests for the Thai solar calendar

* tests/date/date-thailand.sh: New file.
* tests/local.mk (all_tests): Add the test.

2 weeks agodoc: NEWS: mention that 'date' now supports non-Gregorian calendars
Collin Funk [Mon, 21 Jul 2025 21:47:30 +0000 (14:47 -0700)] 
doc: NEWS: mention that 'date' now supports non-Gregorian calendars

Suggested by Bruno Haible in:
<https://lists.gnu.org/r/bug-gnulib/2025-07/msg00091.html>.

* NEWS: Mention the improvement.

2 weeks agobuild: update gnulib submodule to latest
Collin Funk [Mon, 21 Jul 2025 21:43:59 +0000 (14:43 -0700)] 
build: update gnulib submodule to latest

* bootstrap: Update using './bootstrap --bootstrap-sync'.

2 weeks agodate: update documentation regarding non-Gregorian calendars
Bruno Haible [Thu, 17 Jul 2025 14:30:57 +0000 (16:30 +0200)] 
date: update documentation regarding non-Gregorian calendars

* doc/coreutils.texi (Calendars): New section.

2 weeks agodate: force a Gregorian calendar for options --iso-8601 and --rfc-3339
Bruno Haible [Thu, 17 Jul 2025 14:29:05 +0000 (16:29 +0200)] 
date: force a Gregorian calendar for options --iso-8601 and --rfc-3339

* src/date.c (show_date_helper): Add a use_c_locale parameter.
(batch_convert): Add a format_in_c_locale parameter.
(main): Set format_in_c_locale to true if any of the options --rfc-3339,
--iso-8601, -R is seen.

3 weeks agotests: sort: add a test for equivalent floats
Pádraig Brady [Sat, 12 Jul 2025 18:58:06 +0000 (19:58 +0100)] 
tests: sort: add a test for equivalent floats

* tests/sort/sort-float.sh: Ensure equivalent floats
are treated as such.

3 weeks agotests: fix fraction comparison in sort-float
Paul Eggert [Fri, 11 Jul 2025 21:43:32 +0000 (14:43 -0700)] 
tests: fix fraction comparison in sort-float

Problem reported by Cosima Neidahl <https://bugs.gnu.org/78985#13>.
* tests/sort/sort-float.sh: At top level, use C locale at first.
(dbl_minima_order): Assume C locale.
Use string comparison for the fractional parts.

2025-07-10  Paul Eggert  <eggert@cs.ucla.edu>

tests: fix integer overflow in sort-float
Problem reported by Cosima Neidahl <https://bugs.gnu.org/78985>.
* tests/sort/sort-float.sh (dbl_minima_order):
Use expr instead of test, to avoid problems with integers
too large for the shell.

3 weeks agotests: fix integer overflow in sort-float
Paul Eggert [Thu, 10 Jul 2025 17:17:29 +0000 (10:17 -0700)] 
tests: fix integer overflow in sort-float

Problem reported by Cosima Neidahl <https://bugs.gnu.org/78985>.
* tests/sort/sort-float.sh (dbl_minima_order):
Use expr instead of test to compare fractions,
to avoid problems with integers too large for the shell.

3 weeks agofactor: remove SINGLE_WORKS
Paul Eggert [Thu, 10 Jul 2025 05:26:39 +0000 (22:26 -0700)] 
factor: remove SINGLE_WORKS

* src/factor.c (SINGLE_WORKS): Remove, and remove its use,
as the buggy code that it is referring to has been removed.

3 weeks agofactor: use 64-bit internal counters
Paul Eggert [Thu, 10 Jul 2025 04:59:50 +0000 (21:59 -0700)] 
factor: use 64-bit internal counters

* src/factor.c (factor_using_pollard_rho)
(factor_using_pollard_rho2, mp_factor_using_pollard_rho):
Use int_fast64_t for internal counters rather than int, as int
could overflow on some somewhat-practical examples.  Problem
discovered on a hypothetical platform where W_TYPE_SIZE is neither
32 nor 64, when factoring 0x7ffffffffffffeab7fffffffffff7369 ==
170141183460469225450570946617781744489, causing k to overflow in
mp_factor_using_pollard_rho.  Presumably a similar problem exists
in the previous stable coreutils 9.7, too, on 32-bit platforms
with somewhat-larger test cases, though I haven’t take the
somewhat-extensive CPU time to discover it.

3 weeks agofactor: fix mp_factor_using_pollard_rho aliasing
Paul Eggert [Thu, 10 Jul 2025 04:22:12 +0000 (21:22 -0700)] 
factor: fix mp_factor_using_pollard_rho aliasing

* src/factor.c (mp_factor_using_pollard_rho):
Fix recently-introduced aliasing bug by computing q
before g gets updated in place.  Problem discovered
on a hypothetical platform where W_TYPE_SIZE
is neither 32 nor 64.

3 weeks agomaint: fix apostrophe in old NEWS
Paul Eggert [Wed, 9 Jul 2025 22:20:17 +0000 (15:20 -0700)] 
maint: fix apostrophe in old NEWS

3 weeks agofactor: speed up converting strings to uuint
Paul Eggert [Wed, 9 Jul 2025 17:36:04 +0000 (10:36 -0700)] 
factor: speed up converting strings to uuint

* src/factor.c: Do not include c-ctype.h.
(strtouuint): Don’t bother generating a number on
error; just return a strtol_error value other than LONGINT_OK.
Speed up overflow checking.

3 weeks agofactor: simplify primes table
Paul Eggert [Wed, 9 Jul 2025 16:48:21 +0000 (09:48 -0700)] 
factor: simplify primes table

* src/factor.c (primes_ptab): New table of primes, replacing
primes_diff and primes_diff8.  All uses changed.  This is simpler
and should improve performance slightly.  Although this limits the
table’s primes to 2**15 instead of to 668221, the limit can easily
grow to 2**32 by changing the type of ‘prime’, without hurting
performance significantly compared to the primes_diff and
primes_diff8 approach.
* src/make-prime-list.c (output_primes):
For each prime p, output p instead of two differences.

3 weeks agofactor: prefer false for boolean 0
Paul Eggert [Wed, 9 Jul 2025 04:23:20 +0000 (21:23 -0700)] 
factor: prefer false for boolean 0

* src/factor.c: Prefer false to 0 for booleans.

3 weeks agomaint: port speedgen to FreeBSD 15
Paul Eggert [Mon, 7 Jul 2025 07:26:40 +0000 (00:26 -0700)] 
maint: port speedgen to FreeBSD 15

* src/speedgen: Avoid ‘trap 'command' ERR’, as ERR
does not conform to POSIX and does not work in
FreeBSD 15 sh.

3 weeks agofactor: speed up Pollard-rho loop counters
Paul Eggert [Mon, 7 Jul 2025 03:18:10 +0000 (20:18 -0700)] 
factor: speed up Pollard-rho loop counters

* src/factor.c (factor_using_pollard_rho)
(factor_using_pollard_rho2, mp_factor_using_pollard_rho):
Use int, not unsigned long int, for counters that won’t go above
2**31 on practical platforms.  This yields a significant speedup
on GCC 15 x86-64, and using signed values allows for automatic
checks for overflow when using gcc -fsanitize=undefined.

3 weeks agofactor: avoid an mpz init+clear
Paul Eggert [Sun, 6 Jul 2025 20:59:56 +0000 (13:59 -0700)] 
factor: avoid an mpz init+clear

* src/factor.c (mp_factor_insert_ui): Rename fom
mp_factor_insert_ui, and change arg type from unsigned long int to
mp_limb_t.  All uses changed.  This avoids creating and freeing a
small mpz_t.
(mp_factor_using_division): Add a static assert requiring that
that mp_limb_t be wide enough, which it should be (and is in
standard GMP).

3 weeks agofactor: Pollard-rho a is now mp_limb_t
Paul Eggert [Sun, 6 Jul 2025 16:34:00 +0000 (09:34 -0700)] 
factor: Pollard-rho a is now mp_limb_t

* src/factor.c (factor_using_pollard_rho)
(factor_using_pollard_rho2): Use mp_limb_t, not unsigned long int,
for a parameter.  This avoids some casts, and avoids a theoretical
bug where converting to mp_limb_t loses info.

3 weeks agofactor: redo ge2 in terms of lt2
Paul Eggert [Sun, 6 Jul 2025 05:12:22 +0000 (22:12 -0700)] 
factor: redo ge2 in terms of lt2

lt2 a bit more natural, given the current implementation.
* src/factor.c (lt2): New function.
(ge2): Rewrite in terms of lt2.
(gt2): Remove.  All callers changed to use lt2.

3 weeks agofactor: speed up umul_ppmm when !USE_LONGLONG_H
Paul Eggert [Sat, 5 Jul 2025 18:04:54 +0000 (11:04 -0700)] 
factor: speed up umul_ppmm when !USE_LONGLONG_H

* src/factor.c (umul_ppmm): When !USE_LONGLONG_H so we need to
define this, speed things up if there is an unsigned type uuroom_t
wide enough to hold two words.  Do not make a similar change for
udiv_qrnnd, as it is not performance critical and anyway on GCC 15
x86-64 that would mean a subroutine call.

3 weeks agofactor: streamline gcd2_odd
Paul Eggert [Sat, 5 Jul 2025 15:45:17 +0000 (08:45 -0700)] 
factor: streamline gcd2_odd

* src/factor.c (gcd2_odd): Omit a gt2 and adjusts other
tests accordingly.  Omit duplicate code that makes A odd.

3 weeks agofactor: faster gcd_odd since 2nd is odd
Paul Eggert [Sat, 5 Jul 2025 14:07:25 +0000 (07:07 -0700)] 
factor: faster gcd_odd since 2nd is odd

* src/factor.c (gcd_odd, gcd2_odd): Speed up, given that the
second argument is always odd.
(gcd_odd): Avoid recomputing a temporary.
(gcd2_odd): Test for zero only if a multiple of B.
This saves an ‘assume’.

3 weeks agodoc: update ‘factor’ benchmarks
Paul Eggert [Thu, 3 Jul 2025 16:24:27 +0000 (09:24 -0700)] 
doc: update ‘factor’ benchmarks

3 weeks agofactor: prefer exact division
Paul Eggert [Fri, 4 Jul 2025 06:11:26 +0000 (23:11 -0700)] 
factor: prefer exact division

* src/factor.c (mp_factor_using_division, mp_factor_using_pollard_rho):
Use exact division when it suffices, as it’s typically faster.

3 weeks agofactor: tune submod2
Paul Eggert [Wed, 2 Jul 2025 21:46:00 +0000 (14:46 -0700)] 
factor: tune submod2

* src/factor.c (submod2): Use ckd_sub to subtract by hand rather
than using sub_ddmmss plus a compare.  This speeds things up a
bit, on x86-64 with GCC 15 anyway.

3 weeks agofactor: DELIM and DIVBLOCK no longer macros
Paul Eggert [Wed, 2 Jul 2025 20:09:55 +0000 (13:09 -0700)] 
factor: DELIM and DIVBLOCK no longer macros

* src/factor.c (DELIM): Now a constant, not a macro.
(divblock): Now a static inline function, not a macro DIVBLOCK.
All uses changed.

3 weeks agofactor: simplify by assuming !PROVE_PRIMALITY
Paul Eggert [Wed, 2 Jul 2025 14:48:54 +0000 (07:48 -0700)] 
factor: simplify by assuming !PROVE_PRIMALITY

* src/factor.c (PROVE_PRIMALITY, mp_millerrabin): Remove.
All uses removed, and surrounding code simplified.

3 weeks agofactor: simplify by assuming USE_BAILLIE_PSW
Paul Eggert [Wed, 2 Jul 2025 02:56:53 +0000 (19:56 -0700)] 
factor: simplify by assuming USE_BAILLIE_PSW

* src/factor.c (make_uuint2, powm, powm2, millerrabin)
(millerrabin2, USE_BAILLIE_PSW): Remove; no longer used.
(prime_p, prime2_p): Simplify by assuming USE_BAILLIE_PSW.

3 weeks agofactor: prime comments
Paul Eggert [Tue, 1 Jul 2025 19:59:17 +0000 (12:59 -0700)] 
factor: prime comments

* src/factor.c: Add comments re prime functions.

3 weeks agofactor: no ferror+fclose
Paul Eggert [Tue, 1 Jul 2025 18:53:33 +0000 (11:53 -0700)] 
factor: no ferror+fclose

* src/make-prime-list.c (main): Avoid parallel calls
to ferror and fclose.

3 weeks agofactor: define SQUARE_OF_FIRST_OMITTED_PRIME
Paul Eggert [Tue, 1 Jul 2025 18:48:44 +0000 (11:48 -0700)] 
factor: define SQUARE_OF_FIRST_OMITTED_PRIME

* src/make-prime-list.c (output_primes): Output
SQUARE_OF_FIRST_OMITTED_PRIME, not FIRST_OMITTED_PRIME.  All uses
changed.  This way, the uses don’t need to worry about casts to
avoid overflow.

3 weeks agofactor: simplify add_ssaaaa default
Paul Eggert [Tue, 1 Jul 2025 10:34:21 +0000 (03:34 -0700)] 
factor: simplify add_ssaaaa default

* src/factor.c (add_ssaaaa): Simplify default implementation.

3 weeks agofactor: speed up ge2, gt2
Paul Eggert [Tue, 1 Jul 2025 10:33:27 +0000 (03:33 -0700)] 
factor: speed up ge2, gt2

* src/factor.c (ge2, gt2): Now branchless static functions.

3 weeks agofactor: improve millerrabin2 API
Paul Eggert [Tue, 1 Jul 2025 02:05:55 +0000 (19:05 -0700)] 
factor: improve millerrabin2 API

* src/factor.c (make_uuint2): New function.
(powm2, millerrabin2): Pass two-word args as uuints,
not as mp_limb_t const [2] pointers.  All uses changed.
(prime2_p): Rework to use the new API, fixing a FIXME.

3 weeks agofactor: put FACTORS first
Paul Eggert [Mon, 30 Jun 2025 14:34:53 +0000 (07:34 -0700)] 
factor: put FACTORS first

* src/factor.c (factor_using_division, mp_finish_up_in_single)
(mp_finish_in_single, factor_using_pollard_rho)
(factor_using_pollard_rho2, factor_up, factor):
Put FACTORS arg first, for consistency.
This is just a refactoring and should not affect speed.

3 weeks agofactor: use 1-word code only when tested
Paul Eggert [Mon, 23 Jun 2025 17:26:28 +0000 (10:26 -0700)] 
factor: use 1-word code only when tested

* src/factor.c (print_factors): Use single-precision code only
when word size is 32 or 64, as it isn't tested for other sizes and
is known to not work when it the size is 128.  This change does
not affect any known practical platforms.

3 weeks agofactor: decrement Miller-Rabin tests from 25 to 24
Paul Eggert [Mon, 23 Jun 2025 05:31:54 +0000 (22:31 -0700)] 
factor: decrement Miller-Rabin tests from 25 to 24

This avoids some seemingly-unnecessary code in mpz_probab_prime_p.
* src/factor.c (MR_REPS): Shrink from 25 to 24, and add commentary.

3 weeks agofactor: don’t prove primality
Paul Eggert [Sat, 21 Jun 2025 18:41:11 +0000 (11:41 -0700)] 
factor: don’t prove primality

Suggested for consideration by Torbjörn Granlund in:
https://lists.gnu.org/r/coreutils/2025-01/msg00000.html
* src/factor.c (PROVE_PRIMALITY): Now defaults to false.
(mp_prime_p): Help the compiler by telling it mpz_prob_prime_p
returns nonnegative.
* tests/factor/create-test.sh (bigprime): Test 2^400 - 593,
since that’s now practical.
* tests/local.mk (factor_tests): Add new test.

3 weeks agofactor: add comments to factor.c
Paul Eggert [Sat, 21 Jun 2025 00:16:06 +0000 (17:16 -0700)] 
factor: add comments to factor.c

3 weeks agofactor: always use Baillie-PSW
Paul Eggert [Sun, 15 Jun 2025 06:10:25 +0000 (23:10 -0700)] 
factor: always use Baillie-PSW

* src/factor.c (USE_BAILLIE_PSW): New constant.
(prime_p, prime2_p): Use it, i.e., always use Baillie-PSW.
Do so by using mp_prime_p.  Do not tell GCC these functions
are pure; the pure mark was present only to pacify GCC
and is no longer needed now that thes functions call mp_prime_p.

3 weeks agobuild: update gnulib submodule to latest
Paul Eggert [Sun, 15 Jun 2025 05:54:44 +0000 (22:54 -0700)] 
build: update gnulib submodule to latest

3 weeks agofactor: use mpz_probab_prime_p
Paul Eggert [Thu, 12 Jun 2025 20:51:46 +0000 (13:51 -0700)] 
factor: use mpz_probab_prime_p

Inspired by a proposal by Torbjörn Granlund in:
https://lists.gnu.org/r/coreutils/2025-01/msg00000.html
* src/factor.c (mp_prime_p): Use mpz_probab_prime_p rather than doing
it by hand, as mpz_probab_prime_p uses Baillie-PSW which is a win.
This removes the need for the ret2 label and goto.

3 weeks agofactor: don’t give up before last prime in table
Paul Eggert [Thu, 12 Jun 2025 20:45:57 +0000 (13:45 -0700)] 
factor: don’t give up before last prime in table

* src/factor.c (prime_p, prime2_p, mp_prime_p): Do not skip the
flag_prove_primality test for the last prime in the table, i.e.,
when r == PRIMES_PTAB_ENTRIES - 1.
(mp_prime_p): There is no longer a need for the ret1 label or goto.

3 weeks agofactor: move prime_p local in
Paul Eggert [Thu, 12 Jun 2025 20:38:59 +0000 (13:38 -0700)] 
factor: move prime_p local in

* src/factor.c (mp_prime_p): Refactor by moving local further in.

3 weeks agofactor: port back to mini-gmp
Paul Eggert [Fri, 4 Jul 2025 18:52:36 +0000 (11:52 -0700)] 
factor: port back to mini-gmp

mini-gmp lacs mpn_tdiv_qr, so supply an emulation of it
when using mini-gmp.
* src/factor.c (copy_mpn_from_mpz, mpn_tdiv_qr) [!mpn_tdiv_qr]:
New functions.

3 weeks agofactor: speed up multiprecision Pollard’s rho
Paul Eggert [Wed, 11 Jun 2025 00:40:34 +0000 (17:40 -0700)] 
factor: speed up multiprecision Pollard’s rho

These changes are taken from a proposal by Torbjörn Granlund in:
https://lists.gnu.org/r/coreutils/2025-01/msg00000.html
On my x86-64 platform, they improve speed by more than 8× when
factoring 340282366920938463463374607431768211457.
* src/factor.c (mp_modadd, mp_modsub, mp_modadd_1, mp_mulredc):
New functions.
(MP_FACTOR_USING_POLLARD_RHO_N_MAX): New macro.
(mp_factor_using_pollard_rho): Act on mpn not mpz, and on
mp_limb_t not unsigned long int.  Reorder args.  All uses changed.

3 weeks agofactor: use function for binv
Paul Eggert [Tue, 10 Jun 2025 03:51:56 +0000 (20:51 -0700)] 
factor: use function for binv

* src/factor.c (binv_limb): New function, replacing the old
binv macro.  All uses changed.

3 weeks agofactor: use a more functional style
Paul Eggert [Tue, 10 Jun 2025 00:28:34 +0000 (17:28 -0700)] 
factor: use a more functional style

This is mostly to make the code a bit easier to read.
It shrinks the size of factor.o by 0.7% on my x86-64 platform
though it doesn’t affect CPU performance significantly.
* src/factor.c (mp_no_factors): Rename from mp_factor_init.
(mp_no_factors, mp_factor_using_division, mp_factor):
Return struct mp_factors rather than modifying one passed by reference.
All uses changed.

3 weeks agofactor: use single vector in struct mp_factors
Paul Eggert [Mon, 9 Jun 2025 16:20:56 +0000 (09:20 -0700)] 
factor: use single vector in struct mp_factors

* src/factor.c (struct mp_factor): New type.
(struct mp_factors): Use it to replace P and E with F.
All uses changed.

3 weeks agofactor: omit unnecessary divisions by small primes
Paul Eggert [Sun, 8 Jun 2025 18:34:51 +0000 (11:34 -0700)] 
factor: omit unnecessary divisions by small primes

* src/factor.c (mp_factor_using_division):
When continuing in single precision, don’t divide by primes that
were already cast out in multiple precision.
On my platform this gave a 2.5% speedup when factoring
2**128 + 172261 = 4999 * 68070087401668026297934508388031283,
as W_TYPE_SIZE == 64 and 4999 is the last prime in the primes table.