Bruno Haible [Sat, 2 Jan 2021 15:54:21 +0000 (16:54 +0100)]
renameatu: Fix test failures on macOS.
Reported by Martin Storsjö <martin@martin.st> in
<https://lists.gnu.org/archive/html/bug-gnulib/2020-12/msg00003.html>.
* lib/renameatu.c (renameatu): Don't call renameatx_np right away.
Instead, treat it as a variant of renameat, with all possible bugs that
renameat might have.
Bruno Haible [Fri, 1 Jan 2021 23:14:05 +0000 (00:14 +0100)]
time: Define TIME_UTC.
* lib/time.in.h (TIME_UTC, GNULIB_defined_TIME_UTC): New macros.
* m4/time_h.m4 (gl_HEADER_TIME_H_BODY): Set TIME_H_DEFINES_TIME_UTC.
* modules/time (Makefile.am): Substitute TIME_H_DEFINES_TIME_UTC.
* tests/test-time.c: Check that TIME_UTC is defined and a positive
integer.
* doc/posix-headers/time.texi: Mention TIME_UTC.
* lib/canonicalize-lgpl.c, lib/canonicalize.c (NARROW_ADDRESSES):
Remove, and remove all uses, as the optimization is arguably not
worth the extra complexity. Suggested by Adhemerval Zanella in:
https://sourceware.org/pipermail/libc-alpha/2020-December/121203.html
Paul Eggert [Fri, 1 Jan 2021 17:27:54 +0000 (09:27 -0800)]
libc-config: port to Sun C 5.9
* lib/libc-config.h (libc_hidden_proto): Omit ", ..." in macro
definition. It’s not needed for Gnulib and elicits a diagnostic
from Sun C 5.9 Patch 124867-12 2009/11/22.
Bruno Haible [Fri, 1 Jan 2021 14:00:48 +0000 (15:00 +0100)]
quotearg tests: Avoid test failures on Solaris 11.
* modules/quotearg-tests (Makefile.am): Set host_os in
TESTS_ENVIRONMENT.
* tests/test-quotearg.sh: On Solaris 11 systems, make a copy of the fr/
directory that contains the .mo file.
Paul Eggert [Thu, 31 Dec 2020 21:35:53 +0000 (13:35 -0800)]
fnmatch: merge from glibc + proposal
This merges the change proposed by Adhemerval Zanella in:
https://sourceware.org/pipermail/libc-alpha/2020-December/121212.html
which fixes a Gnulib bug that led to a failed assert.
* lib/fnmatch_loop.c (EXT): Use signed level, not unsigned, and
check that it stays nonnegative. Use __flexarr instead of
FLEXIBLE_ARRAY_MEMBER, to port better to glibc.
* tests/test-fnmatch.c (main): New test cases, taken from glibc.
Bruno Haible [Thu, 31 Dec 2020 21:16:52 +0000 (22:16 +0100)]
malloc-h: New module.
* lib/malloc.in.h: New file.
* m4/malloc_h.m4: New file.
* modules/malloc-h: New file.
* doc/glibc-headers/malloc.texi: New file.
* doc/gnulib.texi (Glibc Header File Substitutes): Include it.
Jim Meyering [Wed, 30 Dec 2020 04:00:36 +0000 (20:00 -0800)]
regex-tests: tweak to avoid a clang-10 warning
* tests/test-regex.c: Compare with explicit zero, rather than
as boolean to avoid this from clang-10:
test-regex.c:315:9: error: converting the result of '<<' to a \
boolean always evaluates to true \
[-Werror,-Wtautological-constant-compare]
if (! REG_STARTEND)
Jim Meyering [Wed, 30 Dec 2020 03:34:55 +0000 (19:34 -0800)]
hash: add casts-to-float to avoid clang-10 warnings
* lib/hash.c (compute_bucket_size): Cast SIZE_MAX to float
to avoid this warning from clang-10 (for use in grep):
hash.c:501:11: error: implicit conversion from 'unsigned long' \
to 'float' changes value from 18446744073709551615 to \ 18446744073709551616 [-Werror,-Wimplicit-int-float-conversion]
if (SIZE_MAX <= new_candidate)
(hash_insert_if_absent): Likewise.
Paul Eggert [Wed, 30 Dec 2020 03:34:59 +0000 (19:34 -0800)]
canonicalize: fix size overflow treatment
This also has some minor cleanups.
* lib/canonicalize-lgpl.c, lib/canonicalize.c: No need to include
stddef.h, since the code no longer refers directly to ptrdiff_t.
* lib/canonicalize-lgpl.c (realpath_stk):
* lib/canonicalize.c (canonicalize_filename_mode_stk):
Treat size overflow like other out-of-memory.
* lib/canonicalize.c: No need to include stdlib.h, since
the code no longer refers to stdlib.h functions (other
than those that canonicalize.h must declare).
* lib/canonicalize.c (canonicalize_filename_mode_stk):
Do not bother terminating the string result on error.
Paul Eggert [Wed, 30 Dec 2020 01:08:11 +0000 (17:08 -0800)]
canonicalize: fix ptrdiff_t overflow bug
Problem reported by Adhemerval Zanella in:
https://sourceware.org/pipermail/libc-alpha/2020-December/121182.html
* lib/canonicalize-lgpl.c, lib/canonicalize.c:
Include intprops.h.
(NARROW_ADDRESSES): New constant.
* lib/canonicalize-lgpl.c (realpath_stk):m
* lib/canonicalize.c (canonicalize_filename_mode_stk):
Work even if strlen (END) does not fit in idx_t, or if adding
N to it overflows.
* modules/canonicalize, modules/canonicalize-lgpl (Depends-on):
Add intprops.
Bruno Haible [Tue, 29 Dec 2020 01:48:31 +0000 (02:48 +0100)]
gnulib-tool: Fix logic whether to add a dummy.c.
* gnulib-tool (func_remove_if_blocks): New function.
(func_modules_add_dummy): Use it to eliminate all conditional statements
from the automake snippet.
Paul Eggert [Mon, 28 Dec 2020 20:38:52 +0000 (12:38 -0800)]
faccessat: revert recent EOVERFLOW change
I misunderstood the glibc source code. Deduced from
Adhemerval Zanella’s proposed glibc patch in:
https://sourceware.org/pipermail/libc-alpha/2020-December/121131.html
* doc/posix-functions/faccessat.texi: It is not a problem.
* lib/canonicalize-lgpl.c, lib/canonicalize.c, lib/faccessat.c:
(FACCESSAT_NEVER_OVERFLOWS): Remove. All uses removed.
* lib/faccessat.c: Revert to simpler version now that
LSTAT_FOLLOWS_SLASHED_SYMLINK must be false.
* m4/faccessat.m4 (gl_FUNC_FACCESSAT_EOVERFLOW):
Remove. All uses removed.
* modules/canonicalize, modules/canonicalize-lgpl (Files):
Remove m4/faccessat.m4.
Paul Eggert [Mon, 28 Dec 2020 19:58:38 +0000 (11:58 -0800)]
canonicalize-lgpl: accommodate picky cpp
* lib/canonicalize-lgpl.c: Use "defined FUNC_REALPATH_WORKS" in
case preprocessor is picky. Reported by Adhemerval Zanella in:
https://sourceware.org/pipermail/libc-alpha/2020-December/121130.html
Paul Eggert [Sun, 27 Dec 2020 19:22:11 +0000 (11:22 -0800)]
regex: remove glibc21.m4
It doesn’t seem to be needed any more; at least, I couldn’t
reproduce the circa-2013 problem. Perhaps the recent
--conditional-dependencies fixes have removed the need for it.
* m4/glibc21.m4: Remove. All uses removed.
Bruno Haible [Sat, 26 Dec 2020 13:42:38 +0000 (14:42 +0100)]
execlp: New module.
* lib/execlp.c: New file.
* m4/execlp.m4: New file.
* modules/execlp: New file.
* doc/posix-functions/execlp.texi: Mention more Windows problems and the
new module.
Bruno Haible [Sat, 26 Dec 2020 13:39:39 +0000 (14:39 +0100)]
execle: New module.
* lib/execle.c: New file.
* m4/execle.m4: New file.
* modules/execle: New file.
* doc/posix-functions/execle.texi: Mention more Windows problems and the
new module.
Bruno Haible [Sat, 26 Dec 2020 13:36:35 +0000 (14:36 +0100)]
execl: New module.
* lib/execl.c: New file.
* m4/execl.m4: New file.
* modules/execl: New file.
* doc/posix-functions/execl.texi: Mention more Windows problems and the
new module.
Bruno Haible [Sat, 26 Dec 2020 13:31:50 +0000 (14:31 +0100)]
execv: New module.
* lib/execv.c: New file.
* m4/execv.m4: New file.
* modules/execv: New file.
* doc/posix-functions/execv.texi: Mention more Windows problems and the
new module.
Bruno Haible [Sat, 26 Dec 2020 13:28:16 +0000 (14:28 +0100)]
execvp: New module.
* lib/execvp.c: New file.
* m4/execvp.m4: New file.
* modules/execvp: New file.
* doc/posix-functions/execvp.texi: Mention more Windows problems and the
new module.
Bruno Haible [Sat, 26 Dec 2020 13:23:10 +0000 (14:23 +0100)]
execvpe: New module.
* lib/execvpe.c: New file.
* m4/execvpe.m4: New file.
* modules/execvpe: New file.
* doc/glibc-functions/execvpe.texi: Mention the Windows problems and the
new module.
Bruno Haible [Sat, 26 Dec 2020 13:13:03 +0000 (14:13 +0100)]
execve: New module.
* lib/execve.c: New file.
* m4/execve.m4: New file.
* modules/execve: New file.
* doc/posix-functions/execve.texi: Mention more Windows problems and the
new module.
Paul Eggert [Sat, 26 Dec 2020 01:26:51 +0000 (17:26 -0800)]
idx: change idx.h comment to LGPLv2.1+
* lib/idx.h: Change license notice to match what should be in glibc.
gnulib-tool will change it as appropriate anyway, so this is just
to simplify syncing with glibc.
Paul Eggert [Fri, 25 Dec 2020 05:33:18 +0000 (21:33 -0800)]
canonicalize, canonicalize-lgpl: remove lint
Pacify GCC. Some of these problems were reported by Bruno Haible in:
https://lists.gnu.org/r/bug-gnulib/2020-12/msg00217.html
* lib/canonicalize-lgpl.c, lib/canonicalize.c:
Sort shared include directives, for consistency.
(IF_LINT): New macro.
(suffix_requires_dir_check): Mark with _GL_ATTRIBUTE_PURE.
* lib/canonicalize-lgpl.c (GCC_LINT, _GL_ATTRIBUTE_PURE) [_LIBC]:
New macros.
(realpath_stk): Suppress bogus -Wmaybe-uninitialized warning.
* lib/canonicalize.c (canonicalize_filename_mode_stk):
Omit unused local. Suppress bogus -Wmaybe-uninitialized warning.
Bruno Haible [Fri, 25 Dec 2020 01:16:22 +0000 (02:16 +0100)]
spawn-pipe: Use posix_spawn by default on native Windows.
* lib/spawn-pipe.c (SPAWN_PIPE_IMPL_AVOID_POSIX_SPAWN): New macro.
(create_pipe): Use it to decide among the two possible implementations.
* modules/spawn-pipe (Depends-on): Add posix_spawnattr_setpgroup.
Paul Eggert [Thu, 24 Dec 2020 22:47:31 +0000 (14:47 -0800)]
canonicalize-lgpl: merge proposed libc changes
This merges the changes proposed for glibc in:
https://sourceware.org/pipermail/libc-alpha/2020-December/121085.html
https://sourceware.org/pipermail/libc-alpha/2020-December/121086.html
* lib/canonicalize-lgpl.c: Include idx.h and filename.h
unconditionally.
(idx_t, IDX_MAX, FILE_SYSTEM_PREFIX_LEN, IS_ABSOLUTE_FILE_NAME)
(ISSLASH) [_LIBC]: Remove.
Bruno Haible [Thu, 24 Dec 2020 21:18:27 +0000 (22:18 +0100)]
windows-spawn: Export another auxiliary function.
* lib/windows-spawn.h (convert_CreateProcess_error): New declaration.
* lib/windows-spawn.c (convert_CreateProcess_error): New function,
extracted from spawnpvech.
(spawnpvech): Use it.
Bruno Haible [Thu, 24 Dec 2020 21:18:21 +0000 (22:18 +0100)]
windows-spawn: Export some more auxiliary functions.
* lib/windows-spawn.h: Include <stdbool.h>.
(struct inheritable_handles): New type.
(init_inheritable_handles, compose_handles_block,
free_inheritable_handles): New declarations.
* lib/windows-spawn.c (init_inheritable_handles, compose_handles_block):
New functions, based on spawnvech.
(free_inheritable_handles): New function.
(spawnpvech): Use them.
Bruno Haible [Thu, 24 Dec 2020 21:18:18 +0000 (22:18 +0100)]
windows-spawn: Export another auxiliary function.
* lib/windows-spawn.h (compose_envblock): New declaration.
* lib/windows-spawn.c (compose_envblock): New function, extracted from
spawnpvech.
(spawnpvech): Use it.
Bruno Haible [Thu, 24 Dec 2020 21:18:10 +0000 (22:18 +0100)]
windows-spawn: Export an auxiliary function.
* lib/windows-spawn.h (compose_command): New declaration.
* lib/windows-spawn.c (compose_command): New function, extracted from
spawnpvech.
(spawnpvech): Use it.
Paul Eggert [Thu, 24 Dec 2020 19:38:48 +0000 (11:38 -0800)]
linkat: use eloop-threshold
* lib/linkat.c: Include eloop-threshold.h.
Do not include sys/param.h.
(MAXSYMLINKS): Remove.
(link_follow, linkat_follow): Use __eloop_threshold instead
of MAXSYMLINKS.
* m4/linkat.m4 (gl_FUNC_LINKAT): Omit sys/param.h check.
* modules/linkat (Depends-on): Add eloop-threshold. Sort.
Paul Eggert [Thu, 24 Dec 2020 19:38:48 +0000 (11:38 -0800)]
canonicalize: prefer faccessat to stat
A proper faccessat doesn't have the EOVERFLOW problem, and can be
more efficient as it needn't gather data from the filesystem to
fill in struct stat. So use stat only if faccessat is absent,
or when checking for symlink loops in canonicalize.c.
* lib/canonicalize-lgpl.c, lib/canonicalize.c:
Include fcntl.h, for AT_EACCESS.
(FACCESSAT_NEVER_EOVERFLOWS): Default to false.
(file_accessible): New function, based on faccessat but with
a fallback to stat and with an EOVERFLOW workaround.
(dir_check): Use it.
(dir_suffix): New static constant.
* lib/canonicalize-lgpl.c (FACCESSAT_NEVER_EOVERFLOWS) [_LIBC]:
Use __ASSUME_FACCESSAT2 to set FACCESSAT_NEVER_EOVERFLOWS
(__faccessat) [!_LIBC]: Define.
(realpath_stk): Use dir_suffix now.
* lib/canonicalize.c (canonicalize_filename_mode_stk):
If logical, don't check each component's existence; just check
at the end, as that's enough.
* m4/canonicalize.m4 (gl_FUNC_CANONICALIZE_FILENAME_MODE)
(gl_CANONICALIZE_LGPL_SEPARATE):
Require gl_FUNC_FACCESSAT_EOVERFLOW,
gl_FUNC_LSTAT_FOLLOWS_SLASHED_SYMLINK, and check for faccessat.
(gl_CANONICALIZE_LGPL_SEPARATE): Do not check for readlink,
as the code does not use HAVE_READLINK.
* modules/canonicalize, modules/canonicalize-lgpl (Files):
Add m4/faccessat.m4, m4/lstat.m4.
(Depends-on): Add fcntl-lh.
Paul Eggert [Thu, 24 Dec 2020 19:38:48 +0000 (11:38 -0800)]
faccessat: work around F_OK EOVERFLOW bug
Also, tune when LSTAT_FOLLOWS_SLASHED_SYMLINK.
* doc/posix-functions/faccessat.texi: Mention the problem.
* lib/faccessat.c (FACCESSAT_NEVER_EOVERFLOWS)
(LSTAT_FOLLOWS_SLASHED_SYMLINK): Default to 0.
(rpl_faccessat): If !FACCESSAT_NEVER_EOVERFLOWS, check
for F_OK and EOVERFLOW, which means we can return 0.
If LSTAT_FOLLOWS_SLASHED_SYMLINK, don't worry about
file names ending in slashes, as faccessat should already
do the right thing for them.
* m4/faccessat.m4 (gl_FUNC_FACCESSAT_EOVERFLOW): New macro.
(gl_FUNC_FACCESSAT): Use it.
Paul Eggert [Thu, 24 Dec 2020 19:38:48 +0000 (11:38 -0800)]
stat failing with EOVERFLOW implies existence
* lib/euidaccess.c (euidaccess):
* lib/file-has-acl.c (file_has_acl):
* lib/link.c (link, rpl_link):
* lib/mkdir.c (rpl_mkdir):
* lib/mkfifo.c (rpl_mkfifo):
* lib/mknod.c (rpl_mknod):
* lib/ptsname_r.c (__ptsname_r):
* lib/symlink.c (rpl_symlink):
* lib/symlinkat.c (rpl_symlinkat):
* lib/unlink.c (rpl_unlink):
* lib/unlinkat.c (rpl_unlinkat):
* lib/utime.c (utime):
If stat fails with EOVERFLOW the file exists, so treat it that way
in file-existence tests that do not need struct stat values.
Paul Eggert [Thu, 24 Dec 2020 19:38:47 +0000 (11:38 -0800)]
canonicalize, canonicalize-lgpl: fix symlink bug
Problem reported by Adhemerval Zanella in:
https://lists.gnu.org/r/bug-gnulib/2020-12/msg00155.html
* lib/canonicalize-lgpl.c, lib/canonicalize.c:
(suffix_requires_dir_check, dir_check): New functions.
(GCC_BOGUS_WRETURN_LOCAL_ADDR): New macro, to put the diagnostic
closer to the related GCC diagnostics.
* lib/canonicalize-lgpl.c (realpath_stk):
* lib/canonicalize.c (canonicalize_file_mode_stk):
Use them to fix a bug with .../symlink-to-regular-file/ etc.
* lib/canonicalize-lgpl.c (__stat) [!_LIBC]: New macro.
(realpath_stk): New function,
with the contents of the old __realpath and a new scratch buffer arg.
This is needed to pacify GCC 10.1, as canonicalize.c is already doing.
(__realpath): Use it.
* tests/test-canonicalize-lgpl.c, tests/test-canonicalize.c:
Add test cases for the bugs.
Bruno Haible [Thu, 24 Dec 2020 18:04:57 +0000 (19:04 +0100)]
execute: Treat signalled processes like wait-process does.
* lib/execute.c: Include <sys/types.h>, <sys/wait.h>.
(execute): Recognize the case where the exit code indicates a signalled
child process.
* tests/test-execute-main.c (main): Update expected test result.
* modules/execute (Depends-on): Add sys_wait.
Bruno Haible [Thu, 24 Dec 2020 12:32:39 +0000 (13:32 +0100)]
findprog-in: Improve errno upon failure on native Windows.
* lib/findprog-in.c (find_in_given_path): If the file basename has no
dot and the search with a suffix returned no result, do also a search
without a suffix, and set errno = ENOEXEC if we find a file in this way.
* tests/test-spawn-pipe-script.c (main): Update expected errno.
Bruno Haible [Thu, 24 Dec 2020 02:49:20 +0000 (03:49 +0100)]
posix_spawn, posix_spawnp: Fix execution of scripts.
* m4/posix_spawn.m4 (gl_POSIX_SPAWN_SECURE): New macro.
(gl_POSIX_SPAWN_BODY): Invoke it. Set REPLACE_POSIX_SPAWN if posix_spawn
or posix_spawnp allows unsecure execution of scripts.
* doc/posix-functions/posix_spawn.texi: Document the script execution
problem.
* doc/posix-functions/posix_spawnp.texi: Likewise.
Bruno Haible [Wed, 23 Dec 2020 22:58:17 +0000 (23:58 +0100)]
Don't execute scripts without '#!' marker through /bin/sh.
This reflects the change done in glibc through
<https://sourceware.org/bugzilla/show_bug.cgi?id=13134> and
<https://sourceware.org/git/?p=glibc.git;a=commitdiff;h=d96de9634a334af16c0ac711074c15ac1762b23c>.
* lib/spawni.c (internal_function): Remove macro.
(script_execute): Remove function.
(__spawni): Don't invoke script_execute.
* lib/execute.c (execute): Disable the ENOEXEC handling.
* lib/spawn-pipe.c (create_pipe): Likewise.
* NEWS: Mention the change.