]> git.ipfire.org Git - thirdparty/coreutils.git/log
thirdparty/coreutils.git
4 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.

4 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.

4 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.

4 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.

4 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.

4 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.

4 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.

4 weeks agofactor: use primes_diff more consistently
Paul Eggert [Sun, 8 Jun 2025 07:59:44 +0000 (00:59 -0700)] 
factor: use primes_diff more consistently

* src/factor.c (mp_factor_using_division): Use index into
primes_diff consistently with other uses.  This is mostly just a
style change, and likely doesn’t change the generated machine code.

4 weeks agofactor: refactor to for later performance speedup
Paul Eggert [Sun, 8 Jun 2025 05:29:54 +0000 (22:29 -0700)] 
factor: refactor to for later performance speedup

This does not affect performance much, but it should allow future
performance improvements.
* src/factor.c (factor_using_division): Two new args I and P,
which generalize this function.  All uses changed.
(mp_finish_up_in_single, factor_up): New functions, like the
non-*_up* versions but with two new args PRIME_IDX and PRIME.
They mostly just have the old body of the old non-*_up_ versions.
(mp_finish_in_single, factor): Rewrite in terms of the new functions.

4 weeks agofactor: switch from mp to single when doable
Paul Eggert [Wed, 4 Jun 2025 17:12:29 +0000 (10:12 -0700)] 
factor: switch from mp to single when doable

This significantly improves performance when a number exceeds
2**(W_TYPE_SIZE - 1) and is the product of a prime less than
FIRST_OMITTED_PRIME and another prime less than 2**(W_TYPE_SIZE - 1).
On my platform, for example, it doubled the speed of factoring
4999 * (2**128 - 159).
* src/factor.c (mp_size, mp_finish_in_single): New functions.
(mp_factor_using_division, mp_factor_using_pollard_rho):
Finish using single precision when possible.
* tests/factor/factor.pl (lt-5000-times-128-bit): New test.

4 weeks agofactor: primes_diff idx type consistency
Paul Eggert [Wed, 4 Jun 2025 15:07:23 +0000 (08:07 -0700)] 
factor: primes_diff idx type consistency

* src/factor.c (factor_insert_refind):
Use idx_t for indexes into primes_diff,
for consistency with other indexes into primes_diff.
This has no practical effect unless the primes_diff
table becomes unreasonably large.

4 weeks agofactor: omit q from mp_factor_using_division
Paul Eggert [Mon, 2 Jun 2025 17:03:34 +0000 (10:03 -0700)] 
factor: omit q from mp_factor_using_division

* src/factor.c (mp_factor_using_division): Remove unused local.

4 weeks agofactor: mp insert multiplicity too
Paul Eggert [Mon, 2 Jun 2025 17:02:14 +0000 (10:02 -0700)] 
factor: mp insert multiplicity too

Support a multiplicity argument in the mp case, too.
This helps keeps the two cases in sync, for maintenance.
* src/factor.c (mp_factor_insert, mp_factor_insert_ui):
New arg M, for multiplicity.  All callers changed.

4 weeks agofactor: prefer non-macros
Paul Eggert [Mon, 2 Jun 2025 05:47:36 +0000 (22:47 -0700)] 
factor: prefer non-macros

Use something other than a macro when that is easy and won’t hurt
performance.
* src/factor.c (__ll_B, __ll_lowpart, _ll_highpart) [!USE_LONGLONG_H]:
(MAX_NFACTS, highbit_to_mask, factor_insert, PRIMES_PTAB_ENTRIES):
Make these enums, or constants, or static functions instead of macros.
(highbit_to_mask): Rename from HIGHBIT_TO_MASK.  All uses changed.

4 weeks agofactor: let builder specify MR_REPS
Paul Eggert [Sat, 14 Jun 2025 02:48:16 +0000 (19:48 -0700)] 
factor: let builder specify MR_REPS

* src/factor.c (MR_REPS): Let the builder specify it
with -DMR_REPS=whatever.

4 weeks agofactor: add comments
Paul Eggert [Sat, 31 May 2025 20:09:02 +0000 (13:09 -0700)] 
factor: add comments

4 weeks agofactor: factor insertion simplifications
Paul Eggert [Sat, 31 May 2025 01:58:21 +0000 (18:58 -0700)] 
factor: factor insertion simplifications

* src/factor.c (factor_insert_multiplicity):
Adjust to keep in sync with mp_factor_insert changes below,
by adding 1 to the index and using memmove to move.
(mp_factor_insert): Omit redundant call to mpz_cmp.
Prefer idx_t (always nonnegative) to ptrdiff_t,
by adding 1 to the indexes.
Prefer mpz_init_set to mpz_init+mpz_set.
Use memmove to move, rather than doing it by hand.

4 weeks agofactor: check unsigned char counts
Paul Eggert [Sat, 24 May 2025 18:57:05 +0000 (11:57 -0700)] 
factor: check unsigned char counts

* src/factor.c (MAX_NFACTS): Allow word size of 128 bits,
even if this is only theoretical now.
Check that struct factors’s unsigned char counts won’t overflow.

4 weeks agofactor: fix comment
Paul Eggert [Sat, 24 May 2025 17:37:48 +0000 (10:37 -0700)] 
factor: fix comment

4 weeks agofactor: paren cleanup
Paul Eggert [Sat, 24 May 2025 17:25:21 +0000 (10:25 -0700)] 
factor: paren cleanup

* src/factor.c (umul_ppmm, udiv_qrnnd, addmod, addmod2, submod2)
(binv, divexact_21, redcify2, div_smallq): Omit unnecessary parens.

4 weeks agofactor: simplify longlong.h setup
Paul Eggert [Thu, 22 May 2025 22:35:22 +0000 (15:35 -0700)] 
factor: simplify longlong.h setup

* src/factor.c (USE_LONGLONG_H):
Default to false on unusual (but standard-conforming)
platforms that lack int64_t etc.
(UWtype, UHWtype): Now typedefs, not macros.
(UQItype): Remove.
(SItype, USItype, DItype, UDItype): Use standard C types.

4 weeks agofactor: prefer uuint to two words in a couple of places
Paul Eggert [Sun, 1 Jun 2025 23:28:47 +0000 (16:28 -0700)] 
factor: prefer uuint to two words in a couple of places

This simplifies things slightly by using uuint for
some two-word integers.
* src/factor.c (strtouuint): Accept uuint *, not two mp_limb_t *.
All callers changed.
(print_factors_single): Accept uuint, not two limbs.
All callers changed.
(print_factors): Use simpler test for high bit,
one that need not worry about promoting to int.

4 weeks agofactor: FALLTHROUGH instead of break
Paul Eggert [Sun, 1 Jun 2025 23:22:55 +0000 (16:22 -0700)] 
factor: FALLTHROUGH instead of break

* src/factor.c (print_factors): Use FALLTHROUGH
to make it clear that the "Use GMP" comment also applies here.

4 weeks agofactor: remove wide_uuint
Paul Eggert [Sun, 1 Jun 2025 23:18:09 +0000 (16:18 -0700)] 
factor: remove wide_uuint

Simplify by using GMP’s word type instead of pretending to roll our own.
* src/factor.c (wide_uuint): Remove.  All uses replaced by mp_limb_t.
(umul_ppmm) [!umul_ppmm]: Don’t assume unsigned long is at least half
as wide as mp_limb_t.  This simpler anyway.
(strtouuint): Rename from strto2wide_uint.  All uses changed.

4 weeks agofactor: use same word size as GMP
Paul Eggert [Sun, 1 Jun 2025 23:02:21 +0000 (16:02 -0700)] 
factor: use same word size as GMP

Remove experimental code for 128-bit words as it does not work and
we lack time to figure out why.  Instead, ensure that words are
the same size as with GMP.
* src/factor.c (USE_INT128): Remove.  All uses removed.
(wide_uint, W_TYPE_SIZE): Define to be the same as GMP.
(MP_LIMB_MAX): New macro.  Check that it matches W_TYPE_SIZE.
(USE_LONGLONG_H): Default to true.
(UHWtype) [USE_LONGLONG_H]: Define to unsigned int, same as GMP.
(prime_p): Go back to not worrying about 128-bit words,
since GMP doesn’t worry and doesn’t use them.
(lbuf_putbitcnt): New function, since we cannot assume
that bitcnt_t fits into mp_limb_t.
(print_factors): Use it.
* src/make-prime-list.c (output_primes):
Don’t assume that wide_uint’s maximum is UINTMAX_MAX.

4 weeks agofactor: unsigned long → mp_bitcnt_t
Paul Eggert [Mon, 2 Jun 2025 06:18:23 +0000 (23:18 -0700)] 
factor: unsigned long → mp_bitcnt_t

* src/factor.c (struct mp_factors): e (multiplicity) member
is now of type mp_bitcnt_t, not unsigned long int, since
its value is at most a bit count.  All uses changed.

4 weeks agofactor: fix test case name
Paul Eggert [Tue, 20 May 2025 21:15:01 +0000 (14:15 -0700)] 
factor: fix test case name

* tests/factor/factor.pl (bug-gmp-plus_2_sup_127_plus_1):
Rename from bug-gmp-plus_2_sup_128_plus_1, so that
it accurately reflects the test case.

4 weeks agofactor: generalize BIG_POWER_OF_10
Paul Eggert [Sun, 1 Jun 2025 22:55:27 +0000 (15:55 -0700)] 
factor: generalize BIG_POWER_OF_10

* src/factor.c (BIG_POWER_OF_10, LOG_BIG_POWER_OF_10):
Place fewer restrictions on BIG_POWER_OF_10.
This is only for currently-theoretical hosts;
it shouldn’t affect machine code on practical platforms.

4 weeks agofactor: remove wide_int
Paul Eggert [Sun, 1 Jun 2025 22:51:26 +0000 (15:51 -0700)] 
factor: remove wide_int

* src/factor.c (wide_int): Remove, since it gets in the
way of using mp_limb_t for words.  All uses removed.
(submod2, HIGHBIT_TO_MASK, divexact_21):
Rewrite without using wide_int.
This shouldn't change the machine code these days,
as compilers are pretty smart about isolating the
top bit of an unsigned int.

4 weeks agofactor: add platform sanity check
Paul Eggert [Sun, 1 Jun 2025 22:47:33 +0000 (15:47 -0700)] 
factor: add platform sanity check

* src/factor.c: Check against theoretical platform.

4 weeks agofactor: squfof cleanup
Paul Eggert [Sat, 24 May 2025 17:29:06 +0000 (10:29 -0700)] 
factor: squfof cleanup

* src/factor.c (USE_SQUFOF, STAT_SQUFOF):
Assume these are always false, and simplify the code accordingly.
We can bring it back later if needed be.

4 weeks agofactor: don’t used uninitialized uu[0]
Paul Eggert [Sun, 1 Jun 2025 01:17:34 +0000 (18:17 -0700)] 
factor: don’t used uninitialized uu[0]

In practice there’s no bug but we might as well avoid the
undefined behavior.
* src/factor.c (hi_is_set): New static function.
(factor_insert_large, prime2_p, print_factors_single): Use it.

5 weeks agobuild: avoid make distcheck error
Pádraig Brady [Sat, 5 Jul 2025 16:45:00 +0000 (17:45 +0100)] 
build: avoid make distcheck error

* src/local.mk: Similarly to commit v8.22-156-g09937e9d0
track speedlist.h with nodist_src_stty_SOURCES and DISTCLEANFILES
to ensure the make distcheck manifest comparison passes.
Addresses https://bug.gnu.org/78960

5 weeks agodoc: fix a dead link
Collin Funk [Sat, 5 Jul 2025 04:07:23 +0000 (21:07 -0700)] 
doc: fix a dead link

* doc/coreutils.texi (Block Size): Use an updated link to SI prefixes.

5 weeks agobuild: fix non parallel VPATH builds
Pádraig Brady [Sat, 5 Jul 2025 11:49:02 +0000 (12:49 +0100)] 
build: fix non parallel VPATH builds

* src/local.mk: Use the coarser BUILT_SOURCES mechanism
to generate speedlist.h, rather than a specific dependency
(which did seem to work for parallel builds).
Fixes https://bugs.gnu.org/78960

5 weeks agomaint: prefer endian.h macros to WORDS_BIGENDIAN, part 2
Collin Funk [Sat, 5 Jul 2025 03:52:37 +0000 (20:52 -0700)] 
maint: prefer endian.h macros to WORDS_BIGENDIAN, part 2

* src/blake2/blake2-impl.h: Include endian.h. Use BYTE_ORDER and
LITTLE_ENDIAN instead of WORDS_BIGENDIAN.

5 weeks agomaint: prefer endian.h macros to WORDS_BIGENDIAN
Collin Funk [Fri, 4 Jul 2025 17:59:39 +0000 (10:59 -0700)] 
maint: prefer endian.h macros to WORDS_BIGENDIAN

* src/od.c: Include endian.h.
(WORDS_BIGENDIAN): Remove definition.
(main): Use BYTE_ORDER, BIG_ENDIAN, LITTLE_ENDIAN instead of
WORDS_BIGENDIAN. Fix formatting.

5 weeks agomaint: add files generated by 'make ps' to .gitignore
Collin Funk [Thu, 3 Jul 2025 02:01:06 +0000 (19:01 -0700)] 
maint: add files generated by 'make ps' to .gitignore

* doc/.gitignore (/coreutils.ps, /coreutils.t2d/): Add entries.

5 weeks agodoc: remove outdated TODO/FIXME items
Collin Funk [Thu, 3 Jul 2025 01:41:53 +0000 (18:41 -0700)] 
doc: remove outdated TODO/FIXME items

* TODO: Remove note about missing documentation for 'pinky' and '['.
* doc/coreutils.texi: Likewise.

5 weeks agotests: cat: add test for O_APPEND bug fix
Pádraig Brady [Tue, 1 Jul 2025 21:52:16 +0000 (22:52 +0100)] 
tests: cat: add test for O_APPEND bug fix

* tests/cat/cat-self.sh: Add a test case
for commit v9.6-19-g7386c291b

5 weeks agodoc: remove extraneous double quotes within @samp{}
Pádraig Brady [Tue, 1 Jul 2025 11:02:08 +0000 (12:02 +0100)] 
doc: remove extraneous double quotes within @samp{}

* doc/coreutils.texi (df invocation): @samp{} items
are suitably quoted already.

5 weeks agodoc: use ``...'' instead of "..."
Collin Funk [Tue, 1 Jul 2025 02:50:58 +0000 (19:50 -0700)] 
doc: use ``...'' instead of "..."

* doc/coreutils.texi (split invocation): Use ``...'' for quoting text.
(cksum common options): Likewise.
(Control): Likewise.

5 weeks agotests: avoid false failure due to varied ERANGE errors
Pádraig Brady [Mon, 30 Jun 2025 22:28:32 +0000 (23:28 +0100)] 
tests: avoid false failure due to varied ERANGE errors

* tests/od/od.pl: Use the system error string for ERANGE,
rather than hardcoding a particular one.
Fixes https://bugs.gnu.org/78934

5 weeks agood: port to Apple clang 14
Paul Eggert [Mon, 30 Jun 2025 22:40:57 +0000 (15:40 -0700)] 
od: port to Apple clang 14

* src/od.c (print_function_type): New type.  Use it for convenience.
(width_bytes): Omit duplicate entries, such as ‘double’ vs ‘long
double’ on macOS.  Problem reported by Bruno Haible
<https://bugs.gnu.org/78933>.
(decode_one_format): Cast null pointer to print_function_type
to pacify Apple clang-1400.0.29.202.

5 weeks agobuild: fix VPATH builds with --enable-single-binary
Pádraig Brady [Mon, 30 Jun 2025 14:34:22 +0000 (15:34 +0100)] 
build: fix VPATH builds with --enable-single-binary

* src/local.mk: Adjust the dependency so that speedlist.h
is built irrespective of the object file name.
Note we could use BUILT_SOURCES for this,
but it's better to have this more accurate dependency.

5 weeks agood: reinstate half float validation check
Pádraig Brady [Mon, 30 Jun 2025 13:25:56 +0000 (14:25 +0100)] 
od: reinstate half float validation check

Reinstate check removed in commit 56aa549a0 so that we
disallow -f2 when configured with utils_cv_ieee_16_bit_supported=no.
Otherwise the output routines will consume floats,
i.e. 4 bytes at a time.  Without this extra check
the tests/od/od-endian.sh will fail with this configuration.

* src/od.c (decode_one_format): Reinstate the explicit check
for this configuration edge case.

5 weeks agomaint: avoid sc_prohibit-quotearg failure
Pádraig Brady [Mon, 30 Jun 2025 12:10:15 +0000 (13:10 +0100)] 
maint: avoid sc_prohibit-quotearg failure

* src/od.c (parse_old_offset): s/quotearg_colon/quotef/.

5 weeks agood: add test cases for recent fix
Paul Eggert [Mon, 30 Jun 2025 05:31:01 +0000 (22:31 -0700)] 
od: add test cases for recent fix

* tests/od/od.pl: New tests for the offset issues

5 weeks agood: more minor fixes for offsets
Paul Eggert [Mon, 30 Jun 2025 05:25:28 +0000 (22:25 -0700)] 
od: more minor fixes for offsets

* src/od.c (parse_old_offset): Reject invalid offsets like "++0".
Treat overflowing offsets as errors, not as file names.

5 weeks agood: refactor parse_old_offset
Paul Eggert [Mon, 30 Jun 2025 01:06:22 +0000 (18:06 -0700)] 
od: refactor parse_old_offset

* src/od.c (parse_old_offset): Refactor for brevity and clarity.

5 weeks agomaint: fix version in NEWS
Paul Eggert [Mon, 30 Jun 2025 00:13:07 +0000 (17:13 -0700)] 
maint: fix version in NEWS

* NEWS: Update version number as per Jim Meyering
<https://bugs.gnu.org/78880#46>.

5 weeks agood: pacify gcc -Wduplicated-cond
Paul Eggert [Mon, 30 Jun 2025 00:12:07 +0000 (17:12 -0700)] 
od: pacify gcc -Wduplicated-cond

Problem reported by Pádraig Brady <https://bugs.gnu.org/78880#43>.
This patch doesn’t fix any bugs; it merely pacifies GCC.
* src/od.c (ispec_to_format): New function, replacing
the old ISPEC_TO_FORMAT macro.  All uses changed.
This part of the change is just refactoring.
(decode_one_format): Pacify à la ispec_to_format.

6 weeks agood: be more consistent re sizeof
Paul Eggert [Sun, 29 Jun 2025 03:57:00 +0000 (20:57 -0700)] 
od: be more consistent re sizeof

* src/od.c (width_bytes, decode_one_format): Don’t assume a signed
type has the same size as the corresponding unsigned type.
This has no effect on practical platforms; it’s just for
consistency there.

6 weeks agood: fix integer overflow with large pseudos
Paul Eggert [Sun, 29 Jun 2025 00:36:04 +0000 (17:36 -0700)] 
od: fix integer overflow with large pseudos

* src/od.c (format_address_label): Diagnose overflow.

6 weeks agood: speed up -S
Paul Eggert [Sat, 28 Jun 2025 22:21:18 +0000 (15:21 -0700)] 
od: speed up -S

* src/od.c (read_char): Use getc, not fgetc.

6 weeks agood: check sign bit more often
Paul Eggert [Sat, 28 Jun 2025 22:04:30 +0000 (15:04 -0700)] 
od: check sign bit more often

* src/od.c (read_char, dump_strings, main):
Instead of testing for an exact negative number,
just look at the sign bit.  This is a very minor tweak.

6 weeks agood: simplify away one loop copy
Paul Eggert [Sat, 28 Jun 2025 21:01:18 +0000 (14:01 -0700)] 
od: simplify away one loop copy

* src/od.c (dump): Coalesce two loops into one.

6 weeks agood: simpler static initialization
Paul Eggert [Sat, 28 Jun 2025 16:49:42 +0000 (09:49 -0700)] 
od: simpler static initialization

* src/od.c (address_base, address_pad_len, format_address):
Initialize statically rather than dynamically.
(limit_bytes_to_format): Remove.  All uses replaced by
checking sign of end_offset.
(max_bytes_to_format): Remove static var.  Now local to ‘main’.
(end_offset): -1 now means no limit.  All uses changed.

6 weeks agood: minor lcm tuning
Paul Eggert [Sat, 28 Jun 2025 00:52:15 +0000 (17:52 -0700)] 
od: minor lcm tuning

* src/od.c (dump, main): Redo lcm calcuations to avoid a multiply.

6 weeks agood: omit some duplicate code
Paul Eggert [Sat, 28 Jun 2025 00:08:28 +0000 (17:08 -0700)] 
od: omit some duplicate code

On x86-64 (for example) print_long, print_long_long, and
print_intmax all behave identically, so give GCC enough info so
that it generates code for just one of these functions.
* src/od.c (enum size_spec): Arrange for enum values to
be the same if they represent types that behave the same.
(width_bytes, ISPEC_TO_FORMAT, decode_one_format):
Match the enum size_spec changes.

6 weeks agood: replace lookup tables with simple arithmetic
Paul Eggert [Fri, 27 Jun 2025 23:08:06 +0000 (16:08 -0700)] 
od: replace lookup tables with simple arithmetic

* src/od.c (FMT_BYTES_ALLOCATED): Use a simpler formula.
Although slightly too generous, the storage wasted is very small
and it pacifies gcc -Wformat-overflow=2.
(bytes_to_oct_digits, bytes_to_signed_dec_digits)
(bytes_to_unsigned_dec_digits, bytes_to_hex_digoits): Remove.
All uses replaced by algorithmic calculations, which are good
enough: they are valid for integers up to 2620 bits (!) and might
be slightly conservative for wider integers.  Remove related
static_asserts, which are no longer needed.

6 weeks agood: support uintmax_t too
Paul Eggert [Fri, 27 Jun 2025 15:45:53 +0000 (08:45 -0700)] 
od: support uintmax_t too

This has practical effect only on hypothetical platforms where
uintmax_t is wider than unsigned long long int.
* src/od.c (enum size_spec): New constant INTMAX.
(MAX_INTEGRAL_TYPE_WIDTH): Now equals UINTMAX_WIDTH.
(FMT_BYTES_ALLOCATED): Allow for the extra "l" in "%lld".
Also, fix off-by-two error in size calculation.
(width_bytes, integral_type_size): Add entries for uintmax_t.
(print_intmax): New function.
(decode_one_function): Use it.
(ISPEC_TO_FORMAT): New arg Max_fmt. All uses changed.

6 weeks agood: initialize type-size tables statically
Paul Eggert [Fri, 27 Jun 2025 06:51:37 +0000 (23:51 -0700)] 
od: initialize type-size tables statically

* src/od.c (NO_SIZE): Make it explicitly 0, as the
initializers now rely on this.
(MAX_INTEGRAL_TYPE_SIZE): Remove.  All uses replaced by
ARRAY_CARDINALITY (integral_type_size) - 1.
Move static assertion down to where this can be used.
(integral_type_size, fp_type_size): Make them const,
and initialize them statically.
(main): Omit no-longer-needed initialization code.

6 weeks agood: prefer intmax_t to uintmax_t
Paul Eggert [Thu, 26 Jun 2025 15:45:47 +0000 (08:45 -0700)] 
od: prefer intmax_t to uintmax_t

* src/od.c (MAX_ADDRESS_LENGTH, pseudo_offset, n_bytes_to_skip)
(max_bytes_to_format, end_offset, skip, format_address_none)
(format_address_std, format_address_paren, format_address_label)
(write_block, parse_old_offset, dump, dump_strings, main):
Prefer intmax_t to uintmax_t.  This makes no practical difference,
and lets -fsanitize=undefined check for signed integer overflow.
(skip, dump): Remove no-longer-needed casts.
(xstr2nonneg): New static function.  All callers of xstrtoumax
now call this function instead.
(main): Use ckd_add to detect signed integer overflow, since
the unsigned trick no longer works reliably.
Let xstrtol_fatal report the overflow, instead of doing
it by hand ourselves.

6 weeks agood: fix '+N.' bug
Paul Eggert [Sun, 29 Jun 2025 00:29:22 +0000 (17:29 -0700)] 
od: fix '+N.' bug

* src/od.c (parse_old_offset): First arg is now char *,
not char const *.  If a decimal number, temporarily
modify the string so that xstrtoumax does not complain
about the '.'.
* tests/od/od.pl: Test for the bug.

6 weeks agood: fix some unlikely integer overflows
Paul Eggert [Thu, 26 Jun 2025 06:22:37 +0000 (23:22 -0700)] 
od: fix some unlikely integer overflows

* src/od.c (print_n_spaces, pad_at, pad_at_overflow):
New static functions.
(struct tspec, PRINT_FIELDS, print_named_ascii, print_ascii)
(decode_one_format, write_block, main):
Use idx_t, not int, for counts that depend on the number
of bytes in an object.
(decode_one_format): Use print_n_spaces to output spaces.
(PRINT_FIELDS, print_named_ascii, print_ascii):
Use pad_at to avoid integer overflow.
(write_block): Do not use %*s to pad, as the total pad might
exceed INT_MAX.  Instead, pad by hand with putchar (' ').
(main): Use pad_at_overflow to report integer overflow due to
oversize -w.  Use better way to tell whether -w is used,
without needing IF_LINT.
* tests/od/big-w.sh: New test.
* tests/local.mk (all_tests): Add it.

6 weeks agood: prefer idx_t to size_t
Paul Eggert [Wed, 25 Jun 2025 03:34:29 +0000 (20:34 -0700)] 
od: prefer idx_t to size_t

This helps find overflow bugs when compiling with -fsanitize=undefined.
* src/od.c (struct tspec, bytes_per_block, PRINT_FIELDS)
(PRINT_TYPE, print_named_ascii, print_ascii, decode_one_format)
(skip, write_block, read_block, dump, main):
Use idx_t, not size_t.

6 weeks agood: don’t assume no holes in wide unsigned
Paul Eggert [Wed, 25 Jun 2025 03:01:04 +0000 (20:01 -0700)] 
od: don’t assume no holes in wide unsigned

Also, fix minor related typos.
* src/od.c (MAX_INTEGRAL_TYPE_SIZE, MAX_ADDRESS_LENGTH):
Now a constant, not a macro.
(MAX_INTEGRAL_TYPE_WIDTH): New constant.  Use it instead of
CHAR_BIT, so as not to assume that uintmax_t and unsigned long
long int are hole-free.  This doesn’t matter on practical porting
targets, though there is still a mainframe or two that have holes.
(FMT_BYTES_ALLOCATED): Fix typo by changing "jd" to "jo".
Fix off-by-one typo in static assertion.

6 weeks agomaint: assume long long int
Paul Eggert [Wed, 25 Jun 2025 02:13:20 +0000 (19:13 -0700)] 
maint: assume long long int

It’s long been safe to assume C99+ support for long long int.
* .gitignore: Remove m4/longlong.m4.
* bootstrap.conf (buildreq): Boost git prereq from 1.4.4 to 1.5.5,
syncing with Gnulib.
(bootstrap_post_import_hook): Remove m4/longlong.m4.
* m4/jm-macros.m4 (gl_CHECK_ALL_TYPES):
No need to require AC_TYPE_UNSIGNED_LONG_LONG_INT.
* src/factor.c (DItype, UDItype):
* src/od.c (main):
Assume HAVE_LONG_LONG_INT.
* src/od.c: (unsigned_long_long_int):
Remove.  All uses replaced with unsigned long long int.

6 weeks agood: fix another off-by-one issue with --strings
Paul Eggert [Sat, 28 Jun 2025 15:07:54 +0000 (08:07 -0700)] 
od: fix another off-by-one issue with --strings

* src/od.c (main): Fix off-by-one error in string_min limit.

6 weeks agood: fix theoretical size_t malloc overflow
Paul Eggert [Sat, 28 Jun 2025 15:15:42 +0000 (08:15 -0700)] 
od: fix theoretical size_t malloc overflow

* src/od.c (dump, dump_strings): Use idx_t allocators
rather than size_t allocators, to avoid unchecked integer
overflow on theoretical platforms where SIZE_MAX < IDX_MAX.

6 weeks agodoc: list signals added by POSIX.1-2024
Collin Funk [Sat, 28 Jun 2025 05:15:28 +0000 (22:15 -0700)] 
doc: list signals added by POSIX.1-2024

* doc/coreutils.texi (Signal specifications): Mention that POSIX.1-2024
added SIGWINCH.

6 weeks agodoc: mention that POSIX.1-2024 added dd iflag=fullblock
Collin Funk [Fri, 27 Jun 2025 01:48:51 +0000 (18:48 -0700)] 
doc: mention that POSIX.1-2024 added dd iflag=fullblock

* doc/coreutils.texi (dd invocation): Document that POSIX.1-2024 added
iflag=fullblock.

6 weeks agodoc: cksum: --check: improve supported formats description
Pádraig Brady [Fri, 27 Jun 2025 14:02:50 +0000 (15:02 +0100)] 
doc: cksum: --check: improve supported formats description

* doc/coreutils.texi (cksum common options): Reorder and tweak the info
to make it clearer that --check does not support the legacy crc output
from the cksum command.
Reported at https://bugs.debian.org/1108363

6 weeks agomaint: prefer UINTMAX_MAX to TYPE_MAXIMUM (uintmax_t)
Collin Funk [Wed, 25 Jun 2025 04:39:20 +0000 (21:39 -0700)] 
maint: prefer UINTMAX_MAX to TYPE_MAXIMUM (uintmax_t)

* src/df.c (get_dev): Use UINTMAX_MAX.
* src/shred.c (dopass): Likewise.

6 weeks agood: output standard diagnostics for invalid -w arguments
Pádraig Brady [Tue, 24 Jun 2025 14:47:48 +0000 (15:47 +0100)] 
od: output standard diagnostics for invalid -w arguments

* src/od.c (main): Don't pass LONGINT_OK to xstrtol_fatal(),
as otherwise it will abort().
* tests/od/od.pl: Add test cases.
* NEWS: Mention the bug fix.

Addresses https://bugs.gnu.org/78879

6 weeks agood: fix various off-by-one issues with --strings with -N
Pádraig Brady [Tue, 24 Jun 2025 00:17:12 +0000 (01:17 +0100)] 
od: fix various off-by-one issues with --strings with -N

* src/od.c (dump_strings): There are three related issues here
due to not accounting for the terminating NUL char appropriately.

1. Ensure BUF always has enough space for the terminating NUL.
This avoids CWE-122: Heap-based Buffer Overflow,
where we wrote a single NUL byte directly after the allocated buffer.
I.e., there should be no buffer overflow with:
  printf '%100s' | od -N100 -S1

2. Ensure we support -S == -N (END_OFFSET - STRING_MIN == ADDRESS):
I.e., there should be output with:
  printf '%100s' | od -N10 -S10

3. Ensure we always output a valid address by ensuring
the ADDRESS and I variables are kept in sync.
I.e., this should output address 0000000 not 1777777777777777777777:
  printf '%100s' | od -N10 -S1

As well as fixing these we simplify by using a single loop
to read the data, rather than two.

* doc/coreutils.texi (od invocation): Clarify that -N
implicitly NUL terminates strings.
* tests/od/od-N.sh: Add test cases.
* NEWS: Mention the bug fixes.

Fixes https://bugs.gnu.org/78880

6 weeks agobuild: fix compilation error on OpenBSD and Solaris
Bruno Haible [Mon, 23 Jun 2025 20:59:47 +0000 (22:59 +0200)] 
build: fix compilation error on OpenBSD and Solaris

* src/speedgen: Use 'printf', not 'sed', to emit code with newlines.

6 weeks agomaint: make it clear when to add speeds to the speedgen list
H. Peter Anvin [Mon, 23 Jun 2025 18:20:48 +0000 (11:20 -0700)] 
maint: make it clear when to add speeds to the speedgen list

Add a comment making it clear that it is perfectly safe to add
additional speeds to the canned list in the speedgen script, and under
what conditions it is appropriate to do so.

Signed-off-by: "H. Peter Anvin" (Intel) <hpa@zytor.com>
6 weeks agostty: support baud rate macro extraction on more compilers
H. Peter Anvin [Mon, 23 Jun 2025 18:20:47 +0000 (11:20 -0700)] 
stty: support baud rate macro extraction on more compilers

For generating src/speedtest.h, try a sequence of command-line options
until (or unless) one of them works:

  -dM: gcc, clang and derived compilers, icc classic
  -xdumpmacros: Sun Studio (writes to stderr!)
  -qshowmacros: IBM XL classic
  -PD: MSVC (usable with a wrapper such as cccl from the SWIG project)

Because Sun Studio -xdumpmacros unconditionally writes to stderr,
capture stderr output instead of sending it to /dev/null. This is
perfectly safe, even in the presence of stray stderr output, because:

  1. speedgen ignores input that is not of the form #define B<number>
  2. even if a line of that format would somehow spuriously appear,
     the only outcome is that the generated C code will probe for a few
     more macros.

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
6 weeks agostdbuf: support AIX
Collin Funk [Mon, 23 Jun 2025 01:13:36 +0000 (18:13 -0700)] 
stdbuf: support AIX

* src/stdbuf.c (set_LD_PRELOAD): Use the AIX specific environment
variables LDR_PRELOAD or LDR_PRELOAD64.
* NEWS: Mention the bugfix.

6 weeks agostty: stricter floating point parsing
Pádraig Brady [Sun, 22 Jun 2025 15:40:04 +0000 (16:40 +0100)] 
stty: stricter floating point parsing

* src/stty.c (string_to_baud): Disallow extraneous characters
after floating point numbers.
* tests/stty/stty-invalid.sh: Add test cases.

6 weeks agodoc: stty: adjust description of supported speeds
Pádraig Brady [Sun, 22 Jun 2025 14:01:21 +0000 (15:01 +0100)] 
doc: stty: adjust description of supported speeds

* doc/coreutils.texi (stty invocation): Remove now imprecise
list of speeds given we may now support higher or arbitrary speeds.
Mention that we may support higher or arbitrary speeds.

6 weeks agobuild: add src/termios.c to the tarball
Collin Funk [Sun, 22 Jun 2025 05:05:19 +0000 (22:05 -0700)] 
build: add src/termios.c to the tarball

* src/local.mk (EXTRA_DIST): Add src/termios.c.

6 weeks agomaint: use _GL_CMP instead of handwriting three-valued comparisons
Collin Funk [Sun, 22 Jun 2025 04:50:27 +0000 (21:50 -0700)] 
maint: use _GL_CMP instead of handwriting three-valued comparisons

* src/comm.c (compare_files): Use _GL_CMP.
* src/join.c (keycmp): Likewise.
* src/ls.c (off_cmp): Likewise.
* src/ptx.c (compare_words, compare_occurs): Likewise.
* src/set-fields.c (compare_ranges): Likewise.
* src/sort.c (compare_random, diff_reversed, compare): Likewise.

7 weeks agodoc: NEWS: improve recent stty details
H. Peter Anvin [Sat, 21 Jun 2025 01:01:58 +0000 (18:01 -0700)] 
doc: NEWS: improve recent stty details

* src/NEWS: Fix grammar error,
and indicate baud rate probing is opportunistic.

7 weeks agotty: translate new error
Pádraig Brady [Sat, 21 Jun 2025 09:59:46 +0000 (10:59 +0100)] 
tty: translate new error

* src/tty.c (main): Translate and adjust new ttyname() error
diagnostic, to be clearer and avoid a syntax check failure.

7 weeks agotty: better fix for Bug#26371
Paul Eggert [Fri, 20 Jun 2025 18:53:21 +0000 (11:53 -0700)] 
tty: better fix for Bug#26371

* src/tty.c (TTY_USAGE): Rename from TTY_FAILURE, since this
is used only for usage failures.  All uses changed.
(TTY_TTYNAME_FAILURE): New constant.
(main): Remove no-longer-needed assignment of ENOENT to errno.
Make status-setting clearer too.
Report an error if ttyname fails even though stdin is a terminal,
instead of silently pretending that stdin is not a terminal.
* tests/tty/tty.sh: Test for this issue.  This should fix Bug#78244.

7 weeks agotests: stty: adjust tests for arbitary speeds
Pádraig Brady [Tue, 17 Jun 2025 22:32:05 +0000 (23:32 +0100)] 
tests: stty: adjust tests for arbitary speeds

* tests/stty/stty-invalid.sh: Adjust to what is now invalid.
* tests/stty/stty.sh: Add checks for valid speed variants.
* tests/stty/bad-speed.sh: New test to ensure unsupported speeds
are diagnosed.

7 weeks agostty: arbitrary or non-a priori known speed_t support
H. Peter Anvin [Mon, 16 Jun 2025 21:58:01 +0000 (14:58 -0700)] 
stty: arbitrary or non-a priori known speed_t support

Support the case where speed_t is simply a number, and in that case
assume that arbitrary values can be passed.  This is assumed to be the
case when all known speed_t macros equal their own value.

Try to probe for a variety of speed_t constants by trying to coax
$(CC) into emitting macro definitions (-E -dM).  If this is not
supported, use a fairly extensive list of constants as a
fallback.  This both improves the test for arbitrary speed support, as
well as allowing proper operation in the case where the constants are
not plain numbers and allows for handing enumerated speed constants
that were not known a priori when the source code was written.

A simple shell script (mostly using sed) is used to turn the list of
constants (probed and predefined) into a pair of conversion functions,
baud_to_value() and value_to_baud(); string_to_baud() is then
reimplemented as a wrapper around the latter.

* src/.gitignore: Add generated speedlist.h.
* src/local.mk: Generate speedlist.h.
* src/speedgen: Portable shell script to generate speedlist.h.
* src/stty.c: Adjust string_to_baud to
convert from arbitrary numeric values.
* src/termios.c: A helper used when generating speedlist.h
* NEWS: Mention the improvement.

8 weeks agodate: port test to NetBSD 10
Paul Eggert [Tue, 10 Jun 2025 19:51:05 +0000 (12:51 -0700)] 
date: port test to NetBSD 10

Problem reported by Collin Funk in:
https://lists.gnu.org/r/bug-gnulib/2025-06/msg00094.html
* tests/date/date-debug.sh: Also allow NetBSD 10 mktime behavior.
Although NetBSD contradicts POSIX, POSIX is likely wrong here and
I vaguely recall that there’s a POSIX correction in progress
that will allow the NetBSD behavior.

2 months agobuild: update gnulib submodule to latest
Paul Eggert [Mon, 9 Jun 2025 06:52:51 +0000 (23:52 -0700)] 
build: update gnulib submodule to latest

* tests/date/date-debug.sh: Update to match current behavior
of Gnulib's parse-datetime module.

2 months agodoc: cp --help: mention --reflink=auto is now the default
Pádraig Brady [Sat, 7 Jun 2025 13:27:59 +0000 (14:27 +0100)] 
doc: cp --help: mention --reflink=auto is now the default

* src/cp.c (usage): Reword the REFLINK description to
indicate that --reflink=auto is the default.
Fixes https://github.com/coreutils/coreutils/issues/103

2 months agodoc: make command synopsis more consistent
Pádraig Brady [Tue, 3 Jun 2025 21:58:38 +0000 (22:58 +0100)] 
doc: make command synopsis more consistent

* doc/coreutils.texi: Use @dots{} after [OPTION],
to be consistent with man pages.
* src/printenv.c (Usage): Remove unneeded "...".
* src/timeout.c (Usage): Add needed "...",
and also remove redundant [OPTION] only form.
* src/chroot.c (Usage): Likewise.
Fixes https://bugs.gnu.org/78628

2 months agocksum: port to Apple LLVM version 10.0.0
Paul Eggert [Thu, 29 May 2025 15:30:13 +0000 (08:30 -0700)] 
cksum: port to Apple LLVM version 10.0.0

This compiler lacks support for the x86-64 VPCLMULQDQ instruction;
compiles fail with "error: invalid cpu feature string for builtin".
Problem reported by Peter Dyballa, and fix suggested by
Pádraig Brady <https://bugs.gnu.org/78562#8>.
* configure.ac (USE_AVX512_CRC32):
Also check that __builtin_cpu_supports ("vpclmulqdq") compiles.

2 months agotests: sort: expand multiple output testing
Pádraig Brady [Wed, 28 May 2025 19:48:31 +0000 (20:48 +0100)] 
tests: sort: expand multiple output testing

* tests/sort/sort.pl: Ensure duplicate
output strings are supported.

2 months agomaint: assume O_DIRECTORY
Paul Eggert [Wed, 28 May 2025 19:35:14 +0000 (12:35 -0700)] 
maint: assume O_DIRECTORY

Recent changes in Gnulib guarantee O_DIRECTORY != 0.
* gl/lib/targetdir.c (target_directory_operand):
* src/dd.c (usage):
* src/ln.c (main):
Simplify now that O_DIRECTORY must be nonzero.

2 months agobuild: update gnulib submodule to latest
Paul Eggert [Wed, 28 May 2025 19:35:14 +0000 (12:35 -0700)] 
build: update gnulib submodule to latest

2 months agomaint: avoid a sc_system_h_headers failure
Pádraig Brady [Sat, 24 May 2025 21:01:44 +0000 (22:01 +0100)] 
maint: avoid a sc_system_h_headers failure

* cfg.mk: Also exclude libstdbuf.c from this check.

2 months agostdbuf: don’t allocate more than SIZE_MAX / 2
Paul Eggert [Sat, 24 May 2025 20:01:31 +0000 (13:01 -0700)] 
stdbuf: don’t allocate more than SIZE_MAX / 2

* src/libstdbuf.c (apply_mode): Be more conservative about
sizes passed to malloc, since we can’t rely on Gnulib malloc.