Paul Eggert [Wed, 30 Oct 2024 19:47:02 +0000 (12:47 -0700)]
posix_memalign: check for GNU behavior with size 0
* lib/posix_memalign.c: Include stdckdint.h.
(posix_memalign): Test for overflow more straightforwardly,
and more portably to unlikely platforms where SIZE_MAX <= INT_MAX.
Treat a zero size as if it were alignment.
* m4/posix_memalign.m4 (gl_FUNC_POSIX_MEMALIGN):
* tests/test-posix_memalign.c (main):
Test zero size too. Use volatile to avoid compiler optimizations.
* modules/posix_memalign (Depends-on): Add stdckdint.
Paul Eggert [Wed, 30 Oct 2024 18:54:57 +0000 (11:54 -0700)]
aligned_alloc: check for GNU behavior with size 0
If someone ever needs to distinguish between GNU and merely POSIX
behavior we can split this into two modules, but for now just
make this module act like GNU.
* lib/aligned_alloc.c (aligned_alloc): Treat zero size like GNU.
* m4/aligned_alloc.m4 (gl_FUNC_ALIGNED_ALLOC):
* tests/test-aligned_alloc.c (main):
Test zero size too.
Paul Eggert [Wed, 30 Oct 2024 05:01:43 +0000 (22:01 -0700)]
malloc: fix recent doc bug for AIX 7.3
* doc/posix-functions/malloc.texi: Undo previous change,
as _LINUX_SOURCE_COMPAT no longer affects malloc on AIX 7.3.
It did affect it in AIX 7.1 but 7.1 is no longer supported.
Paul Eggert [Wed, 30 Oct 2024 05:01:42 +0000 (22:01 -0700)]
realloc-posix: realloc (p, 0) yields nonnull
* lib/realloc.c: Include <stdckdint.h>, not "xalloc-oversized.h".
Use of xalloc_oversized replaced by ckd_add.
(rpl_realloc) [!NEED_SANITIZED_REALLOC]:
Treat realloc (p, 0) as if it were a realloc (p, 1) that never fails.
That’s easier, reduces module dependencies,
and better supports the future alloc-0-nonnull module.
* modules/realloc-posix (Depends-on): Remove free-posix,
malloc-posix, xalloc-oversized. Add stdckdint.
Bruno Haible [Tue, 29 Oct 2024 12:48:36 +0000 (13:48 +0100)]
assert-h, stdbool: Allow mixed use of gcc/g++ and clang/clang++ again.
* m4/assert_h.m4 (gl_ASSERT_H): Improve indentation. With GCC and clang,
don't use the value of HAVE_C_STATIC_ASSERT.
* m4/c-bool.m4 (gl_C_BOOL): With GCC and clang, don't use the value of
HAVE_C_BOOL.
Bruno Haible [Sun, 27 Oct 2024 16:01:29 +0000 (17:01 +0100)]
doc: Add a module index.
* doc/Makefile (undocumented-modules.texi): New rule.
(%.info, %.html, %.dvi, %.pdf): Depend on undocumented-modules.texi.
(mostlyclean): Remove also *.m and *.tmp.
(force): New rule.
* doc/*.texi: Add module index entries.
* doc/*/*.texi: Likewise.
Paul Eggert [Sat, 26 Oct 2024 17:06:55 +0000 (10:06 -0700)]
aligned_alloc: document glibc bug 32301
* doc/posix-functions/aligned_alloc.texi:
* doc/posix-functions/posix_memalign.texi: Mention glibc bug
32301, which it is not worth our time to work around.
Paul Eggert [Sat, 26 Oct 2024 00:02:02 +0000 (17:02 -0700)]
eealloc: update commentary
Even if we remove eealloc we might as well add commentary
explaining some of its confusion, before we remove it.
* lib/eealloc.h: Update comment.
* modules/eealloc (Description):
Update, since eealloc is not glibc compatible.
Paul Eggert [Fri, 25 Oct 2024 04:52:19 +0000 (21:52 -0700)]
xalloc: port to Cheri, strict C23, realloc null
* lib/xmalloc.c [__CHERI_PURE_CAPABILITY__]: Include <cheri.h>.
(xrealloc, xreallocarray): Support Cheri. Avoid undefined
behavior in strict C23. Work better on platforms where
realloc (p, 0) returns a null pointer
Paul Eggert [Fri, 25 Oct 2024 04:34:12 +0000 (21:34 -0700)]
reallocarray: simplify
* lib/reallocarray.c (reallocarray): Use simpler workaround
for realloc glitch, which does not involve malloc.
* modules/reallocarray (Depends-on): Remove malloc-posix.
Paul Eggert [Wed, 23 Oct 2024 21:30:35 +0000 (14:30 -0700)]
backupfile: fix irealloc dependency
* modules/backupfile (Depends-on): Depend on irealloc,
not realloc-gnu, as the code now uses irealloc not realloc
and does not depend on GNU semantics anyway.
Paul Eggert [Wed, 23 Oct 2024 20:51:29 +0000 (13:51 -0700)]
realloc: still more improvements for realloc (p, 0)
* doc/posix-functions/malloc.texi: AIX is sans _LINUX_SOURCE_COMPAT.
* doc/posix-functions/realloc.texi:
Give more details about what recent POSIX versions say,
and fix some misperceptions about C89 through C11.
Document that the GNU behavior does not conform to POSIX,
and that AIX's behavior with _LINUX_SOURCE_COMPAT
matches glibc's circa 1999 behavior, not its current behavior.
Be a little less confident about realloc-gnu, since it doesn't
fully implement current glibc behavior.
Give more details about when memory leaks or false positives can occur.
* doc/posix-functions/reallocarray.texi:
Say that it shares realloc’s woes with zero sizes.
Bruno Haible [Mon, 21 Oct 2024 13:29:40 +0000 (15:29 +0200)]
realloc: Optionally check for undefined behaviour.
* m4/realloc.m4 (gl_FUNC_REALLOC_SANITIZED): New macro.
(gl_FUNC_REALLOC_POSIX): Require it. If a sanitized realloc is
requested, define NEED_SANITIZED_REALLOC and compile realloc.c.
(gl_FUNC_REALLOC_GNU): Require it. If a sanitized realloc is requested,
don't compile realloc.c a second time.
* lib/realloc.c (rpl_realloc): If NEED_SANITIZED_REALLOC is defined,
abort in the case of undefined behaviour.
Paul Eggert [Sat, 19 Oct 2024 21:18:49 +0000 (14:18 -0700)]
realloc: more improvements for realloc (p, 0)
* doc/posix-functions/realloc.texi (realloc):
Document more realloc (p, 0) gotchas: evolution of C standards,
errno values, which glibc versions do what, how programs might
misbehave, what happens when not growing.
Bruno Haible [Wed, 9 Oct 2024 15:22:59 +0000 (17:22 +0200)]
csharpcomp: Avoid error on Windows.
Reported by Michele Locati <michele@locati.it>.
* build-aux/csharpcomp.sh.in: Don't produce -reference options for DLLs
whose name starts with a lowercase letter or contains '.Native.'.
* lib/csharpcomp.c (name_is_dll): Filter our file names that start with
a lowercase letter or contain '.Native.'.
Bruno Haible [Wed, 9 Oct 2024 01:14:26 +0000 (03:14 +0200)]
csharpcomp-script: Add support for dotnet.
* m4/csharpcomp.m4 (gt_CSHARPCOMP): Support 'dotnet' as implementation.
Set HAVE_DOTNET_SDK, HAVE_DOTNET_CSC.
* build-aux/csharpcomp.sh.in: Add implementations for the cases
$HAVE_DOTNET_SDK = 1 and $HAVE_DOTNET_CSC = 1.
Bruno Haible [Wed, 9 Oct 2024 01:12:42 +0000 (03:12 +0200)]
csharpexec-script: Add support for dotnet.
* m4/csharpexec.m4 (gt_CSHARPEXEC): Support 'dotnet' as implementation.
Set HAVE_DOTNET.
* build-aux/csharpexec.sh.in (func_tmpdir): New function, copied from
build-aux/csharpcomp.sh.in.
Add implementation for the case $HAVE_DOTNET = 1.
* lib/csharpcomp.c (compile_csharp_using_sscli): Allocate the source
options with malloc() always, not sometimes with malloca() and sometimes
with malloc().
Bruno Haible [Mon, 7 Oct 2024 18:25:06 +0000 (20:25 +0200)]
csharpcomp: Improve Cygwin support.
* lib/csharpcomp.c: Include cygpath.h.
(compile_csharp_using_sscli): Convert the file names passed to 'csc' to
native Windows syntax.
* modules/csharpcomp (Depends-on): Add cygpath.
Bruno Haible [Mon, 7 Oct 2024 18:15:44 +0000 (20:15 +0200)]
csharpexec: Improve Cygwin support.
* lib/csharpexec.c: Include cygpath.h.
(execute_csharp_using_sscli): Convert the first 'clix' argument to
native Windows syntax.
* modules/csharpexec (Depends-on): Add cygpath.
Bruno Haible [Mon, 7 Oct 2024 12:30:52 +0000 (14:30 +0200)]
file-has-acl: Fix performance regression on FreeBSD, Cygwin.
* lib/dirent.in.h (_GL_DT_NOTDIR): New macro.
* lib/acl.h (ACL_SYMLINK_FOLLOW): Increase value.
* lib/file-has-acl.c (file_has_aclinfo): Don't call
acl_get_file (name, ACL_TYPE_DEFAULT) if we know that name does not
denote a directory.
(file_has_acl): Extract from *SB the information that NAME is not a
directory.
Bruno Haible [Sun, 6 Oct 2024 23:14:20 +0000 (01:14 +0200)]
javacomp, javaversion: Fix resource leak.
* lib/javacomp.c (execute_and_read_line): When fdopen fails, terminate
the program.
* lib/javaversion.c (execute_and_read_line): Likewise. When we can't
read a single line, call fclose and wait_subprocess, to free resources.
Paul Eggert [Sat, 5 Oct 2024 16:02:23 +0000 (09:02 -0700)]
mktime: fix daylight default
Problem for FreeBSD 14 reported by Bruno Haible in:
https://lists.gnu.org/r/bug-gnulib/2024-10/msg00026.html
* m4/mktime.m4 (gl_PREREQ_MKTIME): Default daylight to 1, not 0.
Paul Eggert [Sat, 5 Oct 2024 04:07:09 +0000 (21:07 -0700)]
mktime: improve thread-safety
* lib/mktime.c (__mktime_internal) [!_LIBC]: Double the number of
probes. Although this isn’t guaranteed to suffice, it should be
good enough for practical applications, and fixing the problem
in general would require access to the underlying tz state lock
which would be hard to do.
Paul Eggert [Sat, 5 Oct 2024 02:01:30 +0000 (19:01 -0700)]
mktime: fix timegm bug that set tmp->tm_isdst
* lib/timegm.c (__timegm64): Omit now-unnecessary initialization
of tm_isdst. Anyway, the initialization was always wrong, since
timegm should not modify *TMP when it fails.
Bruno Haible [Fri, 4 Oct 2024 21:52:13 +0000 (23:52 +0200)]
bcp47: Refactor.
* lib/bcp47.c (SCRIPT_*): New macros.
(default_script_in_territory, default_script_for_language2,
default_script_for_language3): New functions.
(xpg_to_bcp47, bcp47_to_xpg): Use them.
Paul Eggert [Fri, 4 Oct 2024 16:12:42 +0000 (09:12 -0700)]
timegm: ignore incoming tm_isdst
Problem reported by Florian Weimer via a proposed glibc patch in:
https://sourceware.org/pipermail/libc-alpha/2024-October/160310.html
* lib/mktime.c (__mktime_internal): Ignore any tm_isdst request
if the timezone never observes DST, as is the case for timegm.
* m4/mktime.m4 (gl_PREREQ_MKTIME): Define new C macro __daylight
if needed.
Paul Eggert [Fri, 4 Oct 2024 16:10:21 +0000 (09:10 -0700)]
timegm: desync from glibc for now
* config/srclist.txt: Omit time/timegm.c and time/mktime-internal.h
for now, until we can sync glibc from Gnulib.
* lib/mktime-internal.h, lib/timegm.c: Revert autoupdate, going
back to the recent Gnulib-specific version.
Paul Eggert [Fri, 4 Oct 2024 05:06:33 +0000 (22:06 -0700)]
mktime: prefer static_assert to verify
This should work better with glibc.
* lib/mktime.c: Do not include verify.h.
Use static_assert instead of verify.
* modules/mktime (Depends-on): Depend on assert-h, not verify.
Paul Eggert [Fri, 4 Oct 2024 01:29:43 +0000 (18:29 -0700)]
mktime: refactor convert_time
This is to better merge with a future version of glibc.
This merges a glibc patch by Florian Weimer in:
https://sourceware.org/pipermail/libc-alpha/2024-October/160308.html
* lib/mktime.c (convert_time): Accept a boolean flag instead
of a function pointer. All callers changed.
Paul Eggert [Fri, 4 Oct 2024 01:14:30 +0000 (18:14 -0700)]
mktime: improve comment wording
* src/mktime.c: Improve comment wording. glibc has
changed the comment wording, and this improves on
the glibc changes with the result scheduled to be
copied back to glibc.
Paul Eggert [Thu, 3 Oct 2024 00:40:34 +0000 (17:40 -0700)]
file-has-acl: no need for struct stat
Change the API of the new file_has_aclinfo function so that it no
longer needs a struct stat *. In some cases this can help GNU ls
avoid an unnecessary ‘stat’ call for each file it lists, which
can be a significant win.
* lib/acl.h (ACL_SYMLINK_NOFOLLOW): Change from 1 to UCHAR_MAX+1
so that it can be ORed with any d_type value.
* lib/file-has-acl.c: Include dirent.h, for the DT_* macros.
Check that ACL_SYMLINK_NOFOLLOW is outside unsigned char range.
(file_has_aclinfo): Change API so that struct stat is no longer
needed. Instead, the file type (if known) is passed as part of
the flags. All callers changed. Simplify NFSv4 code.
* modules/file-has-acl (Depends-on): Add assert-h for static_assert,
and dirent for DT_* macros.
* tests/test-file-has-acl.c: Include dirent.h.
(main): Adjust to file_has_aclinfo API change.
Briefly test ACL_SYMLINK_FOLLOW.
Paul Eggert [Wed, 2 Oct 2024 22:50:10 +0000 (15:50 -0700)]
dirent: define DT_* macros on all platforms
* lib/dirent.in.h (DT_UNKNOWN, DT_FIFO, DT_CHR, DT_DIR, DT_BLK)
(DT_REG, DT_LNK, DT_SOCK, DT_WHT): Define these on all platforms,
if the system does not already define them. Check that they
have distinct values.
(_GL_DIRENT_S_ISWHT, _GL_DIRENT_S_IFWHT) [!(IFTODT && DTTOIF)]:
New macros.
(IFTODT, DTTOIF): Define if not already defined.
* modules/dirent (Depends-on): Add assert-h, extensions.
Paul Eggert [Wed, 2 Oct 2024 02:51:50 +0000 (19:51 -0700)]
file-has-acl.c: port back to macOS
Problem reported by Bruno Haible in:
https://lists.gnu.org/r/bug-gnulib/2024-10/msg00000.html
* lib/file-has-acl.c (file_has_aclinfo): Don’t attempt to link to
acl_extended_file if !HAVE_ACL_EXTENDED_FILE. Most of this patch
consists of indenting changes; the real change is to use ‘#if’
rather than ‘if’.
Bruno Haible [Wed, 2 Oct 2024 00:23:57 +0000 (02:23 +0200)]
localename-unsafe: Modernize locale name mapping.
* lib/localename-unsafe.c (gl_locale_name_from_win32_LANGID): Return
"az" instead of "az@latin", "az_AZ" instead of "az_AZ@latin",
"ber_MA" instead of "ber_MA@arabic", "ber_DZ" instead of "ber_DZ@latin".
Paul Eggert [Mon, 30 Sep 2024 17:46:57 +0000 (10:46 -0700)]
file-has-acl: improve performance on Linux symlinks
* lib/file-has-acl.c (USE_LINUX_XATTR): Now can be used outside #if.
(file_has_aclinfo): As an optimization on Linux, do not attempt to
get extended attributes on symlinks, as this will always fail.
Also, use lgetxattr (not getxattr) and acl_extended_file_nofollow
(not acl_extended_file) when not following symlinks, to avoid some
races.
Paul Eggert [Sun, 29 Sep 2024 23:13:53 +0000 (16:13 -0700)]
file-has-acl: new function file_has_aclinfo
This is for GNU coreutils, whose ‘ls’ can be made faster with the
new function because it means (for example) that ‘ls’ needn’t call
both listxattr and lgetxattr in the common case where the file has
no extended attributes.
* lib/acl.h (ACL_SYMLINK_FOLLOW): New constant.
(struct aclinfo): New type.
* lib/file-has-acl.c (UNKNOWN_SECURITY_CONTEXT): New constant.
(USE_LINUX_XATTR): New macro. When set:
Include stdint.h (for uint32_t). If also USE_SELINUX_SELINUX_H,
include selinux/selinux.h (for getfilecon).
If HAVE_SMACK, include <sys/smack.h>, otherwise provide substitutes
for smack_smackfs_path and smack_new_label_from_path.
(is_smack_enabled): New function.
(aclinfo_has_xattr): Rename from have_xattr and make it extern.
Use struct aclinfo const * arg instead of char const * and ssize_t.
Work even if ai->size < 0. Supply a no-op macro on platforms
lacking xattr.
(get_aclinfo): New static function, much of it taken from
coreutils/src/ls.c.
(file_has_aclinfo): New function, which generalizes file_has_acl
to provide more info. Its body is taken from the old file_has_acl
with new stuff from ls.c.
(file_has_acl): Use it.
(aclinfo_scontext_free, aclinfo_free): Nwew functions, if not
already no-op macros.
* m4/acl.m4 (gl_FUNC_ACL_ARG): Add --without-libsmack option.
(gl_FILE_HAS_ACL): Check for libsmack, selinux.
* m4/selinux-selinux-h.m4 (gl_CHECK_HEADER_SELINUX_SELINUX_H):
New macro, for use by file-has-acl. Rename HAVE_SELINUX_SELINUX_H
to USE_SELINUX_SELINUX_H to avoid confusion as to whether we have
<selinux/selinux.h>; all uses changed.
(gl_HEADERS_SELINUX_SELINUX_H): Use the new macro.
* modules/file-has-acl (Files): Add m4/selinux-selinux-h.m4.
(Depends-on): Add errno, ssize_t.
* tests/test-file-has-acl.c (main): Add a little test for
file_has_aclinfo.