Paul Eggert [Sun, 14 May 2023 04:47:10 +0000 (21:47 -0700)]
stdio: use _GL_ATTRIBUTE_MALLOC
* lib/stdio.in.h (fdopen, fopen, popen, tmpfile): Declare with
_GL_ATTRIBUTE_MALLOC, for consistency with glibc, and so that
building the fopen module with ‘gcc -O2 -Wsuggest-attribute=malloc
-Wsystem-headers -Werror’ does not fail with “stdio.h: In function
‘rpl_fopen’: stdio.h:970:1: error: function might be candidate for
attribute ‘malloc’ [-Werror=suggest-attribute=malloc]”, a problem
I noticed on both Fedora 38 and Ubuntu 23.04.
sigsegv: Add tentative support for Hurd/x86_64. Reported by
Samuel Thibault <samuel.thibault@ens-lyon.org>.
Paul Eggert [Fri, 12 May 2023 18:56:17 +0000 (11:56 -0700)]
file-has-acl: port to Fedora 39
Fedora 39 getxattr with XATTR_NAME_POSIX_ACL_ACCESS either
succeeds or fails with ENODATA, so it is no longer possible to
detect from its failure that the filesystem might support NFSv4 ACLs.
Problem reported by Ondrej Valousek in:
https://lists.gnu.org/r/bug-gnulib/2023-04/msg00228.html
Instead, use listxattr to determine whether NFSv4 ACLs are in play.
This typically saves syscalls anyway.
* lib/file-has-acl.c: In #if, use (HAVE_LINUX_XATTR_H &&
HAVE_LISTXATTR) instead of GETXATTR_WITH_POSIX_ACLS.
The following changes apply when (USE_ACL && HAVE_LINUX_XATTR_H &&
HAVE_LISTXATTR):
Include minmax.h.
(have_xattr): New function.
(file_has_acl): Try listxattr first; typically this means we need
to do no other syscall. Call getxattr only if there are NFSv4
ACLs but not POSIX ACLs.
* m4/acl.m4 (gl_FILE_HAS_ACL): Simplify by merely testing for
linux/xattr.h and listxattr. All uses changed.
Bruno Haible [Thu, 4 May 2023 21:27:12 +0000 (23:27 +0200)]
c32swidth: New module.
* lib/uchar.in.h (c32swidth): New declaration.
* lib/wcswidth-impl.h: Use macros FUNC, UNIT, CHARACTER_WIDTH.
* lib/wcswidth.c: Define FUNC, UNIT, CHARACTER_WIDTH before including
wcswidth-impl.h.
* lib/c32swidth.c: New file.
* modules/c32swidth: New file.
* m4/uchar_h.m4 (gl_UCHAR_H_REQUIRE_DEFAULTS): Initialize
GNULIB_C32SWIDTH.
* modules/uchar (Makefile.am): Substitute GNULIB_C32SWIDTH.
Bruno Haible [Wed, 3 May 2023 15:09:20 +0000 (17:09 +0200)]
vasnprintf, vasnwprintf: Make '0' flag handling more ISO C compliant.
* lib/vasnprintf.c (VASNPRINTF): When doing the padding ourselves,
ignore the '0' flag if a precision is specified and the conversion is
one of d, i, o, u, x, X, b, B.
* tests/test-vasnprintf-posix.c (test_function): Update expected results
accordingly.
* tests/test-vasprintf-posix.c (test_function): Likewise.
* tests/test-snprintf-posix.h (test_function): Likewise.
* tests/test-sprintf-posix.h (test_function): Likewise.
* tests/test-vasnwprintf-posix.c (test_function): Likewise.
Paul Eggert [Mon, 1 May 2023 18:19:05 +0000 (11:19 -0700)]
extern-inline: port to pcc
* m4/extern-inline.m4 (gl_EXTERN_INLINE): Port to pcc
1.2.0.DEVEL 20220331, which doesn’t support extern inline
even though it claims to be GCC 4.3 and to support C11.
Paul Eggert [Mon, 1 May 2023 16:04:15 +0000 (09:04 -0700)]
mktime: prefer C23 style overflow checking
Prefer stdckdint.h macros to intprops.h macros where either will do,
as this is the C23 standard. Also, it ports around a pcc bug.
* config/srclist.txt: Comment out mktime.c.
* lib/mktime.c: Include stdckdint.h, not intprops.h.
(__mktime_internal): Prefer stdckdint.h to intprops.h macros.
* modules/mktime (Depends-on): Add stdckdint.
Paul Eggert [Mon, 1 May 2023 15:11:12 +0000 (08:11 -0700)]
limits-h: port to pcc
* doc/posix-headers/limits.texi: Document the issue.
* lib/limits.in.h (MB_LEN_MAX): New macro, if not already defined.
* m4/limits-h.m4 (gl_LIMITS_H): Test for MB_LEN_MAX.
* tests/test-limits-h.c: Check that it’s positive.
Paul Eggert [Sat, 29 Apr 2023 18:44:13 +0000 (11:44 -0700)]
year2038-recommended: new module
Remove year2038-required and largefile-required, replacing
the former with year2038-recommended and simply removing
the latter. This syncs with Autoconf master.
* MODULES.html.sh, NEWS, doc/largefile.texi:
* all-modules (exclude): Exclude year2038-recommended, not -required.
* doc/posix-headers/sys_types.texi, doc/posix-headers/time.texi:
* doc/year2038.texi: Mention this.
* m4/largefile.m4: Sync from Autoconf. Override existing macros
if AC_SYS_YEAR2038_RECOMMENDED is not defined, rather than if
AC_SYS_LARGEFILE_REQUIRED is not defined.
* modules/largefile-required, modules/year2038-required: Removed.
* modules/year2038: Do not depend on largefile; simply
use m4/largefile.m4, since we shouldn’t need the extra goodies
largefile supplies.
* modules/year2038-recommended: New module.
Bruno Haible [Sat, 29 Apr 2023 01:24:43 +0000 (03:24 +0200)]
stdio: Avoid different configure results in different testdirs.
* m4/stdio_h.m4 (gl_STDIO_H_EARLY): New macro, extracted from
gl_STDIO_H.
(gl_STDIO_H): Move the code that sets __USE_MINGW_ANSI_STDIO to
gl_STDIO_H_EARLY.
* modules/stdio (configure.ac-early): New section.
Bruno Haible [Thu, 27 Apr 2023 23:12:16 +0000 (01:12 +0200)]
localeconv: Work around a mingw bug.
* m4/localeconv.m4 (gl_FUNC_LOCALECONV): Test whether fields of type
'char' are filled correctly.
(gl_PREREQ_LOCALECONV): Test whether 'struct lconv' has the int_{p,n}_*
members.
* lib/localeconv.c (FIX_CHAR_VALUE): New macro.
(localeconv): Replace negative field values with CHAR_MAX.
* doc/posix-functions/localeconv.texi: Mention the mingw bug.
Bruno Haible [Wed, 26 Apr 2023 23:42:25 +0000 (01:42 +0200)]
fdopendir: Fix fd leak and test failure on native Windows.
* lib/dirent-private.h: On mingw, define 'struct gl_directory' as a
wrapper around the original DIR. On MSVC, add an 'fd_to_close' field to
'struct gl_directory'.
* lib/dirent.in.h (DIR): Define when DIR_HAS_FD_MEMBER is 0, i.e. on
both mingw and MSVC.
(GNULIB_defined_DIR): New macro.
(opendir): Avoid incompatible redeclaration.
(readdir): Consider REPLACE_READDIR.
(rewinddir): Consider REPLACE_REWINDDIR.
* m4/dirent_h.m4 (gl_DIRENT_DIR): New macro.
(gl_DIRENT_H): Invoke it.
(gl_DIRENT_H_DEFAULTS): Initialize REPLACE_READDIR, REPLACE_REWINDDIR.
* modules/dirent (Makefile.am): Substitute DIR_HAS_FD_MEMBER,
REPLACE_READDIR, REPLACE_REWINDDIR.
--
* lib/dirfd.c (dirfd): If GNULIB_defined_DIR, just use the
'fd_to_close' field.
* m4/dirfd.m4 (gl_FUNC_DIRFD): Set HAVE_DIRFD. Don't set REPLACE_DIRFD
to 1 if HAVE_DIRFD is 0. If DIR_HAS_FD_MEMBER is 0, ensure dirfd.c gets
compiled.
* modules/dirfd (Files): Add lib/dirent-private.h.
(Depends-on, configure.ac): Simplify conditions.
--
* lib/closedir.c: Include <stdlib.h> always, for free().
(closedir): If GNULIB_defined_DIR, arrange to call close(dirfd(dirp)) at
the end. On mingw, call free() of dirp. Prefer testing HAVE_DIRENT_H,
for consistency with dirent.h.
* m4/closedir.m4 (gl_FUNC_CLOSEDIR): Don't set REPLACE_CLOSEDIR to 1 if
HAVE_CLOSEDIR is 0. If DIR_HAS_FD_MEMBER is 0, ensure closedir.c gets
compiled.
--
* lib/opendir.c: Include <stdlib.h> always. Include <string.h>.
(opendir): On mingw, allocate the 'struct gl_directory' through malloc.
If GNULIB_defined_DIR, set the 'fd_to_close' field to -1. Prefer
testing HAVE_DIRENT_H, for consistency with dirent.h.
* m4/opendir.m4 (gl_FUNC_OPENDIR): Don't set REPLACE_OPENDIR to 1 if
HAVE_OPENDIR is 0. If DIR_HAS_FD_MEMBER is 0, ensure opendir.c gets
compiled.
--
* lib/fdopendir.c (fdopendir): If GNULIB_defined_DIR, use a simple
implementation based on opendir and the fchdir module. If __KLIBC__,
don't define unused auxiliary functions.
* modules/fdopendir (Files): Add lib/dirent-private.h.
--
* lib/readdir.c (readdir): On mingw, redirect to the original readdir
function. Prefer testing HAVE_DIRENT_H, for consistency with dirent.h.
* m4/readdir.m4 (gl_FUNC_READDIR): If DIR_HAS_FD_MEMBER is 0, ensure
readdir.c gets compiled.
* modules/readdir (configure.ac): Consider REPLACE_READDIR.
--
* lib/rewinddir.c (rewinddir): On mingw, redirect to the original
rewinddir function. Prefer testing HAVE_DIRENT_H, for consistency with
dirent.h.
* m4/rewinddir.m4 (gl_FUNC_REWINDDIR): If DIR_HAS_FD_MEMBER is 0, ensure
rewinddir.c gets compiled.
* modules/rewinddir (configure.ac): Consider REPLACE_REWINDDIR.
--
* lib/fchdir.c (dir_info_t): Remove a FIXME.
Po Lu [Wed, 26 Apr 2023 02:57:31 +0000 (04:57 +0200)]
gnulib-tool: For conditional dependencies, generate portable sh code.
* gnulib-tool (func_emit_autoconf_snippets): Avoid sh syntax
'if ! variable', that does not work with Solaris /bin/sh.
* pygnulib/GLEmiter.py (GLEmiter.autoconfSnippets): Likewise.
Bruno Haible [Tue, 25 Apr 2023 11:38:47 +0000 (13:38 +0200)]
poll tests: Avoid test failure on native Windows.
* tests/test-poll.c (test_pipe): Disable the POLLHUP check also on
native Windows.
* doc/posix-functions/poll.texi: Mention also native Windows w.r.t.
POLLHUP.
Paul Eggert [Mon, 24 Apr 2023 19:06:55 +0000 (12:06 -0700)]
fclose: pacify gcc -Wanalyzer-file-leak
Without this patch, building coreutils with
--enable-gcc-checking=expensive would fail with a message like
“lib/exclude.c:682:6: error: leak of FILE 'in' [CWE-775]
[-Werror=analyzer-file-leak]”, because Gnulib replaced fclose but
not fopen, and GCC saw a call to fopen followed by a call to
rpl_fclose. The patch causes GCC to instead see a call to
rpl_fopen followed by rpl_fclose.
* m4/fclose.m4 (gl_FUNC_FCLOSE): Replace fopen when replacing
fclose.
* modules/fclose (Depends-on): Add fopen.
(configure.ac): Replace fopen when replacing fclose.
* tests/test-unsetenv.c (main): Make entry static. Even with this
change, it’s unclear whether this test is portable POSIX code, but
that’s a different matter.
Bruno Haible [Mon, 24 Apr 2023 10:48:31 +0000 (12:48 +0200)]
unicodeio tests: Avoid test failures on native Windows.
* tests/test-unicodeio.c: Include localcharset.h.
(main): Handle C locales whose encoding is CP1252 or similar.
* modules/unicodeio-tests (Depends-on): Add localcharset.
Paul Eggert [Sun, 23 Apr 2023 15:53:59 +0000 (08:53 -0700)]
manywarnings: update C warnings for GCC 13
Adjust for C programs compiled by GCC 13.
(A C++ expert still needs to look at manywarnings-c++.m4.)
* build-aux/gcc-warning.spec: Add warnings introduced in GCC 13.
* doc/manywarnings.texi (manywarnings): Document flex arrays.
* m4/manywarnings.m4 (gl_MANYWARN_ALL_GCC): Add
-fstrict-flex-arrays and -Wstrict-flex-arrays as these should be
suitable for Gnulib-using code.
Bruno Haible [Sat, 22 Apr 2023 15:38:28 +0000 (17:38 +0200)]
string-desc tests: Avoid test failure on native Windows.
* tests/test-string-desc.c: Include <fcntl.h>, <unistd.h>.
(main): Expect a file name argument. Write to this file, instead of to
fd 3.
* tests/test-string-desc.sh: Pass a file name as argument, instead of
using '3>'.
* modules/string-desc-tests (Depends-on): Add close.
Bruno Haible [Sat, 22 Apr 2023 11:47:15 +0000 (13:47 +0200)]
dfa tests: Fix test failure on mingw differently.
Suggested by Paul Eggert.
* tests/test-dfa-invalid-char-class.sh: Revert last change.
* tests/test-dfa-match-aux.c: Include binary-io.h.
(main): Put stdout into binary mode.
* modules/dfa-tests (Depends-on): Add binary-io.
Bruno Haible [Thu, 20 Apr 2023 12:21:09 +0000 (14:21 +0200)]
Move remaining call_once tests from mtx-tests to call_once-tests.
* tests/test-call_once1.c: Renamed from tests/test-call_once.c.
* tests/test-call_once2.c: New file, based on tests/test-mtx.c.
* tests/test-mtx.c: Remove the code that was testing call_once.
* modules/call_once-tests (Files): Add test-call_once1.c,
test-call_once2.c. Remove test-call_once.c.
(Depends-on): Add thrd, lock, stdint.
(configure.ac): Check for alarm.
(Makefile.am): Test test-call_once1 instead of test-call_once. Also test
test-call_once2.
Bruno Haible [Thu, 20 Apr 2023 06:42:56 +0000 (08:42 +0200)]
assert-h, verify: Fix compilation error in C++ mode with MSVC 14.30.
* lib/verify.h (_Static_assert): In C++ mode with MSVC 14.1 or newer,
define merely to static_assert.
(static_assert): In C++ mode with MSVC 14.1 or newer, don't define.
Bruno Haible [Wed, 19 Apr 2023 21:20:54 +0000 (14:20 -0700)]
year2038-required: Fix configure failure with MSVC.
* m4/largefile.m4 (_AC_SYS_LARGEFILE_PROBE): Distinguish the results
"support not detected" and "supported through gnulib". If the result is
"supported through gnulib", don't fail.
Bruno Haible [Wed, 19 Apr 2023 15:59:03 +0000 (17:59 +0200)]
wcsncmp: Work around two ISO C compliance bugs on several platforms.
* lib/wchar.in.h (wcsncmp): Consider REPLACE_WCSNCMP.
* lib/wcsncmp-impl.h (wcsncmp): Don't assume that the two wide
characters are in the range 0..INT_MAX.
* m4/wcsncmp.m4 (gl_FUNC_WCSNCMP): Test whether wcsncmp works for all
wide characters. Set REPLACE_WCSNCMP.
* m4/wchar_h.m4 (gl_WCHAR_H_DEFAULTS): Initialize REPLACE_WCSNCMP.
* modules/wchar (Makefile.am): Substitute REPLACE_WCSNCMP.
* modules/wcsncmp (Status, Notice): Un-obsolete this module.
(configure.ac): Consider REPLACE_WCSNCMP.
* doc/posix-functions/wcsncmp.texi: Mention the two bugs.
Bruno Haible [Wed, 19 Apr 2023 00:14:09 +0000 (02:14 +0200)]
wcscmp: Work around two ISO C compliance bugs on several platforms.
* lib/wchar.in.h (wcscmp): Consider REPLACE_WCSCMP.
* lib/wcscmp-impl.h (wcscmp): Don't assume that the two wide characters
are in the range 0..INT_MAX.
* m4/wcscmp.m4 (gl_FUNC_WCSCMP): Test whether wcscmp works for all wide
characters. Set REPLACE_WCSCMP.
* m4/wchar_h.m4 (gl_WCHAR_H_DEFAULTS): Initialize REPLACE_WCSCMP.
* modules/wchar (Makefile.am): Substitute REPLACE_WCSCMP.
* modules/wcscmp (Status, Notice): Un-obsolete this module.
(configure.ac): Consider REPLACE_WCSCMP.
* doc/posix-functions/wcscmp.texi: Mention the two bugs.
Bruno Haible [Tue, 18 Apr 2023 23:01:56 +0000 (01:01 +0200)]
wmemcmp: Work around ISO C compliance bug on several platforms.
* lib/wchar.in.h (wmemcmp): Consider REPLACE_WMEMCMP.
* lib/wmemcmp-impl.h (wmemcmp): Don't assume that the two wide
characters are in the range 0..INT_MAX.
* m4/wmemcmp.m4 (gl_FUNC_WMEMCMP): Test whether wmemcmp works for all
wide characters. Set REPLACE_WMEMCMP.
* m4/wchar_h.m4 (gl_WCHAR_H_DEFAULTS): Initialize REPLACE_WMEMCMP.
* modules/wchar (Makefile.am): Substitute REPLACE_WMEMCMP.
* modules/wmemcmp (configure.ac): Consider REPLACE_WMEMCMP.
* doc/posix-functions/wmemcmp.texi: Mention the bug.
Paul Eggert [Tue, 18 Apr 2023 21:25:09 +0000 (14:25 -0700)]
Go back to dynamic largefile, year2038 tests
Problem reported by Bruno Haible in:
https://lists.gnu.org/r/bug-gnulib/2023-04/msg00134.html
* modules/largefile-tests, modules/year2038-tests (Depends-on):
Remove assert-h.
* tests/test-largefile.c, tests/test-year2038.c:
Test dynamically, not via static_assert.