Bruno Haible [Tue, 9 Sep 2025 10:42:04 +0000 (12:42 +0200)]
fsusage: Remove support for OSF/1.
* lib/fsusage.c (get_fs_usage): Remove code for STAT_STATFS3_OSF1.
* m4/fsusage.m4 (gl_FILE_SYSTEM_USAGE): Remove test for for 3-argument
statfs function.
Paul Eggert [Sun, 7 Sep 2025 23:34:43 +0000 (16:34 -0700)]
maint: allow false/true in C macros
* top/maint.mk (sc_Wundef_boolean): Allow false and true in C
macro definiens. C23 requires support for false and true, and the
‘bool’ module makes it easy to support this in older compilers.
crypto/sha3-buffer, crypto/sha3: Protect against double frees (regr. today).
* lib/sha3.c (sha3_free_ctx): Only free the EVP_MD_CTX if it is not
NULL, and set it to NULL after freeing.
(DEFINE_SHA3_INIT_CTX, sha3_finish_ctx, sha3_process_bytes): Leave
freeing memory to the caller.
* lib/sha3-stream.c (sha3_xxx_stream): Call sha3_free_ctx on success and
if sha3_init_ctx fails.
* tests/test-sha3-224-buffer.c (main): Add a test that would otherwise
segfault without this patch.
* tests/test-sha3-256-buffer.c (main): Likewise.
* tests/test-sha3-384-buffer.c (main): Likewise.
* tests/test-sha3-512-buffer.c (main): Likewise.
crypto/sha3-buffer: Set errno when OpenSSL functions fail.
* lib/sha3.c: Include <errno.h>
(DEFINE_SHA3_INIT_CTX): Set errno to ENOMEM if function fails.
(sha3_finish_ctx, sha3_process_block): Set errno to EINVAL on failure.
crypto/sha3, crypto/sha3-buffer: Don't leak memory when using OpenSSL.
Reported by Pádraig Brady in:
<https://lists.gnu.org/archive/html/bug-gnulib/2025-09/msg00058.html>.
* lib/sha3.c (DEFINE_SHA3_INIT_CTX) [!HAVE_OPENSSL_SHA3]: Always return
true.
[HAVE_OPENSSL_SHA3]: Call EVP_MD_CTX_create to allocate an EVP_MD_CTX.
(DEFINE_SHA3_BUFFER, sha3_process_bytes, sha3_process_block)
[!HAVE_OPENSSL_SHA3]: Always return true.
[HAVE_OPENSSL_SHA3]: Return NULL if any function calls fail.
(sha3_finish_ctx) [HAVE_OPENSSL_SHA3]: Free memory allocated by
EV_MD_CTX_create.
(sha3_free_ctx): New function.
* lib/sha3.h (struct sha3_ctx): Use a heap allocated EVP_MD_CTX.
(sha3_224_init_ctx, sha3_256_init_ctx, sha3_384_init_ctx)
(sha3_512_init_ctx, sha3_process_block, sha3_process_bytes): Change
prototype to return a bool. Mention that they return false if an OpenSSL
function fails.
(sha3_finish_ctx, sha3_read_ctx, sha3_224_buffer, sha3_256_buffer)
(sha3_384_buffer, sha3_512_buffer): Mention that these functions return
NULL if an OpenSSL function fails.
(sha3_free_ctx): New function.
* lib/sha3-stream.c (sha3_xxx_stream): Expect a function parameter that
returns bool. Check the return values of the sha3 functions, cleaning up
memory on failure.
* modules/crypto/sha3-buffer: Add bool.
Paul Eggert [Fri, 5 Sep 2025 22:18:31 +0000 (15:18 -0700)]
dfa, propername-lite, quotearg: prefer mbszero
Problem reported by Collin Funk in:
https://lists.gnu.org/r/bug-gnulib/2025-09/msg00063.html
* lib/dfa.c (mbszero) [GAWK]: Omit unnecessary parens.
* lib/localeinfo.c (mbszero) [GAWK]: New macro, copied from dfa.c.
(is_using_utf8, init_localeinfo): Use it.
* lib/propername-lite.c (proper_name_lite):
* lib/quotearg.c (gettext_quote):
Prefer mbszero to initializing the entire mbstate_t.
Paul Eggert [Fri, 5 Sep 2025 20:54:08 +0000 (13:54 -0700)]
unlocked-io: also deal with fileno
This shouldn’t affect performance on glibc, where fileno and
fileno_unlocked are aliases under the theory that no locking is needed.
However, it might help a bit on platforms like FreeBSD where
fileno_unlocked is inline and does not lock.
* lib/unlocked-io.h (fileno, fileno_unlocked):
Define as needed, similarly to fgets etc.
* m4/unlocked-io.m4 (gl_FUNC_GLIBC_UNLOCKED_IO):
Also check fileno_unlocked.
Paul Eggert [Fri, 5 Sep 2025 20:04:09 +0000 (13:04 -0700)]
progname: static check instead of dynamic
* lib/progname.c: Don’t include stdio.h or stdlib.h.
(set_program_name): Omit dynamic check that (with current glibc
optimization) drags in fwrite even when unlocked I/O is wanted.
The check was not all that useful in practice and we now have a
static one anyway (which admittedly is not that useful either).
Prefer memcmp to strncmp when equivalent, for clarity.
* lib/progname.h: Include arg-nonnull.h and declare
set_program_name with _GL_ARG_NONNULL.
* modules/progname (Depends-on): Add snippet/arg-nonnull.
Paul Eggert [Fri, 5 Sep 2025 07:15:38 +0000 (00:15 -0700)]
propername-lite: lighten it up some more
This should help GNU diffutils avoid some Gnulib modules.
* lib/propername-lite.c: Do not include c-strcase.h, localcharset.h.
Include <uchar.h> and mbrtowc32 if available.
Use __has_include to detect this; that should be good enough nowadays.
Use native mbrtoc32 instead of Gnulib replacement; that should
be good enough. 2nd arg is now possibly unused.
Use mbrtoc32, if available, to determine whether UTF-8 is being used,
to avoid dependencies.
* modules/propername-lite (Depends-on):
Remove localcharset, c-strcasecmp.
Paul Eggert [Fri, 5 Sep 2025 04:18:30 +0000 (21:18 -0700)]
quotearg: do not depend on localcharset
* lib/quotearg.c: Do not include localcharset.h.
(gettext_quote): Do not use locale_charset; instead, use
mbrtoc32 to determine whether the character set uses UTF-8.
Treat GB-18030 like similar encodings, as it is not worth the
trouble of special-casing: its special-case code has been broken
since 2011, nobody cared enough to report the bug, and the idea
that someone would use GB-18030 without translations is weird anyway.
* modules/quotearg (Depends-on): Remove localcharset.
Bruno Haible [Thu, 4 Sep 2025 20:52:44 +0000 (22:52 +0200)]
gnulib-tool: Improve changes from yesterday and today.
* gnulib-tool.sh (func_emit_tests_Makefile_am): Consider also the case
that --with-tests is specified and --makefile-name /
--tests-makefile-name are not specified. Simplify an initialization and
augmentation to an initialization.
* pygnulib/GLEmiter.py (GLEmiter.tests_Makefile_am): Likewise.
* modules/crypto/sha3-buffer (Depends-on): Add stddef-h.
* lib/sha3.h: Include stddef.h.
(sha3_ctx): Use a stack allocated buffer used to cast to store an
EVP_MD_CTX.
* lib/sha3.c (DEFINE_SHA3_INIT_CTX): Initialize the structure to zero.
Use the stack allocated buffer instead of calling EVP_MD_CTX_create.
(sha3_read_ctx): Just call sha3_finish_ctx similar to the other crypto
modules.
(sha3_finish_ctx): Remove call to EVP_MD_CTX_free. Call
EVP_DigestFinal_ex.
gnulib-tool: Avoid Automake error when using --create-testdir (regr. today).
* gnulib-tool.sh (func_emit_tests_Makefile_am): Initialize AM_CFLAGS and
AM_CXXFLAGS when creating a test directory.
* pygnulib/GLEmiter.py (GLEmiter.tests_Makefile_am): Likewise.
Bruno Haible [Wed, 3 Sep 2025 22:15:19 +0000 (00:15 +0200)]
gnulib-tool: In tests directories, augment AM_CFLAGS and AM_CXXFLAGS.
Reported by Pádraig Brady in
<https://lists.gnu.org/archive/html/bug-gnulib/2025-09/>.
* gnulib-tool.sh (func_emit_tests_Makefile_am): Append the
warning-protection options to AM_CFLAGS and AM_CXXFLAGS, in addition to
initializing CFLAGS and CXXFLAGS.
* pygnulib/GLEmiter.py (GLEmiter.tests_Makefile_am): Likewise.
* doc/gnulib-tool.texi (Modified build rules): Document the need to
initialize AM_CFLAGS and AM_CXXFLAGS in tests directories.
* NEWS: Mention the new requirement.
Bruno Haible [Wed, 3 Sep 2025 21:43:45 +0000 (23:43 +0200)]
gnulib-tool: Improve C++ awareness of 2021-06-10 / 2024-03-06 commit.
* gnulib-tool.sh (func_emit_lib_Makefile_am): If the file list contains
some C++ files, emit also an initialization for
${libname}_${libext}_CXXFLAGS.
(func_emit_tests_Makefile_am): If the file list contains no C++ files,
don't emit an initialization for CXXFLAGS.
* pygnulib/GLEmiter.py (GLEmiter.lib_Makefile_am): If the file list
contains some C++ files, emit also an initialization for
${libname}_${libext}_CXXFLAGS.
(GLEmiter.tests_Makefile_am): If the file list contains no C++ files,
don't emit an initialization for CXXFLAGS.
* lib/sha3.c (DEFINE_SHA3_INIT_CTX, sha3_read_ctx, sha3_finish_ctx)
(DEFINE_SHA3_BUFFER, sha3_process_bytes, sha3_process_block)
[HAVE_OPENSSL_SHA3]: Define these functions/macros using the OpenSSL EVP
API.
* lib/sha3.h [HAVE_OPENSSL_SHA3]: Include <openssl/evp.h>.
(struct sha3_ctx) [HAVE_OPENSSL_SHA3]: Only store a pointer to an
EVP_MD_CTX in the structure.
* m4/gl-openssl.m4 (gl_CRYPTO_CHECK): If the argument is SHA3 check for
EVP_sha3_224.
* m4/sha3.m4 (gl_SHA3): New file, based on m4/sha512.m4.
* modules/crypto/sha3-buffer (Files): Add m4/gl-openssl.m4 and
m4/sha3.m4.
(configure.ac): Invoke gl_SHA3. Remove gl_BIGENDIAN.
* modules/crypto/sha3-buffer-tests (Makefile.am): Link to @LIB_CRYPTO@.
Bruno Haible [Mon, 1 Sep 2025 22:12:43 +0000 (00:12 +0200)]
uchar-h: Fix compilation error of <cuchar> in C++ mode on macOS 15.
* lib/uchar.in.h: In C++ mode, use CXX_HAVE_UCHAR_H instead of
HAVE_UCHAR_H.
* m4/uchar_h.m4 (gl_UCHAR_H): Set CXX_HAVE_UCHAR_H.
* modules/uchar-h (Makefile.am): Substitute CXX_HAVE_UCHAR_H.
sys_types-h tests: Fix a static_assert failure on glibc/hppa.
* tests/test-sys_types-h.c [__GLIBC__ && __hppa]: Don't check that
blksize_t and blkcnt_t are signed.
* doc/posix-headers/sys_types.texi: Mention that these types are
unsigned on this platform.
sys_stat-h tests: Fix a static_assert failure on glibc/hppa.
Reported by Santiago Vila <sanvila@debian.org> in:
<https://lists.gnu.org/archive/html/bug-m4/2025-09/msg00000.html>.
* tests/test-sys_stat-h.c [__GLIBC__ && __hppa]: Don't check that
blksize_t and blkcnt_t are signed.
* doc/posix-headers/sys_stat.texi: Mention that these types are
unsigned on this platform.
Collin Funk [Sun, 31 Aug 2025 21:21:02 +0000 (14:21 -0700)]
crypto/sha3: New module.
* modules/crypto/sha3: New file.
* lib/sha3-stream.c: New file, based on sha512-stream.c.
* lib/sha3.h (sha3_224_stream, sha3_256_stream, sha3_384_stream)
(sha3_512_stream): New declarations.
Collin Funk [Sun, 31 Aug 2025 18:43:37 +0000 (11:43 -0700)]
crypto/sha3-buffer: New module.
* lib/u64.h (u64getlo, u64not): New functions.
* lib/sha3.c: New file, based on lib/sha512.c.
* lib/sha3.h: New file, based on lib/sha512.h.
* modules/crypto/sha3-buffer: New file.
Paul Eggert [Sun, 31 Aug 2025 14:54:18 +0000 (07:54 -0700)]
u64: avoid theoretical problem with >64-bit int
* lib/u64.h: Include limits.h, for INT_MAX. Use uint64_t only if
INT_MAX < UINT64_MAX, to avoid undefined behavior on theoretical
platforms where adding two uint64_t expressions can have undefined
behavior on signed integer overflow.
Bruno Haible [Tue, 19 Aug 2025 18:05:47 +0000 (20:05 +0200)]
doc: Update for glibc 2.42.
* doc/glibc-functions/uabs.texi: New file.
* doc/glibc-functions/ulabs.texi: New file.
* doc/glibc-functions/ullabs.texi: New file.
* doc/glibc-functions/uimaxabs.texi: New file.
* doc/gnulib.texi (Glibc inttypes.h): New section.
(Glibc stdlib.h): Include three of these files.
Pádraig Brady [Mon, 18 Aug 2025 14:34:59 +0000 (15:34 +0100)]
nproc: honor cgroupv2 CPU quotas
cgroupv1 CPU quotas are not considered,
as those are now legacy (RHEL7 era),
and are more complex/inefficient to parse.
Tested in coreutils on Fedora 42
as detailed in tests/test-nproc.c
* lib/nproc.c (cgroup2_mount): Identify the cgroup2 mount point,
first at the common location for efficiency,
resorting to searching mount points otherwise.
(get_cgroup2_cpu_quota): Walk cgroup2 quotas for the current process,
returning the lowest integer number of CPUs configured.
(cpu_quota): On Linux return the cgroupv2 CPU quota if the
currrent scheduler honors it. Otherwise return ULONG_MAX.
(num_processors): Clamp the return to <= quota.
* m4/nproc.m4: Add a check for mntent.h.
* tests/test-nproc.c: Document how cgroup CPU quotas were tested.
Bruno Haible [Fri, 15 Aug 2025 12:42:07 +0000 (14:42 +0200)]
Reduce risk of compilation errors within include files.
* lib/dirent.in.h: Move include <sys/stat.h> near the end of the file.
* lib/stdlib.in.h: Move include <sys/wait.h> near the end of the file.
* lib/sys_select.in.h: Move include <string.h> near the end of the file.
* lib/unistd.in.h: Add comment.
Bruno Haible [Thu, 14 Aug 2025 16:36:00 +0000 (18:36 +0200)]
issymlink, issymlinkat: New modules.
* lib/sys_stat.in.h: Invoke _GL_INLINE_HEADER_BEGIN,
_GL_INLINE_HEADER_END. Include <errno.h>, <unistd.h>.
(_GL_ISSYMLINK_INLINE, _GL_ISSYMLINKAT_INLINE): New macros.
(issymlink, issymlinkat): New declarations.
* lib/unistd.in.h: Do the #include <fcntl.h>, when needed for O_CLOEXEC,
at the end of the file. So that when <fcntl.h> includes <sys/stat.h>,
the declarations of readlink() and readlinkat() on native Windows are
already present.
* lib/issymlink.c: New file.
* lib/issymlinkat.c: New file.
* m4/sys_stat_h.m4 (gl_SYS_STAT_H_REQUIRE_DEFAULTS): Initialize
GNULIB_ISSYMLINK, GNULIB_ISSYMLINKAT.
* modules/sys_stat-h (Depends-on): Add extern-inline.
(Makefile.am): Substitute GNULIB_ISSYMLINK, GNULIB_ISSYMLINKAT.
* modules/issymlink: New file.
* modules/issymlinkat: New file.
Paul Eggert [Tue, 12 Aug 2025 00:22:03 +0000 (17:22 -0700)]
Prefer readlink to lstat+S_ISLNK when easy
To test for a symlink, use readlink, not lstat+S_ISLNK,
when the lstat is used only for the symlink test.
This avoids EOVERFLOW issues.
* lib/lchown.c (rpl_lchown) [CHOWN_CHANGE_TIME_BUG]:
* lib/rename.c (rpl_rename):
[!(_WIN32 && !__CYGWIN__) && (RENAME_TRAILING_SLASH_SOURCE_BUG
|| RENAME_DEST_EXISTS_BUG || RENAME_HARD_LINK_BUG)]:
* lib/renameatu.c (renameatu):
[HAVE_RENAMEAT && RENAME_TRAILING_SLASH_SOURCE_BUG]:
* lib/unlink.c (rpl_unlink):
* lib/unlinkat.c (rpl_unlinkat):
* lib/utimens.c (lutimens) [!HAVE_LUTIMENS]:
Prefer readlink to lstat+S_ISLNK.
* modules/lchown, modules/rename, modules/unlink, modules/utimens:
(Depends-on): Add readlink.
* modules/unlinkat (Depends-on): Add fstatat, readlinkat.
Bruno Haible [Tue, 5 Aug 2025 21:16:15 +0000 (23:16 +0200)]
git-merge-changelog: Remove module.
It is now available through
$ git clone https://git.savannah.gnu.org/git/vc-changelog.git
see https://gitweb.git.savannah.gnu.org/gitweb/?p=vc-changelog.git .