Bruno Haible [Mon, 21 Aug 2023 15:23:41 +0000 (17:23 +0200)]
alignasof, stdalign: Fix a compilation error in C++ mode on FreeBSD 12.
* m4/stdalign.m4 (gl_ALIGNASOF): In C++ mode, prefer __builtin_offsetof
over offsetof when possible, since __builtin_offsetof works also when
<stddef.h> has not been fully included yet.
Bruno Haible [Mon, 21 Aug 2023 13:58:16 +0000 (15:58 +0200)]
wcsstr-simple: Relicense under LGPLv2+.
* modules/wcsstr-simple (License): Change to LGPLv2+.
* lib/wcsstr.c: Update license notice.
* lib/wcsstr-impl.h: Update license notice. The code added here on
2023-03-27 was under LGPLv2+.
Paul Eggert [Sun, 20 Aug 2023 20:23:11 +0000 (13:23 -0700)]
ldexp: fix INT_MIN infloop
* lib/ldexp.c (FUNC): Instead of converting EXP to unsigned,
work on it directly. This simplifies the code and avoids
an infinite loop when EXP == INT_MIN.
* modules/ldexp, modules/ldexpl: Depend on stdbool.
* tests/test-ldexp.h: Include <limits.h> for INT_MIN.
(test_function): Test for infloop.
Bruno Haible [Sun, 20 Aug 2023 00:43:01 +0000 (02:43 +0200)]
ldexp: Work around OpenBSD/mips64 bug.
* lib/math.in.h (ldexp): New declaration.
* lib/ldexp.c: New file, based on lib/ldexpl.c.
* lib/ldexpl.c: Moved the implementation to lib/ldexp.c. Just include
it.
* m4/math_h.m4 (gl_MATH_H_REQUIRE_DEFAULTS): Initialize GNULIB_LDEXP.
(gl_MATH_H_DEFAULTS): Initialize REPLACE_LDEXP.
* m4/ldexp.m4 (gl_FUNC_LDEXP): Require gl_MATH_H_DEFAULTS and
gl_FUNC_ISNAND. Invoke gl_FUNC_LDEXP_WORKS. Set REPLACE_LDEXP. Consider
it when setting LDEXP_LIBM.
(gl_FUNC_LDEXP_WORKS): New macro.
* modules/math (Makefile.am): Substitute GNULIB_LDEXP, REPLACE_LDEXP.
* modules/ldexp (Files): Add lib/ldexp.c.
(Depends-on): Add math, isnand.
(configure.ac): Set GL_COND_OBJ_LDEXP. Invoke gl_MATH_MODULE_INDICATOR.
(Makefile.am): Conditionally compile ldexp.c.
* modules/ldexpl (Files): Add lib/ldexp.c.
* doc/posix-functions/ldexp.texi: Mention the OpenBSD bug.
Bruno Haible [Sat, 19 Aug 2023 22:45:05 +0000 (00:45 +0200)]
logbl: Work around endless loop on OpenBSD 7.3/mips64.
* m4/logbl.m4 (gl_FUNC_LOGBL_WORKS): Terminate the test program if it
takes longer than 5 seconds.
* doc/posix-functions/logbl.texi: Mention the OpenBSD bug.
Bruno Haible [Fri, 18 Aug 2023 20:38:04 +0000 (22:38 +0200)]
thrd: Work around thrd_join bug on AIX 7.3.1.
* m4/threads_h.m4 (gl_THREADS_H): Test against AIX 7 thrd_join bug. Set
BROKEN_THRD_JOIN.
(gl_THREADS_H_DEFAULTS): Initialize BROKEN_THRD_JOIN.
* m4/thrd.m4 (gl_FUNC_THRD_JOIN): Set REPLACE_THRD_* to 1 also if
BROKEN_THRD_JOIN is 1. Define BROKEN_THRD_START_T_OR_JOIN instead of
BROKEN_THRD_START_T.
* modules/threads-h (Makefile.am): Substitute BROKEN_THRD_JOIN.
* lib/threads.in.h (rpl_thrd_t, thrd_t): Define also if BROKEN_THRD_JOIN
is 1.
* lib/thrd.c: Test BROKEN_THRD_START_T_OR_JOIN instead of
BROKEN_THRD_START_T.
* doc/posix-functions/thrd_join.texi: Update.
* doc/posix-functions/thrd_exit.texi: Likewise.
Bruno Haible [Fri, 18 Aug 2023 19:14:40 +0000 (21:14 +0200)]
thrd: Refactor.
* m4/thrd.m4 (gl_FUNC_THRD_JOIN): Define BROKEN_THRD_JOIN_NULL, not
BROKEN_THRD_JOIN. Rename gl_cv_func_thrd_join_works to
gl_cv_func_thrd_join_null_works.
* lib/thrd.c: Test BROKEN_THRD_JOIN_NULL instead of BROKEN_THRD_JOIN.
Bruno Haible [Fri, 18 Aug 2023 16:54:28 +0000 (18:54 +0200)]
aligned_alloc: Fix test failure on AIX 7.3 with ibm-clang.
* m4/aligned_alloc.m4 (gl_FUNC_ALIGNED_ALLOC): Use 'volatile', to
disable optimization of ibm-clang -O2.
* doc/posix-functions/aligned_alloc.texi: Update version info.
Bruno Haible [Sun, 13 Aug 2023 23:04:36 +0000 (01:04 +0200)]
nproc, physmem: Use sysctl() as a fallback on GNU/kFreeBSD.
* lib/nproc.c: Do include <sys/sysctl.h> on GNU/kFreeBSD.
(num_processors_ignoring_omp): Call sysctl on GNU/kFreeBSD.
* lib/physmem.c: Do include <sys/sysctl.h> on GNU/kFreeBSD.
(physmem_total, physmem_available): Call sysctl on GNU/kFreeBSD.
Paul Eggert [Sun, 13 Aug 2023 16:46:47 +0000 (09:46 -0700)]
fts: improve memory-allocation errno handling
* lib/fts.c (fts_read, fts_build): When enter_dir or setup_dir
fails, report its errno value back to the user.
(internal_function): Preserve errno.
* modules/fts (Depends-on): Add calloc-posix, free-posix,
malloc-posix, and realloc-posix, for better errno handling
on allocation failures.
Paul Eggert [Sun, 13 Aug 2023 15:34:44 +0000 (08:34 -0700)]
hash: set errno on failure
* lib/hash.c: Include errno.h.
(compute_bucket_size, hash_initialize, hash_rehash)
(hash_insert_if_absent): Set errno reliably on failure.
(hash_free): Preserve errno, like plain 'free'.
* modules/hash (Depends-on): Depend on calloc-posix,
free-posix, malloc-posix, so that errno is set reliably.
Bruno Haible [Sun, 13 Aug 2023 14:08:33 +0000 (16:08 +0200)]
readutmp, boot-time: Fix compilation error on Android API 8.
Reported by Po Lu in
<https://lists.gnu.org/archive/html/bug-gnulib/2023-08/msg00108.html>.
* m4/readutmp.m4 (gl_PREREQ_READUTMP_H): Test whether sysinfo is
declared.
* lib/boot-time-aux.h (get_linux_uptime): Invoke sysinfo only if it is
declared.
* doc/glibc-functions/sysinfo.texi: Mention the Android problem.
Bruno Haible [Sun, 13 Aug 2023 13:39:09 +0000 (15:39 +0200)]
readutmp, boot-time: Fix compilation error on old Android.
Reported by Po Lu in
<https://lists.gnu.org/archive/html/bug-gnulib/2023-08/msg00108.html>.
* lib/readutmp.c (endutent): New fallback declaration, for Android.
(getutent): Remove Ultrix workaround from 2000-04-05.
* lib/boot-time.c: Likewise.
* m4/readutmp.m4 (gl_PREREQ_READUTMP_H): Test whether endutent is
declared, not getutent.
* doc/glibc-functions/endutent.texi: Mention the Android bug.
Paul Eggert [Sat, 12 Aug 2023 23:45:30 +0000 (16:45 -0700)]
boot-time,readutmp: remove -lrt usage
This code uses clock-relevant functions only on platforms
that do not need -lrt.
* m4/readutmp.m4 (gl_READUTMP): Do not require gl_CLOCK_TIME
or add CLOCK_TIME_LIB to READUTMP_LIB.
* modules/boot-time (Link): No need to link with CLOCK_TIME_LIB.
Paul Eggert [Sat, 12 Aug 2023 23:05:22 +0000 (16:05 -0700)]
boot-time,readutmp: do not depend on fopen-gnu
These modules should work well enough even if fopen is not fixed
to conform to fopen-gnu standards. The only gotcha I can see is
older fopen implementations that lack support for "e", and
a potential O_CLOEXEC leak is not worth worrying about.
* modules/boot-time (Depends-on):
* modules/readutmp (Depends-on):
Remove fopen-gnu.
Paul Eggert [Sat, 12 Aug 2023 22:46:43 +0000 (15:46 -0700)]
boot-time: do not depend on timespec_get
This is for Emacs, which does not use timespec_get now
and which likes to minimize dependencies.
Also, treat musl libc like recent glibc,
and fix a timespec_get return value typo.
* lib/boot-time-aux.h (get_linux_uptime):
Assume musl libc supports CLOCK_BOOTTIME.
(get_linux_boot_time_final_fallback):
Likewise for musl libc and CLOCK_REALTIME.
Do not rely on the timespec_get module, to break the dependency.
Consider 0 to be a failure return from timespec_get.
Fall back on gettimeofday if timespec_get does not exist.
* modules/boot-time (Depends-on): Remove timespec_get.
Bruno Haible [Sat, 12 Aug 2023 17:40:28 +0000 (19:40 +0200)]
readutmp, boot-time: On Haiku, return the boot time.
* m4/readutmp.m4 (gl_PREREQ_READUTMP_H): Test whether <OS.h> exists.
* lib/boot-time-aux.h (get_haiku_boot_time,
get_haiku_boot_time_final_fallback): New functions.
* lib/readutmp.c: Include <OS.h>.
(read_utmp_from_file): If opening UTMP_FILE fails, continue processing
instead of failing. Invoke get_haiku_boot_time and
get_haiku_boot_time_final_fallback.
* lib/boot-time.c: Include <OS.h>.
(get_boot_time_uncached): Invoke get_haiku_boot_time and
get_haiku_boot_time_final_fallback.
Paul Eggert [Sat, 12 Aug 2023 16:54:08 +0000 (09:54 -0700)]
c-file-type: new module
* lib/c-file-type.c: New file, containing all of the
old file-type except for the gettext call.
* lib/file-type.c (_): Remove; no longer used.
(file_type): Call c_file_type for most of the work.
* modules/c-file-type: New module.
* modules/file-type (Depends-on): Add c-file-type.
Bruno Haible [Sat, 12 Aug 2023 13:09:50 +0000 (15:09 +0200)]
readutmp, boot-time: Use the BSD sysctl as fallback.
* m4/readutmp.m4 (gl_PREREQ_READUTMP_H): Test for <sys/param.h>,
<sys/sysctl.h>, sysctl.
* lib/boot-time-aux.h (get_bsd_boot_time_final_fallback): New function.
* lib/readutmp.c: Include <sys/param.h> and <sys/sysctl.h>.
(read_utmp_from_file): Invoke get_bsd_boot_time_final_fallback as a
fallback.
* lib/boot-time.c: Include <sys/param.h> and <sys/sysctl.h>.
(get_boot_time_uncached): Invoke get_bsd_boot_time_final_fallback as a
fallback.
Bruno Haible [Fri, 11 Aug 2023 21:20:44 +0000 (23:20 +0200)]
readutmp: Refactor boot time determination code.
* lib/boot-time-aux.h: New file, extracted from lib/readutmp.c.
* lib/readutmp.c: On Linux, include <sys/sysinfo.h> even if
!READUTMP_USE_SYSTEMD.
Include boot-time-aux.h.
(SIZEOF): Remove macro, moved to boot-time-aux.h.
(get_linux_uptime): Remove function, moved to boot-time-aux.h.
(read_utmp_from_file): Invoke get_linux_boot_time_fallback,
get_android_boot_time, get_openbsd_boot_time, get_windows_boot_time.
Code moved to boot-time-aux.h.
(get_boot_time_uncached: Invoke get_linux_boot_time_final_fallback.
Code moved to boot-time-aux.h.
* m4/readutmp.m4 (gl_PREREQ_READUTMP_H): New macro, extracted from
gl_READUTMP.
(gl_READUTMP): Invoke it.
* modules/readutmp (Files): Add lib/boot-time-aux.h.
Bruno Haible [Fri, 11 Aug 2023 14:09:22 +0000 (16:09 +0200)]
readutmp: Make 'struct utmpx32' usable by other code.
* lib/readutmp.h (struct utmpx32): Moved to here from lib/readutmp.c.
(UTMP_STRUCT_NAME): Define as utmpx32 if needed.
* lib/readutmp.c (read_utmp_from_file): Simply use UTMP_STRUCT_NAME.
Bruno Haible [Fri, 11 Aug 2023 13:22:43 +0000 (15:22 +0200)]
readutmp: Fix the boot time returned on Minix.
* lib/readutmp.c (read_utmp_from_file): [__minix] When the time of the
BOOT_TIME entry is very close to the Epoch, replace it with the time
from the "run-level m" entry.
Bruno Haible [Fri, 11 Aug 2023 12:29:32 +0000 (14:29 +0200)]
readutmp: On Cygwin and Windows, return the boot time.
* lib/readutmp.h (READ_UTMP_SUPPORTED): Define also on native Windows.
* lib/readutmp.c (desirable_utmp_entry): Ignore READ_UTMP_CHECK_PIDS on
Windows.
(read_utmp_from_file): Add a BOOT_TIME entry on Windows.
Bruno Haible [Fri, 11 Aug 2023 00:31:30 +0000 (02:31 +0200)]
readutmp: Tweak the Android specific addition.
* lib/readutmp.c (read_utmp_from_file) [__ANDROID__]: Don't fake a
BOOT_TIME entry if the options request to omit it or if a BOOT_TIME
entry is already present.
Bruno Haible [Thu, 10 Aug 2023 15:23:56 +0000 (17:23 +0200)]
readutmp: Fix the boot time returned on Raspbian.
* lib/readutmp.c (read_utmp_from_file): When the time of the BOOT_TIME
entry is very close to the Epoch, replace it with the time from the
"runlevel"/"~" entry.
Bruno Haible [Thu, 10 Aug 2023 05:59:19 +0000 (07:59 +0200)]
readutmp: Return a boot time also on Android.
* lib/readutmp.c (get_linux_uptime): New function, extracted from
get_boot_time_uncached.
(read_utmp_from_file): Don't look for file time stamps on Android.
Instead, use get_linux_uptime.
(get_boot_time_uncached): Use get_linux_uptime.
Bruno Haible [Wed, 9 Aug 2023 20:52:22 +0000 (22:52 +0200)]
readutmp: Return a boot time also on OpenBSD.
* lib/readutmp.h (BOOT_TIME, USER_PROCESS): Provide fallback
definitions.
* lib/readutmp.c (read_utmp_from_file) [__OpenBSD__]: Fake a BOOT_TIME
entry by looking at the time stamp of a specific file.
Bruno Haible [Wed, 9 Aug 2023 20:27:16 +0000 (22:27 +0200)]
readutmp: Return a boot time also on Alpine Linux.
* lib/readutmp.c: Include stat-time.h.
(SIZEOF): New macro.
(read_utmp_from_file) [__linux__]: Fake a BOOT_TIME entry by looking
at the time stamp of a specific file.
* modules/readutmp (Depends-on): Add stat-time.
Bruno Haible [Wed, 9 Aug 2023 19:12:40 +0000 (21:12 +0200)]
readutmp: Fix boot time in VMs after sleep state and date update.
* lib/readutmp.c (read_utmp_from_file): New function, extracted from
read_utmp.
(get_boot_time_uncached): Before all other approaches, try to find the
boot time in the /var/run/utmp file.
(read_utmp): Invoke read_utmp_from_file.
Bruno Haible [Wed, 9 Aug 2023 16:49:22 +0000 (18:49 +0200)]
readutmp: Make it easier to filter for/against the boot-time entry.
* lib/readutmp.h (READ_UTMP_BOOT_TIME, READ_UTMP_NO_BOOT_TIME): New
enum items.
* lib/readutmp.c (desirable_utmp_entry, read_utmp_from_systemd):
Implement them.
(read_utmp): If no entries can match the given options, return
immediately.
Bruno Haible [Tue, 8 Aug 2023 21:27:38 +0000 (23:27 +0200)]
readutmp: Use classical implementation for files != /var/run/utmp.
* lib/readutmp.c (read_utmp_from_systemd): Renamed from read_utmp
[READUTMP_USE_SYSTEMD]. Remove file argument.
(read_utmp): Call it when the file argument is "/var/run/utmp".
Paul Eggert [Mon, 7 Aug 2023 16:10:21 +0000 (09:10 -0700)]
quotearg: fix obsolete comment
* lib/quotearg.h: Fix comment to match behavior.
This fixes a commentary bug introduced in
commit 1a43a982c927eaf26bbc2701a872009d9be4b33b
"quotearg: do not use grave accent for left quote"
dated 2011-12-18 15:44:17+01, where the comment
was not updated to match the changed behavior.
Paul Eggert [Sun, 6 Aug 2023 19:19:36 +0000 (12:19 -0700)]
Document Android, OpenBSD printf "%n" lack
In doc/posix/functions/*printf*.texi,
document that the POSIX-specified printf functions
do not support the %n format on Android and OpenBSD.
This lack of support is deliberate, as %n is
a common target of attacks on security.
Paul Eggert [Sat, 5 Aug 2023 18:16:12 +0000 (11:16 -0700)]
readutmp: anticipate Y2038 hack for utmp
* lib/readutmp.c (struct utmpx32): Use unsigned int for tv_sec,
not int, as that is more likely to work after 2038.
Suggested by Andreas Schwab in:
https://sourceware.org/pipermail/libc-alpha/2023-August/150661.html
Paul Eggert [Sat, 5 Aug 2023 17:04:41 +0000 (10:04 -0700)]
diffseq: simplify lint removal
* lib/diffseq.h (IF_LINT): Remove.
Instead, always ignore the diagnostic, as that’s simpler
now that we have the pragma change installed in May.
This removes the last IF_LINT from diffutils, though not
the last use of GCC_LINT.
Bruno Haible [Sat, 5 Aug 2023 00:40:03 +0000 (02:40 +0200)]
unistr/{u8-mbtouc,u8-mbsnlen}: Fix test failures (regr. 2023-07-25).
* modules/unistr/u8-mbtouc (configure.ac): Compile this code if the
preinstalled libunistring version is >= 0.9.4, < 1.2.
* modules/unistr/u8-mbsnlen (configure.ac): Likewise.