Paul Eggert [Sun, 10 Sep 2023 00:22:19 +0000 (17:22 -0700)]
trim: support GNULIB_MCEL_PREFER
Support mcel API for apps that prefer it.
The following changes are in effect only if GNULIB_MCEL_PREFER.
* lib/trim.c: Include mcel.h, not mbchar.h and mbuiterf.h.
(trim2): Use mcel API.
* modules/trim (Depends-on): Add c32isspace.
Paul Eggert [Sun, 10 Sep 2023 00:14:15 +0000 (17:14 -0700)]
mbsstr: support GNULIB_MCEL_PREFER
Support mcel API for apps that prefer it.
* lib/mbsstr.c [GNULIB_MCEL_PREFER]: Include mcel.h not mbuiter.h.
(mbchar_t, mb_equal) [GNULIB_MCEL_PREFER]: New type and function,
to make it easier to use common code.
(knuth_morris_pratt_multibyte): Don't assume mbchar_t's alignment
is at least that of size_t.
(knuth_morris_pratt_multibyte, mbsstr) [GNULIB_MCEL_PREFER]:
Use mcel API.
* modules/mbsstr (Depends-on): Add alignasof.
Paul Eggert [Sat, 9 Sep 2023 22:47:27 +0000 (15:47 -0700)]
mbslen: support GNULIB_MCEL_PREFER
Support mcel API for apps that prefer it.
The following changes are in effect only if GNULIB_MCEL_PREFER.
* lib/mbslen.c: Include mcel.h instead of mbuiterf.h.
(mbslen): Use mcel API.
Paul Eggert [Sat, 9 Sep 2023 16:53:02 +0000 (09:53 -0700)]
chown: work around symlink issues on odd platforms
Problem reported by Jordi Sanfeliu in:
https://lists.gnu.org/archive/html/bug-gnulib/2023-07/msg00116.html
* lib/chown.c (rpl_chown) [CHOWN_MODIFIES_SYMLINK]:
Do not declare unused locals st, stat_valid.
Redo to just call chown if arg is a symlink.
This induces a race but is perhaps the best we can do easily
on oddball platforms where chown does not follow symlinks.
Paul Eggert [Thu, 7 Sep 2023 21:51:58 +0000 (14:51 -0700)]
mbscasecmp: support GNULIB_MCEL_PREFER
* lib/mbscasecmp.c: Include stdlib.h, since we use MB_CUR_MAX.
Include uchar.h, for c32tolower.
(GNULIB_MCEL_PREFER): Include mcel.h instead of mbuiterf.h.
(mbscasecmp) [GNULIB_MCEL_PREFER]: Use mcel instead of mbuiterf.
* modules/mbscasecmp (Depends-on): Add c32tolower, stdlib, uchar.
Depend on mbuiterf only if not preferring mcel.
Paul Eggert [Thu, 7 Sep 2023 21:51:58 +0000 (14:51 -0700)]
exclude: support GNULIB_MCEL_PREFER
Support mcel API for apps that prefer it.
The following changes are in effect only if GNULIB_MCEL_PREFER.
* lib/exclude.c: Include mcel.h instead of mbuiter.h.
(string_hasher_ci): Use mcel_scanz instead of mbui_init,
mbui_avail, mbui_cur, and mbui_advance.
* modules/exclude: Do not depend on mbuiter.
Paul Eggert [Thu, 7 Sep 2023 21:51:56 +0000 (14:51 -0700)]
mcel-bench-tests: new module
* modules/mcel-bench-tests, tests/bench-mcel.c: New files.
* tests/bench-multibyte.h (TEXT_LATIN_ASCII_LINE1)
(TEXT_FRENCH_UTF8_LINE1, TEXT_GREEK_UTF8_LINE1)
(TEXT_CHINESE_UTF8_LINE1): New macros.
(text_random_bytes): New constant.
* tests/bench.h (timing_output): Mark with _GL_UNUSED,
since bench-mcel.c does not use it.
Bruno Haible [Thu, 7 Sep 2023 14:21:25 +0000 (16:21 +0200)]
c-*snprintf: Fix some clang -Wmissing-prototypes warnings.
* lib/c-snprintf.c: Include c-snprintf.h instead of <stdio.h>.
* lib/c-vsnprintf.c: Include c-vsnprintf.h instead of <stdio.h>.
* lib/c-vasnprintf.c: Include c-vasnprintf.h.
Bruno Haible [Thu, 7 Sep 2023 00:20:05 +0000 (02:20 +0200)]
doc: Refine documentation of MSVC support for shared libraries.
* doc/lib-symbol-visibility.texi (Exported Symbols of Shared Libraries):
Recommend to define BUILDING_SHARED as an Autoconf variable. Recommend
to test DLL_EXPORT.
Bruno Haible [Tue, 5 Sep 2023 14:36:11 +0000 (16:36 +0200)]
stdint, *printf: Update doc about MSVC.
* doc/posix-headers/stdint.texi: MSVC 14 has <stdint.h>.
* doc/posix-functions/*printf.texi: Current mingw and MSVC 14 support
the j, t, z size specifiers.
* doc/glibc-functions/obstack_*printf.texi: Likewise.
Bruno Haible [Mon, 4 Sep 2023 19:54:09 +0000 (21:54 +0200)]
Use statement-expressions without warnings, even in strict ISO C mode.
Suggested by Eric Blake <eblake@redhat.com> in
<https://lists.gnu.org/archive/html/bug-gnulib/2023-09/msg00025.html>.
* lib/error.in.h (__gl_error_call): Use the variant with obvious control
flow also with clang. Use '__extension__' to avoid -Wpedantic warnings.
* lib/math.in.h (gl_signbitf, gl_signbitd, gl_signbitl): Define as
macros even when __STRICT_ANSI__ is defined. But use '__extension__' to
avoid -Wpedantic warnings.
* lib/setenv.c (KNOWN_VALUE): Use '__extension__' to avoid -Wpedantic
warnings.
* lib/xalloc-oversized.h (xalloc_oversized): Use optimized variant even
when __STRICT_ANSI__ is defined. But use '__extension__' to avoid
-Wpedantic warnings.
Paul Eggert [Mon, 4 Sep 2023 01:14:53 +0000 (18:14 -0700)]
same-inode, stat-size: support pointers too
Add functions and macros so that we can test pointers to struct
stat as well as plain struct stat. This lets coreutils deal with
structs that are only partly initialized, without relying on
undefined behavior.
* NEWS: Mention this.
* doc/posix-headers/sys_stat.texi, doc/stat-size.texi:
Mention this and modernize.
* lib/at-func2.c (at_func2):
* lib/fts.c (same_fd):
* lib/rename.c (rpl_rename) [RENAME_HARD_LINK_BUG]:
* lib/same-inode.c: New file.
* lib/same.c (same_nameat):
* lib/term-style-control.c (activate_term_style_controller):
Prefer psame_inode (a, b) to SAME_INODE (*a, *b).
* lib/hash-triple-simple.c (triple_compare_ino_str):
* lib/hash-triple.c (triple_compare):
Prefer PSAME_INODE (a, b) to SAME_INODE (*a, *b).
psame_inode is not suitable since the args are not struct stat *.
* lib/same-inode.h: Check that config.h is included first.
(SAME_INODE_INLINE, PSAME_INODE): New macros.
(SAME_INODE): Reimplement in terms of PSAME_INODE.
(psame_inode): New function.
* lib/stat-size.h (STP_BLKSIZE, STP_NBLOCKS): New macros.
(ST_BLKSIZE, ST_NBLOCKS): Use them.
* lib/term-style-control.c (log_signal_handler_called):
Always define as a function, to pacify -Wunused*.
* modules/canonicalize-lgpl-tests (Files): Add m4/musl.m4.
(Depends-on): Call gl_MUSL_LIBC.
* modules/same-inode (Files): Add same-inode.c.
(Depends-on): Add extern-inline, stdbool.
(lib_SOURCES): New macro.
* tests/test-binary-io.c, tests/test-canonicalize-lgpl.c:
* tests/test-canonicalize.c, tests/test-cloexec.c:
* tests/test-dup-safer.c, tests/test-dup2.c, tests/test-error.c:
* tests/test-fcntl.c, tests/test-fdopendir.c, tests/test-fgetc.c:
* tests/test-fputc.c, tests/test-fread.c, tests/test-fstat.c:
* tests/test-fstatat.c, tests/test-ftruncate.c:
* tests/test-fwrite.c, tests/test-getcwd.c:
* tests/test-getdtablesize.c, tests/test-isblank.c:
* tests/test-linkat.c, tests/test-lock.c, tests/test-lstat.h:
* tests/test-malloc-gnu.c, tests/test-openat.c:
* tests/test-pthread-thread.c, tests/test-pthread_sigmask1.c:
* tests/test-pthread_sigmask2.c, tests/test-ptsname.c:
* tests/test-ptsname_r.c, tests/test-raise.c:
* tests/test-realloc-gnu.c, tests/test-rwlock1.c:
* tests/test-sigprocmask.c, tests/test-snprintf.c:
* tests/test-stat.h, tests/test-term-style-control-hello.c:
* tests/test-term-style-control-yes.c, tests/test-thread_create.c:
* tests/test-unlinkat.c, tests/test-vasnprintf.c:
* tests/test-xalloc-die.c:
Adjust to these changes, and fix some warnings elicited by
-Wall -Wextra that I ran into while testing.
* top/maint.mk (sc_prohibit_stat_st_blocks): Mention STP_NBLOCKS.
Reported by Agostino Sarubbo via Sam James <sam@gentoo.org> in
<https://lists.gnu.org/archive/html/bug-gnulib/2023-09/msg00000.html>.
* lib/sha1.h: Test the OpenSSL major version before attempting to
include <openssl/configuration.h>.
* lib/sha256.h: Likewise.
* lib/sha512.h: Likewise.
* lib/md5.h: Likewise.
* lib/sm3.h: Likewise.
Paul Eggert [Thu, 31 Aug 2023 01:26:52 +0000 (18:26 -0700)]
readutmp: fix core dump if --enable-systemd
Problem reported by Thorsten Kukuk <https://bugs.gnu.org/65617>.
* lib/readutmp.c (read_utmp_from_systemd):
Don’t assume session_ptr != NULL if num_sessions == 0.
In practice it can be null, and the man page OKs this behavior.
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.