Paul Eggert [Fri, 14 Nov 2025 23:29:09 +0000 (15:29 -0800)]
openat2: port to O_DIRECTORY before O_NOFOLLOW
* lib/openat2.c (do_openat2): Don’t assume that openat (...,
"symlink", O_DIRECTORY | O_NOFOLLOW | ...) will fail with ELOOP.
The O_DIRECTORY check might be done first, so it might fail with
ENOTDIR. Problem discovered on Solaris 10.
* tests/test-openat2.c (do_prepare_symlinks, do_test_resolve)
(do_test_basic): Test for the portability bug.
Bruno Haible [Thu, 13 Nov 2025 10:29:16 +0000 (11:29 +0100)]
file-remote: Tweaks.
* lib/file-remote.c (file_is_remote): On Haiku, avoid an incorrectly
documented system function. Demonstrate a slow fallback code for unknown
platforms.
do-release-commit-and-tag: Accommodate alternative NEWS formats.
* build-aux/do-release-commit-and-tag: Introduce new options
parametrizing the NEWS file name, and its noteworthy_stub location
and contents. Avoid unconditional strftime in inner Perl loop.
(help): Describe the new options.
maintainer-makefile: Accommodate alternative NEWS formats.
* top/maint.mk (gl_noteworthy_news_): Make overridable.
(news-check-regexp-prev, NEWS_file, release_commit_args): New
overridable variables.
(NEWS_hash, sc_immutable_NEWS, update-NEWS-hash, news-check)
(announcement, release-commit, emit-commit-log): Use them.
(release-prep): Ditto. Search for news-check-regexp within
news-check-lines-spec instead of hard-coding line 3.
* top/maint.mk (update-NEWS-hash): Use AM_V_GEN.
(gpgv): Detect gpgv2 via 'command -v'; calling it directly results
in several 'gpgv2: command not found' messages.
Bruno Haible [Mon, 10 Nov 2025 09:28:28 +0000 (10:28 +0100)]
posix_spawnp tests: Add test against previous bug.
* tests/test-posix_spawnp-vfork.c: New file, based on
tests/test-posix_spawnp-script.c.
* modules/posix_spawnp-tests (Files): Add it.
(Makefile.am): Arrange to compile and test test-posix_spawnp-vfork.
Paul Eggert [Sat, 8 Nov 2025 20:45:49 +0000 (12:45 -0800)]
gendocs: port better to texi2html 5.0
Problem reported by Sergey Poznyakoff in:
https://lists.gnu.org/archive/html/bug-gnulib/2021-03/msg00002.html
* build-aux/gendocs.sh (html_split): Do not create symlink
from index.html to ${PACKAGE}.html if the former exists
or the latter does not.
Collin Funk [Fri, 7 Nov 2025 05:18:12 +0000 (21:18 -0800)]
renameat, renameatu: Work around GNU/Hurd bugs.
* lib/renameatu.c (renameatu): Handle RENAME_TRAILING_SLASH_SOURCE_BUG
and RENAME_TRAILING_SLASH_DEST_BUG when renameat2 is called.
* doc/glibc-functions/renameat2.texi: Mention the bugs.
* doc/posix-functions/renameat.texi: Likewise.
Paul Eggert [Fri, 7 Nov 2025 06:38:55 +0000 (22:38 -0800)]
stdcountof-h: allow compound literal args
* lib/stdcountof.in.h (countof, _gl_verify_is_array):
Allow arguments that are compound literals, and thus
appear as multiple arguments to a C macro.
* tests/test-stdcountof-h.c: Test for this.
Paul Eggert [Thu, 6 Nov 2025 22:32:10 +0000 (14:32 -0800)]
stdio-windows: fix <stdarg.h> include position
Problem reported by Andy Moreton in:
https://lists.gnu.org/r/bug-gnulib/2025-11/msg00059.html
* lib/stdio-consolesafe.c [__MINGW32__ && __USE_MINGW_ANSI_STDIO]:
Include <stdarg.h> even if HAVE_VASPRINTF
Collin Funk [Wed, 5 Nov 2025 03:56:18 +0000 (19:56 -0800)]
nproc: Fix compilation error with Android API ≤ 20.
Reported by Po Lu in
<https://lists.gnu.org/archive/html/bug-gnulib/2025-11/msg00027.html>.
* lib/nproc.c (cgroup2_mount): Don't assume we have setmntent if we have
mntent.h.
* m4/nproc.m4 (gl_PREREQ_NPROC): Check if setmntent is supported by the
current Android API.
Paul Eggert [Tue, 4 Nov 2025 16:10:49 +0000 (08:10 -0800)]
time_rz: tzfree now preserves errno
This is consistent with bleeding-edge TZDB and with POSIX 'free'.
* lib/time.in.h (tzfree) [!HAVE_TZALLOC]: Replace tzfree.
I suspect Android and NetBSD (the major implementations) don’t
always preserve errno, and it’s easier to replace tzfree everywhere.
* lib/time_rz.c: Always include errno.h.
(tzfree) [HAVE_TZALLOC]: New replacement function.
(set_tz): Do not bother to save and restore errno,
now that tzfree preserves errno.
* modules/time_rz (Depends-on): Add free-posix.
(configure.ac, Makefile.am): Always compile time_rz.c.
Paul Eggert [Mon, 3 Nov 2025 05:05:04 +0000 (21:05 -0800)]
fchmodat: don’t depend on openat
* modules/fchmodat (Depends-on): Remove openat. Even though
fchmodat.c calls openat, that call is used only on platforms
that do not need anything that the openat module supplies.
Removing the unnecessary dependency simplifies GNU Emacs.
Lukáš Zaoral [Thu, 23 Oct 2025 07:16:52 +0000 (09:16 +0200)]
fts: Introduce the FTS_MOUNT flag.
This mimics behaviour of the FTW_MOUNT flag described in nftw(3) which
implements the behaviour of find(1) -mount primary standardized by
POSIX.1-2024.
* lib/fts.in.h (FTS_MOUNT): New flag.
(FTS_OPTIONMASK): Adjust.
(FTS_NAMEONLY): Adjust.
(FTS_STOP): Adjust.
* lib/fts.c (fts_read): Implement FTS_MOUNT.
(fts_build): Do not skip stat(2) when FTS_MOUNT as set.
Pádraig Brady [Sat, 18 Oct 2025 20:47:52 +0000 (21:47 +0100)]
doc: mcel: give more detail on error interface
* lib/mcel.h: Mention that errors may be given on
some systems even with the "C" locale, as mcel
has explicitly disabled the workaround for:
https://sourceware.org/PR29511
Also state that len is set to 1 on any error.
Paul Eggert [Sun, 2 Nov 2025 00:45:12 +0000 (18:45 -0600)]
nstrftime: do not return PTRDIFF_MAX
Previously, nstrftime (NULL, SIZE_MAX, ...) could return
PTRDIFF_MAX, which would cause problems in the common case
where the caller adds 1 to the result in order to allocate.
To avoid this, arrange for nstrftime to return at most PTRDIFF_MAX - 1.
* lib/strftime.c (__strftime_internal) [FAILURE && !FPRINTFTIME]:
Silently ceiling MAXSIZE to PTRDIFF_MAX.
* lib/strftime.c (SBYTE_COUNT_MAX): Remove.
(incr_overflow): New macro.
(width_add): Use it.
(__strftime_internal): Omit no-longer-needed local.
Fail If the width overflows rather than substituting
SBYTE_COUNT_MAX, as the latter approach is unreliable.
Paul Eggert [Sat, 1 Nov 2025 16:54:55 +0000 (10:54 -0600)]
nstrftime: do not preserve errno on success
* NEWS: Mention this, and coalesce recent changes for the
benefit of future readers.
* lib/strftime.c (__strftime_internal):
Preserve errno only if FAILURE == 0,
for consistency with other functions returning -1 on failure.
Bruno Haible [Sat, 1 Nov 2025 13:17:10 +0000 (14:17 +0100)]
openat2 tests: Avoid test failure on native Windows.
* tests/test-openat2.c (do_prepare_symlinks): New function, extracted
from do_prepare.
(main): Invoke it before do_test_resolve, do_test_basic. Disable these
tests on native Windows.
Paul Eggert [Sat, 1 Nov 2025 04:22:50 +0000 (22:22 -0600)]
fprintftime: return negative on output error
* lib/strftime.c (FPUTC) [FPRINTFTIME]:
New macro. All uses of fputc changed to FPUTC.
(width_cpy) [FPRINTFTIME]: Do not ignore fwrite failure.
(fwrite_lowcase, fwrite_uppcase) [FPRINTFTIME]:
Remove. All uses replaced with inline code.
Bruno Haible [Fri, 31 Oct 2025 22:54:37 +0000 (23:54 +0100)]
posix_spawn_file_actions_addclose: Ignore test failure on NetBSD 10.0.
Based on comments by Collin Funk and Grisha Levit.
* m4/posix_spawn.m4 (gl_FUNC_POSIX_SPAWN_FILE_ACTIONS_ADDCLOSE): Revert
last change.
* tests/test-posix_spawn_file_actions_addclose.c (main): Treat NetBSD
like musl and Cygwin.
* doc/posix-functions/posix_spawn_file_actions_addclose.texi: Document
the large fd bug as "not fixed".
Paul Eggert [Fri, 31 Oct 2025 00:04:48 +0000 (18:04 -0600)]
fprintftime: sbyte_count_t to fix some overflows
* lib/strftime.c: Include <stdint.h>, for PTRDIFF_MAX.
(byte_count_t): Now a typedef instead of a macro.
(sbyte_count_t): New typedef.
(SBYTE_COUNT_MAX): New macro.
(memset_byte, width_add, __strftime_internal):
(fwrite_lowcase, fwrite_uppcase) [FPRINTFTIME]:
Avoid overflow issues with fprintftime by using byte_count_t
or sbyte_count_t instead of size_t or int.
* modules/nstrftime: Depend on stdint-h.
Bruno Haible [Thu, 30 Oct 2025 11:56:21 +0000 (12:56 +0100)]
fprintftime: Avoid size_t overflow for very large outputs.
Reported by Jeff Epler <jepler@unpythonic.net> in
<https://lists.gnu.org/archive/html/bug-gnulib/2025-10/msg00126.html>.
* lib/fprintftime.h: Include <sys/types.h>.
(fprintftime): Change return type to off64_t.
* lib/strftime.c (byte_count_t): New macro.
(my_strftime, __strftime_internal): Change return type to off64_t.
* modules/fprintftime (Depends-on): Add sys_types-h.
* NEWS: Mention the change.
Paul Eggert [Wed, 29 Oct 2025 04:15:11 +0000 (21:15 -0700)]
openat2: port O_TMPFILE check to non-GNU/Linux
* lib/openat2.c (openat2): Don’t assume !!(O_TMPFILE & O_DIRECTORY).
Although true on GNU/Linux, it is a hack and might not be true on
other systems such as Cygwin.
Paul Eggert [Wed, 29 Oct 2025 00:03:28 +0000 (17:03 -0700)]
openat2-tests: port to FreeBSD, NetBSD
Problem reported by Bruno Haible in:
https://lists.gnu.org/r/bug-gnulib/2025-10/msg00117.html
* tests/test-openat2.c (is_nofollow_error): New function.
(do_test_resolve): Use it.
Bruno Haible [Tue, 28 Oct 2025 21:11:11 +0000 (22:11 +0100)]
posix_spawn_file_actions_addclose: Fix test failure on NetBSD 10.0.
* m4/posix_spawn.m4 (gl_FUNC_POSIX_SPAWN_FILE_ACTIONS_ADDCLOSE): Test
also against the NetBSD bug.
* doc/posix-functions/posix_spawn_file_actions_addclose.texi: Document
the NetBSD bug.
Paul Eggert [Tue, 28 Oct 2025 00:00:53 +0000 (17:00 -0700)]
openat2: new module
This supports the openat2 system call of Linux 5.6 (2020) and
later. Although not yet exposed by glibc, the call is useful for
programs like GNU Tar that need to be paranoid about traversing
file names from untrusted sources. On platforms lacking
openat2, it is emulated in user space.
* lib/openat2.c, m4/openat2.m4, modules/openat2:
* modules/openat2-tests, tests/test-openat2.c: New files.
* lib/fcntl.in.h (struct open_how, RESOLVE_NO_XDEV)
(RESOLVE_NO_MAGICLINKS, RESOLVE_NO_SYMLINKS, RESOLVE_BENEATH)
(RESOLVE_IN_ROOT, RESOLVE_CACHED):
New type and constants, if <linux/openat2.h> does not define.
(openat2): New decls.
* m4/fcntl_h.m4 (gl_FCNTL_H, gl_FCNTL_H_REQUIRE_DEFAULTS)
(gl_FCNTL_H_DEFAULTS):
* modules/fcntl-h (fcntl.h):
Also check for openat2.
Paul Eggert [Mon, 27 Oct 2025 20:38:08 +0000 (13:38 -0700)]
stdcountof-tests: pacify ODS 12.6
* tests/test-stdcountof-h.c (test_func) [__SUNPRO_C]: Omit tests
involving u"xxx" and u8"...", as Oracle Developer Studio 12.6
lacks support for this despite claiming C11 conformance.
(a, b, c) [__SUNPRO_C]: Define; ODS 12.6 has the same bug as MSVC 14.
Paul Eggert [Fri, 24 Oct 2025 06:35:36 +0000 (23:35 -0700)]
doc: mention -fsanitize-trap=all etc
* doc/gnulib-readme.texi: Mention _GLIBCXX_ASSERTIONS,
-fsanitize-trap=all, -fhardened.
Problem reported by Basil L. Contovounesios in:
https://lists.gnu.org/r/bug-gnulib/2025-10/msg00068.html
Bruno Haible [Thu, 23 Oct 2025 14:14:15 +0000 (16:14 +0200)]
stdioext: Add support for OpenBSD >= 7.8.
* lib/stdio-impl.h (fp_): Separate definitions for OpenBSD from those
for Android. Add definition for OpenBSD >= 7.8.
* lib/fflush.c (clear_ungetc_buffer, disable_seek_optimization,
update_fpos_cache, rpl_fflush): Don't test for __OpenBSD__, since
OpenBSD <= 7.7 is covered by the __sferror test and OpenBSD >= 7.8 does
not need the workarounds.
* lib/fseeko.c (fseeko): Likewise.
* lib/fpurge.c (fpurge): Likewise.
Bruno Haible [Thu, 23 Oct 2025 14:06:22 +0000 (16:06 +0200)]
stdioext: Revert unneeded changes in 2025-07-20 commit.
* lib/fpending.c (__fpending): Don't test for __OpenBSD__, since
OpenBSD >= 7.6 already has __fpending.
* lib/freadahead.c (freadahead): Don't test for __OpenBSD__, since
OpenBSD >= 7.6 already has __freadahead.
* lib/freading.c (freading): Don't test for __OpenBSD__, since
OpenBSD >= 7.6 already has __freading.
* lib/freadptr.c (freadptr): Don't test for __OpenBSD__, since
OpenBSD >= 7.6 already has __freadptr.
* lib/freadseek.c (freadptrinc): Don't test for __OpenBSD__, since
OpenBSD >= 7.6 already has __freadptrinc.
* lib/fseterr.c (fseterr): Don't test for __OpenBSD__, since
OpenBSD >= 7.6 already has __fseterr.
* lib/fwriting.c (fwriting): Don't test for __OpenBSD__, since
OpenBSD >= 7.6 already has __fwriting.
Collin Funk [Tue, 21 Oct 2025 03:50:21 +0000 (20:50 -0700)]
fenv-rounding tests: Avoid test failure on Android.
* tests/test-fenv-round.c (test_towardzero, test_upward)
(test_downward): Disable tests that are known to fail.
* doc/posix-functions/fesetround.texi: Update list of platforms.
Bruno Haible [Mon, 20 Oct 2025 19:13:39 +0000 (21:13 +0200)]
glob: Add support for Android.
Reported by Collin Funk in
<https://lists.gnu.org/archive/html/bug-gnulib/2025-10/msg00054.html>.
* m4/glob.m4 (gl_GLOB): On Android, skip a test that assumes that
/bin/sh exists. Update cross-compilation guess.
* tests/test-glob.c (main): On Android, skip a test that assumes that
/bin/sh exists.
* doc/posix-functions/glob.texi: Mention also Android.
Collin Funk [Sat, 11 Oct 2025 05:34:19 +0000 (22:34 -0700)]
glob: Prevent a stack overflow with many slashes.
* lib/glob.c (__glob): Strip trailing slashes before making the
recursive call.
* m4/glob.m4 (gl_GLOB): Check for the glibc bug.
* doc/posix-functions/glob.texi: Mention the bug.
Bruno Haible [Mon, 13 Oct 2025 10:41:39 +0000 (12:41 +0200)]
getline: Fix compilation error in C++ mode (regression 2025-10-10).
* lib/stdio.in.h (getdelim): On glibc, define __getdelim instead of
rpl_getdelim.
(getline): In C++ mode, define getline as an inline function instead of
as a macro.
* lib/getdelim.c (getdelim): On glibc, don't test whether fp is NULL.
Collin Funk [Fri, 10 Oct 2025 03:41:09 +0000 (20:41 -0700)]
getline: Work around a glibc bug.
* m4/getline.m4 (gl_FUNC_GETLINE): Check that the buffer is terminated
with a NUL character when the first character read is EOF. Guess that
the function does not work on glibc.
* doc/posix-functions/getline.texi: Mention the bug.
Collin Funk [Fri, 10 Oct 2025 03:36:15 +0000 (20:36 -0700)]
getdelim: Work around a glibc bug.
* m4/getdelim.m4 (gl_FUNC_GETDELIM): Check that the buffer is terminated
with a NUL character when the first character read is EOF. Guess that
the function does not work on glibc.
* doc/posix-functions/getdelim.texi: Mention the bug.
Bruno Haible [Fri, 3 Oct 2025 19:51:11 +0000 (21:51 +0200)]
unimetadata/base: Add tests.
* tests/unimetadata/test-unimetadata-h.c: New file.
* modules/unimetadata/base-tests: New file.
* tests/unimetadata/test-unimetadata-h-c++.cc: New file.
* modules/unimetadata/base-c++-tests: New file.
Bruno Haible [Fri, 3 Oct 2025 19:51:08 +0000 (21:51 +0200)]
unicase/base: Add tests.
* tests/unicase/test-unicase-h.c: New file.
* modules/unicase/base-tests: New file.
* tests/unicase/test-unicase-h-c++.cc: New file.
* modules/unicase/base-c++-tests: New file.
Bruno Haible [Fri, 3 Oct 2025 19:51:05 +0000 (21:51 +0200)]
uninorm/base: Add tests.
* tests/uninorm/test-uninorm-h.c: New file.
* modules/uninorm/base-tests: New file.
* tests/uninorm/test-uninorm-h-c++.cc: New file.
* modules/uninorm/base-c++-tests: New file.
Bruno Haible [Fri, 3 Oct 2025 19:51:01 +0000 (21:51 +0200)]
unilbrk/base: Add tests.
* tests/unilbrk/test-unilbrk-h.c: New file.
* modules/unilbrk/base-tests: New file.
* tests/unilbrk/test-unilbrk-h-c++.cc: New file.
* modules/unilbrk/base-c++-tests: New file.