Paul Eggert [Sun, 25 Dec 2022 19:41:57 +0000 (11:41 -0800)]
largefile: sync from Autoconf master
* m4/largefile.m4 (gl_SET_LARGEFILE_SOURCE): Test whether
AC_SYS_YEAR2038 is defined when this macro is defined, not when it
is used, as we now define AC_SYS_YEAR2038 later.
(_AC_SYS_LARGEFILE_MACRO_VALUE): Remove.
(_AC_SYS_YEAR2038_TEST_CODE, _AC_SYS_YEAR2038_OPTIONS)
(_AC_SYS_YEAR2038_PROBE, _AC_SYS_YEAR2038_ENABLE)
(_AC_SYS_YEAR2038_OPT_IN, AC_SYS_YEAR2038)
(_AC_SYS_LARGEFILE_TEST_CODE, _AC_SYS_LARGEFILE_OPTIONS)
(_AC_SYS_LARGEFILE_PROBE, _AC_SYS_LARGEFILE_ENABLE): New macros.
(AC_SYS_LARGEFILE): Use them.
* m4/year2038.m4: Remove. All mentions removed.
* modules/largefile, modules/year2038 (configure.ac-early):
Do not require gl_YEAR2038_EARLY.
* modules/year2038 (Depends-on): Depend on largefile.
(configure.ac): Require AC_SYS_YEAR2038, not gl_YEAR2038.
Paul Eggert [Tue, 9 Aug 2022 18:12:05 +0000 (11:12 -0700)]
largefile, year2038: simplify if Autoconf 2.72
* m4/largefile.m4 (gl_SET_LARGEFILE_SOURCE)
(_AC_SYS_LARGEFILE_MACRO_VALUE):
* m4/year2038.m4 (gl_YEAR2038_EARLY, gl_YEAR2038, gl_YEAR2038_BODY):
Adjust to Autoconf 2.72, which should contain the Gnulib
patches in this area and so should not need to be overridden.
Paul Eggert [Wed, 28 Dec 2022 22:15:43 +0000 (14:15 -0800)]
assert-h: port static_assert to strict C99
* lib/verify.h (_GL_VERIFY): Port MSVC hack back to C99.
Problem found when testing bleeding-edge gzip on IBM XL C for AIX,
V12.1 (5765-J02, 5725-C72), which complained ‘"malloca.c", line
42.56: 1506-041 (E) The invocation of macro _Static_assert
contains fewer arguments than are required by the macro
definition.’ This diagnostic is valid because C99 requires
that if you #define _Static_assert(R, ...) you must call
_Static_assert with at least two arguments. I found a similar
problem with Sun C 5.9 SunOS_sparc Patch 124867-12 2009/11/22.
Bruno Haible [Tue, 27 Dec 2022 10:21:45 +0000 (11:21 +0100)]
Fix compilation errors in C++ mode on Solaris 11 OpenIndiana.
* m4/gnulib-common.m4 (gl_COMMON_BODY): In _GL_ATTRIBUTE_DEALLOC_FREE,
with GNU C++, cast the 'free' function.
* lib/string.in.h (_GL_ATTRIBUTE_DEALLOC_FREE): With GNU C++, cast the
'free' function.
* lib/wchar.in.h (_GL_ATTRIBUTE_DEALLOC_FREE): Likewise.
Paul Eggert [Mon, 26 Dec 2022 18:17:17 +0000 (10:17 -0800)]
stdbool-c99: fix typo
Reported against Autoconf by Todd C. Miller in:
https://lists.gnu.org/r/autoconf/2022-12/msg00001.html
* m4/stdbool.m4 (AC_CHECK_HEADER_STDBOOL): Sync from Autoconf master.
Paul Eggert [Fri, 23 Dec 2022 05:19:34 +0000 (21:19 -0800)]
posix_spawnp-tests: fix filename typo
Problem reported for GNU m4 by Mitchell Dorrell in:
https://lists.gnu.org/r/bug-m4/2022-12/msg00000.html
* tests/test-posix_spawnp-script.c (DATA_FILENAME):
Fix typo in file name that caused race with
test-posix_spawn-script.c.
Bruno Haible [Mon, 17 Oct 2022 00:44:54 +0000 (02:44 +0200)]
getdelim: Work around buggy implementation on macOS 10.13.
* doc/posix-functions/getdelim.texi: Mention the macOS bug.
* m4/getdelim.m4 (gl_FUNC_GETDELIM): Let the "checking for working
getdelim function" test answer 'no' on macOS.
Paul Eggert [Mon, 26 Sep 2022 01:33:49 +0000 (18:33 -0700)]
fts: fix errno handling if dirfd fails
* lib/fts.c (fts_build): Use proper errno if dirfd failed.
Although I don’t know of any platform where dirfd can fail here,
we might as well get it right.
Bruno Haible [Sun, 18 Sep 2022 01:05:21 +0000 (03:05 +0200)]
wchar: Fix compilation errors in C++ mode on Solaris 11.3.
* lib/wchar.in.h (wcsnlen, wcpcpy, wcpncpy, wcscasecmp, wcsncasecmp,
wcsdup): Force declaration in C++ mode on Solaris (which does not
declare these functions in the global namespace).
Bruno Haible [Wed, 14 Sep 2022 22:50:41 +0000 (00:50 +0200)]
time: Fix compilation errors with clang/MSVC.
* m4/time_h.m4 (gl_TIME_H): Test whether asctime_r and ctime_r are
declared.
* lib/time.in.h (asctime_r, ctime_r): Skip _GL_WARN_ON_USE invocations
when these functions are not declared.
Bruno Haible [Sat, 10 Sep 2022 16:56:14 +0000 (18:56 +0200)]
uchar: Work around error in C++ mode on AIX 7.2 with xlclang.
* lib/uchar.in.h (char16_t, char32_t): On AIX with xlclang++, define
these as macros.
* doc/posix-headers/uchar.texi: Document the AIX + xlclang++ bug.
Bruno Haible [Sat, 10 Sep 2022 16:03:02 +0000 (18:03 +0200)]
math: Fix compilation error in C++ mode on AIX 7.2 with xlclang.
* lib/math.in.h (cbrtl, copysignl, exp2l, expm1l, fmal, ilogbl, log1pl,
log2l, logbl, remainderl, rintl, roundl, truncl): Enable the C++ alias
warning only on glibc systems.
Bruno Haible [Fri, 9 Sep 2022 14:49:10 +0000 (16:49 +0200)]
spawn-pipe: Fix pipe-filter-* test hangs (regression 2020-12-24).
* lib/windows-spawn.h (struct inheritable_handles): Widen the per-fd
flags from 8 bits to 16 bits.
(KEEP_OPEN_IN_CHILD): New macro.
(init_inheritable_handles): Change description of what it does when
duplicate == true.
* lib/windows-spawn.c (init_inheritable_handles): If duplicate == true,
add all fds to the array, regardless whether they are scheduled to be
preserved in the child process.
(compose_handles_block): Update.
(spawnpvech): Update.
* lib/spawni.c (grow_inheritable_handles): Update.
(shrink_inheritable_handles): Also close the handles not marked with
KEEP_OPEN_IN_CHILD.
(do_open, do_dup2): Mark the new fd with KEEP_OPEN_IN_CHILD.
Bruno Haible [Tue, 6 Sep 2022 13:09:41 +0000 (15:09 +0200)]
pipe-filter-gi tests: Fix long-standing failure on native Windows.
* tests/test-pipe-filter-gi2-main.c: Include binary-io.h.
(main): Avoid NL to CRLF conversion on standard output.
* tests/test-pipe-filter-gi2-child.c: Include <unistd.h>, binary-io.h.
(main): Avoid NL to CRLF conversion on standard output.
Bruno Haible [Wed, 7 Sep 2022 21:33:31 +0000 (23:33 +0200)]
posix_spawn_file_actions_addclose tests: Avoid test failure on musl.
Reported by Valery Ushakov <uwe@stderr.spb.ru> in
<https://lists.gnu.org/archive/html/bug-gnulib/2022-09/msg00041.html>.
* modules/posix_spawn_file_actions_addclose-tests (configure.ac): Invoke
gl_MUSL_LIBC.
* tests/test-posix_spawn_file_actions_addclose.c (main): Skip one of the
tests on musl libc.
Bruno Haible [Mon, 5 Sep 2022 19:54:10 +0000 (21:54 +0200)]
pthread-h: Fix compilation error on mingw with --enable-threads=windows.
* lib/pthread.in.h: In C++ mode, if mingw's <pthread.h> has not been
used, import many pthread_* symbols from the GNULIB_NAMESPACE into the
global namespace.
Bruno Haible [Sun, 4 Sep 2022 23:53:28 +0000 (01:53 +0200)]
Fix various test link errors on MSVC.
* modules/crypto/gc-arcfour-tests (Makefile.am): Link test-gc-arcfour
with $(LIB_GETRANDOM).
* modules/crypto/gc-arctwo-tests (Makefile.am): Link test-gc-arctwo with
$(LIB_GETRANDOM).
* modules/crypto/gc-des-tests (Makefile.am): Link test-gc-des with
$(LIB_GETRANDOM).
* modules/crypto/gc-hmac-md5-tests (Makefile.am): Link test-gc-hmac-md5
with $(LIB_GETRANDOM).
* modules/crypto/gc-hmac-sha1-tests (Makefile.am): Link
test-gc-hmac-sha1 with $(LIB_GETRANDOM).
* modules/crypto/gc-hmac-sha256-tests (Makefile.am): Link
test-gc-hmac-sha256 with $(LIB_GETRANDOM).
* modules/crypto/gc-hmac-sha512-tests (Makefile.am): Link
test-gc-hmac-sha512 with $(LIB_GETRANDOM).
* modules/crypto/gc-md2-tests (Makefile.am): Link test-gc-md2 with
$(LIB_GETRANDOM).
* modules/crypto/gc-md4-tests (Makefile.am): Link test-gc-md4 with
$(LIB_GETRANDOM).
* modules/crypto/gc-md5-tests (Makefile.am): Link test-gc-md5 with
$(LIB_GETRANDOM).
* modules/crypto/gc-pbkdf2-tests (Makefile.am): Link test-gc-pbkdf2 with
$(LIB_GETRANDOM).
* modules/crypto/gc-pbkdf2-sha1-tests (Makefile.am): Link
test-gc-pbkdf2-sha1 with $(LIB_GETRANDOM).
* modules/crypto/gc-rijndael-tests (Makefile.am): Link test-gc-rijndael
with $(LIB_GETRANDOM).
* modules/crypto/gc-sha1-tests (Makefile.am): Link test-gc-sha1 with
$(LIB_GETRANDOM).
* modules/crypto/gc-sha256-tests (Makefile.am): Link test-gc-sha256 with
$(LIB_GETRANDOM).
* modules/crypto/gc-sha512-tests (Makefile.am): Link test-gc-sha512 with
$(LIB_GETRANDOM).
* modules/crypto/gc-sm3-tests (Makefile.am): Link test-gc-sm3 with
$(LIB_GETRANDOM).
* modules/sys_stat-c++-tests (Makefile.am): Link test-sys_stat-c++ with
$(LIB_GETRANDOM).
* modules/unistd-c++-tests (Makefile.am): Link test-unistd-c++ with
$(LIB_GETRANDOM).
Bruno Haible [Sun, 4 Sep 2022 23:34:36 +0000 (01:34 +0200)]
count-leading-zeros: Fix a link error on 32-bit MSVC and a test failure.
* lib/count-leading-zeros.h: Correct syntax for #pragma intrinsic.
(COUNT_LEADING_ZEROS): Fix the return value.
(count_leading_zeros_ll): Use two _BitScanReverse invocations instead
of a _BitScanReverse64 invocation.
Bruno Haible [Sun, 4 Sep 2022 23:29:26 +0000 (01:29 +0200)]
count-trailing-zeros: Fix a link error on 32-bit MSVC.
* lib/count-trailing-zeros.h: Correct syntax for #pragma intrinsic.
(count_trailing_zeros_ll): Use two _BitScanForward invocations instead
of a _BitScanForward64 invocation.
Bruno Haible [Sun, 4 Sep 2022 15:09:53 +0000 (17:09 +0200)]
timespec_get: Fix compilation error with MSVC 14.
* m4/gettime.m4 (gl_CHECK_FUNC_TIMESPEC_GET): New macro.
(gl_GETTIME): Use it instead of AC_CHECK_FUNCS_ONCE.
* m4/timespec_get.m4 (gl_FUNC_TIMESPEC_GET): Likewise.
Bruno Haible [Sun, 4 Sep 2022 11:26:19 +0000 (13:26 +0200)]
nanosleep: Work around bug on newer 32-bit mingw.
* m4/nanosleep.m4 (gl_FUNC_NANOSLEEP): Test for 32-bit mingw bug.
* tests/test-nanosleep.c (main): Add another test.
* doc/posix-functions/nanosleep.texi: Mention the mingw bug.
Bruno Haible [Sun, 4 Sep 2022 00:52:14 +0000 (02:52 +0200)]
Fix a compilation error in C++ mode on Solaris 11.4.
* lib/uchar.in.h (c32rtomb): Enable the C++ alias warning only on
glibc ≥ 2.16 systems. Fix a GNULIB_POSIXCHECK mistake.
(mbrtoc32): Enable the C++ alias warning only on glibc ≥ 2.16 systems.
Bruno Haible [Sat, 3 Sep 2022 23:14:18 +0000 (01:14 +0200)]
Fix compilation errors of C++ tests on Solaris 10 with Sun C++.
* modules/string-c++-tests (Makefile.am): Link test-string-c++ with
$(LIBUNISTRING).
* modules/wchar-c++-tests (Makefile.am): Link test-wchar-c++ with
$(LIBUNISTRING).
Paul Eggert [Mon, 22 Aug 2022 20:43:18 +0000 (15:43 -0500)]
tempname: don't lose entropy in seed
* lib/tempname.c (random_bits): Don't lose entropy in S
in the rare case where where the template has more than 10 Xs.
From a suggestion by Bruno Haible in:
https://bugs.gnu.org/57129#149
Paul Eggert [Mon, 22 Aug 2022 19:07:27 +0000 (12:07 -0700)]
tempname: fix multithreading, ASLR leak etc.
Fix problems with tempname and multithreading, entropy loss,
and missing clock data (this last on non-GNU platforms).
See analysis by Bruno Haible in:
https://bugs.gnu.org/57129#149
While looking into this, I noticed that tempname can leak
info derived from ASLR into publicly-visible file names,
which is a no-no. Fix that too.
* lib/tempname.c: Don't include stdalign.h.
(HAS_CLOCK_ENTROPY): Remove.
(mix_random_values): New function.
(random_bits): Use it. Args are now new value address and
old value, and this function now returns a success indicator.
Omit old USE_GETRANDOM argument: always try getrandom now, as
there is no good reason not to now that GRND_NONBLOCK is used.
Caller changed. Use CLOCK_REALTIME for for ersatz entropy,
as CLOCK_MONOTONIC doesn't work on some platforms.
Also, mix in ersatz entropy from tv_sec and from clock ().
(try_tempname_len): Do not mix in ASLR-based entropy, as
the result is published to the world and ASLR should be private.
Do not try to use a static var as that has issues if multithreaded.
Instead, simply generate new random bits.
Worry about bias only with high-quality random bits.
* modules/tempname (Depends-on): Do not depend on stdalign.
Paul Eggert [Mon, 22 Aug 2022 19:22:52 +0000 (12:22 -0700)]
tempname: merge 64-bit time_t fix from glibc
This merges glibc commit 52a5fe70a2c77935afe807fb6e904e512ddd894e
"Use 64 bit time_t stat internally".
* lib/tempname.c (struct_stat64) [_LIBC]: Use struct __stat64_t64.
(__lstat64_time64) [!_LIBC]: Rename from __lstat64.
All uses changed.
(direxists): Use __stat64_time64 instead of __stat64.
Paul Eggert [Tue, 16 Aug 2022 19:06:48 +0000 (12:06 -0700)]
tempname: generate better names for MinGW Emacs
On MinGW, GNU Emacs disables clock_gettime, which reliably breaks
some of gen_tempname’s optimistic callers. Work around the
problem by making the generated names less predictable. We don’t
need cryptographic randomness here, just enough unpredictability
to keep Emacs happy most of the time.
* lib/tempname.c (HAS_CLOCK_ENTROPY): New macro.
(random_bits): Use it.
(try_tempname_len): On systems lacking clock entropy, maintain
state so that gen_filename generates less-predictable names on
successive successful calls.
Paul Eggert [Sun, 14 Aug 2022 03:00:02 +0000 (20:00 -0700)]
stdbool: port to C23
* m4/stdbool.m4 (AC_CHECK_HEADER_STDBOOL): Copy from bleeding-edge
Autoconf. Don’t define if Autoconf 2.72 or later.
* tests/test-stdbool.c (bool, false, true)
(__bool_true_false_are_defined): Do not require these to be
defined. C23 still requires __bool_true_false_are_defined but
marks it as obsolescent, and it’s no longer worth testing.
(WORKING_BOOL): New macro, which also tests __STDC_VERSION__.
Use it in tests for working bool.
Test for bool instead of for _Bool, which C23 says is obsolescent.
Bug reported by Bruno Haible in
<https://lists.gnu.org/r/bug-gnulib/2022-04/msg00023.html>.
* lib/hamt.c (entry_insert): Remove technically undefined
behavior when shifting an integer of N bits by N or more bits.
Bruno Haible [Sun, 10 Jul 2022 19:52:11 +0000 (21:52 +0200)]
vma-iter: Add support for AIX 7.
* lib/vma-iter.h (VMA_ITERATE_SUPPORTED): Define also on AIX.
* lib/vma-iter.c (vma_iterate): Add code for AIX, known to work on
AIX 7.
* lib/get-rusage-as.c: Update comments.
* lib/get-rusage-data.c: Likewise.
* tests/test-get-rusage-as.c (main): Take into account the special
address space organization on AIX in 32-bit mode.
Jim Meyering [Thu, 23 Jun 2022 15:12:44 +0000 (08:12 -0700)]
maint.mk: fix syntax-check for unnecessary hash.h header use
* top/maint.mk (_hash_re): Correct the regexp. It had two problems:
- lacked the "hash_" prefix, so would match non-uses
- failed to detect uses of the hash_x?initialize functions
The former led to an excess/unneeded use of hash.h in coreutils' cut.c.
The latter would have led to a FP "not needed" report for copy.c.
Bruno Haible [Tue, 21 Jun 2022 23:43:52 +0000 (01:43 +0200)]
chmod: New module.
* lib/sys_stat.in.h (chmod): Declare when GNULIB_CHMOD is 1.
* lib/chmod.c: New file, based on lib/lchmod.c.
* m4/chmod.m4: New file, based on m4/fchmodat.m4.
* m4/sys_stat_h.m4 (gl_SYS_STAT_H): Test whether chmod is declared.
(gl_SYS_STAT_H_REQUIRE_DEFAULTS): Initialize GNULIB_CHMOD.
(gl_SYS_STAT_H_DEFAULTS): Initialize REPLACE_CHMOD.
* modules/sys_stat (Makefile.am): Substitute GNULIB_CHMOD,
REPLACE_CHMOD.
* modules/chmod: New file, based on modules/lchmod.
* doc/posix-functions/chmod.texi: Mention the new module and the
problems on IRIX and Windows.
Paul Eggert [Mon, 20 Jun 2022 04:30:01 +0000 (23:30 -0500)]
lchmod: port back to AIX 7.2
Problem reported by Bruno Haible in:
https://lists.gnu.org/r/bug-gnulib/2022-06/msg00075.html
* lib/lchmod.c: Include string.h, for strlen.
(lchmod): Do not depend on HAVE_READLINK since we now depend on
the readlink module. Check for AIX 7.2 bug.
* m4/lchmod.m4 (gl_PREREQ_LCHMOD): Do not check for readlink
since we now depend on the readlink module.
* modules/lchmod (Depends-on): Depend on readlink.
Paul Eggert [Sun, 12 Jun 2022 20:46:52 +0000 (13:46 -0700)]
fchmodat: port better to MS-Windows etc.
MS-Windows problem reported by Bruno Haible in:
https://lists.gnu.org/r/bug-gnulib/2022-06/msg00041.html
Although I don’t use MS-Windows I see some related fstatat etc.
problems and am trying to fix them with this further patch.
* lib/fchmodat.c (fchmodat):
* lib/lchmod.c (lchmod):
* lib/lchown.c (lchown)
[!HAVE_LCHOWN && HAVE_CHOWN && !CHOWN_MODIFIES_SYMLINK]:
* lib/renameatu.c (renameatu)
[HAVE_RENAME && RENAME_TRAILING_SLASH_SOURCE_BUG]:
Use readlinkat/readlink instead of fstatat/lstat to test merely
whether a string names a symlink, as this avoids problems
with EOVERFLOW. Also, I hope it works around the MS-Windows
issues that Bruno noted.
* m4/fchmodat.m4 (gl_PREREQ_FCHMODAT):
Check for readlinkat, not lchmod.
* m4/lchmod.m4 (gl_FUNC_LCHMOD): Do not require AC_CANONICAL_HOST
or check for lstat.
(gl_PREREQ_LCHMOD): Check for readlink.
* modules/lchown (Depends-on): Add readlink. Do not depend on
lstat merely because !HAVE_LCHOWN.
* modules/renameatu (Depends-on): Add fstatat, readlinkat.