Paul Eggert [Wed, 30 Aug 2023 17:15:09 +0000 (10:15 -0700)]
wchar-single: fix module broken since 2021
Adjust to 2021-03-07 change “Rename GNULIB_WCHAR_SINGLE to
GNULIB_WCHAR_SINGLE_LOCALE”. Apparently nobody noticed that
the module was broken. Perhaps we should obsolete the module?
* modules/wchar-single (GNULIB_WCHAR_SINGLE_LOCALE): Define.
Bruno Haible [Wed, 30 Aug 2023 00:19:01 +0000 (02:19 +0200)]
wctype: Rely on module iswpunct.
* m4/wctype.m4 (gl_FUNC_WCTYPE): Also test whether the "punct" class
works.
* modules/wctype (Depends-on): Add iswpunct.
* tests/test-iswctype.c (main): Add more tests of the "punct" class.
* doc/posix-functions/wctype.texi: Mention the Android problem.
Bruno Haible [Wed, 30 Aug 2023 00:18:26 +0000 (02:18 +0200)]
iswpunct: Add tests.
* tests/test-iswpunct.c: New file, based on tests/test-iswdigit.c and
tests/test-c32ispunct.c.
* tests/test-iswpunct.sh: New file, based on tests/test-iswdigit.sh.
* modules/iswpunct-tests: New file.
Paul Eggert [Mon, 28 Aug 2023 19:21:23 +0000 (12:21 -0700)]
spelling fix: cloneable -> clonable
* build-aux/bootstrap, top/bootstrap, top/bootstrap-funclib.sh:
Spell it “clonable”, the more common English way, instead of
“cloneable”, the Java way. Found while doing spelling check
of Coreutils.
Paul Eggert [Sun, 27 Aug 2023 06:19:12 +0000 (23:19 -0700)]
trim: do not over-allocate result
* lib/trim.c: Include mbuiterf.h, not mbiterf.h, since we no
longer compute strlen at first.
(trim2): Do not over-allocate result and then trim the parts we
don’t want. Instead, skip unwanted input before allocating,
so that the result is just the right size. Use mempcpy
instead of memmove. Simplify.
* modules/trim (Depends-on): Remove mbiterf, memmove, strdup, xalloc.
Add mbuiterf, mempcpy, xalloc-die.
Paul Eggert [Sun, 27 Aug 2023 06:19:10 +0000 (23:19 -0700)]
Tune single-byte code involving tolower
* lib/mbmemcasecmp.c (mbmemcasecmp):
* lib/mbscasecmp.c (mbscasecmp):
* lib/mbscasestr.c (mbscasestr):
* lib/mbsncasecmp.c (mbsncasecmp):
* lib/mbspcasecmp.c (mbspcasecmp):
Avoid some unnecessary calls to tolower. For example, if the two
single-byte characters are equal before downcasing there is no
need to call tolower on either character.
Bruno Haible [Sat, 26 Aug 2023 20:45:17 +0000 (22:45 +0200)]
crypto/{sha*,md5,sm3}-buffer: Ignore too old OpenSSL versions.
* lib/sha1.h: If <openssl/macros.h> would give a compile-time error,
undefine HAVE_OPENSSL_SHA1.
* lib/sha256.h: If <openssl/macros.h> would give a compile-time error,
undefine HAVE_OPENSSL_SHA256.
* lib/sha512.h: If <openssl/macros.h> would give a compile-time error,
undefine HAVE_OPENSSL_SHA512.
* lib/md5.h: If <openssl/macros.h> would give a compile-time error,
undefine HAVE_OPENSSL_MD5.
* lib/sm3.h: If <openssl/macros.h> would give a compile-time error,
undefine HAVE_OPENSSL_SM3.
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.