]> Savannah Git Hosting - gnulib.git/log
gnulib.git
4 years agocanonicalize: fix ptrdiff_t overflow bug
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.

4 years agohavelib: Fix for Solaris 11 OpenIndiana and Solaris 11 OmniOS.
Bruno Haible [Tue, 29 Dec 2020 03:00:53 +0000 (04:00 +0100)]
havelib: Fix for Solaris 11 OpenIndiana and Solaris 11 OmniOS.

* m4/lib-prefix.m4 (AC_LIB_PREPARE_MULTILIB): In
acl_is_expected_elfclass, use 'expr', not 'test'.

4 years agoptsname_r: Fix a compiler warning on Solaris.
Bruno Haible [Tue, 29 Dec 2020 02:05:25 +0000 (03:05 +0100)]
ptsname_r: Fix a compiler warning on Solaris.

* lib/ptsname_r.c (__ptsname_r): Reduce the scope of variable 'err'.

4 years agognulib-tool: Fix logic whether to add a dummy.c.
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.

4 years agofaccessat: revert recent EOVERFLOW change
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.

4 years agocanonicalize-lgpl: accommodate picky cpp
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

4 years agocanonicalize: simplify via scratch_buffer_dupfree
Paul Eggert [Mon, 28 Dec 2020 19:38:58 +0000 (11:38 -0800)]
canonicalize: simplify via scratch_buffer_dupfree

* config/srclist.txt: Adjust accordingly.
* lib/canonicalize-lgpl.c (realpath_stk):
* lib/canonicalize.c (canonicalize_filename_mode_stk):
Simplify by using scratch_buffer_dupfree.
* lib/malloc/scratch_buffer.h (scratch_buffer_dupfree): New function.
* lib/malloc/scratch_buffer_dupfree.c: New file.
* modules/scratch_buffer (Files, Depends-on):
Add malloc/scratch_buffer_dupfree.c.

4 years agoregex: remove glibc21.m4
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.

4 years agognulib-tool: Make --conditional-dependencies work with --with-tests.
Bruno Haible [Sun, 27 Dec 2020 00:21:22 +0000 (01:21 +0100)]
gnulib-tool: Make --conditional-dependencies work with --with-tests.

Reported by Paul Eggert in
<https://lists.gnu.org/archive/html/bug-gnulib/2020-12/msg00236.html>.

* gnulib-tool (func_emit_tests_Makefile_am): Handle conditional
dependencies like func_emit_lib_Makefile_am.

4 years agoexecvpe: Make dependency to stdbool explicit.
Bruno Haible [Sat, 26 Dec 2020 16:02:03 +0000 (17:02 +0100)]
execvpe: Make dependency to stdbool explicit.

* lib/execvpe.c: Include <stdbool.h>.
* modules/execvpe (Depends-on): Add stdbool.

4 years agoexeclp: Add tests.
Bruno Haible [Sat, 26 Dec 2020 13:43:58 +0000 (14:43 +0100)]
execlp: Add tests.

* tests/test-execlp-main.c: New file.
* tests/test-execlp.sh: New file.
* modules/execlp-tests: New file.

4 years agoexeclp: New module.
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.

4 years agoexecle: Add tests.
Bruno Haible [Sat, 26 Dec 2020 13:40:49 +0000 (14:40 +0100)]
execle: Add tests.

* tests/test-execle-main.c: New file.
* tests/test-execle.sh: New file.
* modules/execle-tests: New file.

4 years agoexecle: 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.

4 years agoexecl: Add tests.
Bruno Haible [Sat, 26 Dec 2020 13:37:54 +0000 (14:37 +0100)]
execl: Add tests.

* tests/test-execl-main.c: New file.
* tests/test-execl.sh: New file.
* modules/execl-tests: New file.

4 years agoexecl: 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.

4 years agoexecv: Add tests.
Bruno Haible [Sat, 26 Dec 2020 13:33:33 +0000 (14:33 +0100)]
execv: Add tests.

* tests/test-execv-main.c: New file.
* tests/test-execv.sh: New file.
* modules/execv-tests: New file.

4 years agoexecv: 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.

4 years agoexecvp: Add tests.
Bruno Haible [Sat, 26 Dec 2020 13:29:56 +0000 (14:29 +0100)]
execvp: Add tests.

* tests/test-execvp-main.c: New file.
* tests/test-execvp.sh: New file.
* modules/execvp-tests: New file.

4 years agoexecvp: 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.

4 years agoexecvpe: Add tests.
Bruno Haible [Sat, 26 Dec 2020 13:25:06 +0000 (14:25 +0100)]
execvpe: Add tests.

* tests/test-execvpe-main.c: New file.
* tests/test-execvpe.sh: New file.
* modules/execvpe-tests: New file.

4 years agoexecvpe: 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.

4 years agoexecve: Add tests.
Bruno Haible [Sat, 26 Dec 2020 13:19:29 +0000 (14:19 +0100)]
execve: Add tests.

* tests/test-exec-child.c: New file.
* tests/test-execve-main.c: New file.
* tests/test-execve.sh: New file.
* modules/execve-tests: New file.

4 years agoexecve: 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.

4 years agoexecve, execvpe, execvp, execv, execl, execle, execlp: Prepare modules.
Bruno Haible [Sat, 26 Dec 2020 13:09:29 +0000 (14:09 +0100)]
execve, execvpe, execvp, execv, execl, execle, execlp: Prepare modules.

* lib/unistd.in.h (execl, execle, execlp, execv, execve, execvp,
execvpe): Add declarations for the new modules.
* m4/unistd_h.m4 (gl_UNISTD_H): Test whether execl, execle, execlp,
execv, execve, execvp, execvpe are declared.
(gl_UNISTD_H_DEFAULTS): Initialize GNULIB_EXEC*, HAVE_EXECVPE,
REPLACE_EXEC*.
* modules/unistd (Makefile.am): Substitute GNULIB_EXEC*, HAVE_EXECVPE,
REPLACE_EXEC*.
* tests/test-unistd-c++.cc: Check the signature of execl, execle,
execlp, execv, execve, execvp, execvpe.

4 years agostack: Fix typo in comments.
Bruno Haible [Sat, 26 Dec 2020 12:54:09 +0000 (13:54 +0100)]
stack: Fix typo in comments.

* lib/stack.h: Fix typo in comments.

4 years agobitset: Fix conflict with 'free-posix' module.
Bruno Haible [Sat, 26 Dec 2020 12:48:37 +0000 (13:48 +0100)]
bitset: Fix conflict with 'free-posix' module.

* lib/bitset/base.h: Include <stdlib.h>.

4 years agoidx: change idx.h comment to LGPLv2.1+
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.

4 years agoMODULES.html.sh: Update after 2020-12-19 change.
Thien-Thi Nguyen [Fri, 25 Dec 2020 23:27:37 +0000 (18:27 -0500)]
MODULES.html.sh: Update after 2020-12-19 change.

* MODULES.html.sh (func_all_modules): Do s/free/free-posix/.

4 years agoMake it possible to turn off the mkdir override on Windows.
Bruno Haible [Fri, 25 Dec 2020 17:39:47 +0000 (18:39 +0100)]
Make it possible to turn off the mkdir override on Windows.

* lib/sys_stat.in.h (mkdir): Conditionalize through GNULIB_MKDIR and
GNULIB_MDA_MKDIR. Also support GNULIB_POSIXCHECK.
* m4/sys_stat_h.m4 (gl_SYS_STAT_H_DEFAULTS): Initialize GNULIB_MKDIR,
GNULIB_MDA_MKDIR.
* modules/sys_stat (Makefile.am): Substitute GNULIB_MKDIR,
GNULIB_MDA_MKDIR.
* modules/mkdir (configure.ac): Invoke gl_SYS_STAT_MODULE_INDICATOR.
* doc/posix-functions/mkdir.texi: Mention also the 'sys_stat' module.

4 years agoMake it possible to turn off each of the Windows oldnames workarounds.
Bruno Haible [Fri, 25 Dec 2020 12:48:17 +0000 (13:48 +0100)]
Make it possible to turn off each of the Windows oldnames workarounds.

* lib/fcntl.in.h (creat, open):  Conditionalize each of the Windows
oldnames workarounds through a GNULIB_MDA_<func> symbol.
* lib/math.in.h (j0, j1, jn, y0, y1, yn): Likewise.
* lib/search.in.h (lfind, lsearch): Likewise.
* lib/stdio.in.h (fcloseall, fdopen, fileno, getw, putw, tempnam):
Likewise.
* lib/stdlib.in.h (ecvt, fcvt, gcvt, mktemp, putenv): Likewise.
* lib/string.in.h (memccpy, strdup): Likewise.
* lib/sys_stat.in.h (chmod, umask): Likewise.
* lib/time.in.h (tzset): Likewise.
* lib/unistd.in.h (access, chdir, close, dup, dup2, execl, execle,
execlp, execv, execve, execvp, execvpe, getcwd, getpid, isatty, lseek,
read, rmdir, swab, unlink, write): Likewise.
* lib/utime.in.h (utime): Likewise.
* lib/wchar.in.h (wcsdup): Likewise.
* m4/fcntl_h.m4 (gl_FCNTL_H_DEFAULTS): Initialize these
GNULIB_MDA_<func> symbols.
* m4/math_h.m4 (gl_MATH_H_DEFAULTS): Likewise.
* m4/search_h.m4 (gl_SEARCH_H_DEFAULTS): Likewise.
* m4/stdio_h.m4 (gl_STDIO_H_DEFAULTS): Likewise.
* m4/stdlib_h.m4 (gl_STDLIB_H_DEFAULTS): Likewise.
* m4/string_h.m4 (gl_HEADER_STRING_H_DEFAULTS): Likewise.
* m4/sys_stat_h.m4 (gl_SYS_STAT_H_DEFAULTS): Likewise.
* m4/time_h.m4 (gl_HEADER_TIME_H_DEFAULTS): Likewise.
* m4/unistd_h.m4 (gl_UNISTD_H_DEFAULTS): Likewise.
* m4/utime_h.m4 (gl_UTIME_H_DEFAULTS): Likewise.
* m4/wchar_h.m4 (gl_WCHAR_H_DEFAULTS): Likewise.
* modules/fcntl-h (Makefile.am): Substitute these GNULIB_MDA_<func>
symbols.
* modules/math (Makefile.am): Likewise.
* modules/search (Makefile.am): Likewise.
* modules/stdio (Makefile.am): Likewise.
* modules/stdlib (Makefile.am): Likewise.
* modules/string (Makefile.am): Likewise.
* modules/sys_stat (Makefile.am): Likewise.
* modules/time (Makefile.am): Likewise.
* modules/unistd (Makefile.am): Likewise.
* modules/utime-h (Makefile.am): Likewise.
* modules/wchar (Makefile.am): Likewise.

4 years agocanonicalize, canonicalize-lgpl: remove lint
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.

4 years agospawn-pipe: Use posix_spawn by default on native Windows.
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.

4 years agounistd-safer: Implement pipe_safer on native Windows.
Bruno Haible [Fri, 25 Dec 2020 01:16:18 +0000 (02:16 +0100)]
unistd-safer: Implement pipe_safer on native Windows.

* lib/pipe-safer.c (pipe_safer): Don't test HAVE_PIPE.
* modules/unistd-safer (Depends-on): Add pipe-posix.

4 years agoexecute: Use posix_spawn by default on native Windows.
Bruno Haible [Fri, 25 Dec 2020 01:15:38 +0000 (02:15 +0100)]
execute: Use posix_spawn by default on native Windows.

* lib/execute.c (EXECUTE_IMPL_AVOID_POSIX_SPAWN): New macro.
(execute): Use it to decide among the two possible implementations.

4 years agocanonicalize-lgpl: merge proposed libc changes
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.

4 years agoautoupdate
Paul Eggert [Thu, 24 Dec 2020 22:47:31 +0000 (14:47 -0800)]
autoupdate

4 years agoposix_spawn-internal: Implement for native Windows.
Bruno Haible [Thu, 24 Dec 2020 21:18:36 +0000 (22:18 +0100)]
posix_spawn-internal: Implement for native Windows.

* lib/spawni.c (grow_inheritable_handles, shrink_inheritable_handles,
close_inheritable_handles, memiszero, sigisempty, open_handle, do_open,
do_dup2, do_close): New functions.
(__spawni): Implement on native Windows.
* modules/posix_spawn-internal (Depends-on): Add filename,
concat-filename, findprog-in, malloca, windows-spawn.
* doc/posix-functions/posix_spawn.texi: Update.
* doc/posix-functions/posix_spawnp.texi: Likewise.

4 years agowindows-spawn: Export another auxiliary function.
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.

4 years agowindows-spawn: Export some more auxiliary functions.
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.

4 years agowindows-spawn: Export another auxiliary function.
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.

4 years agowindows-spawn: Export an auxiliary function.
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.

4 years agoposix_spawn* tests: Add support for native Windows.
Bruno Haible [Thu, 24 Dec 2020 21:14:38 +0000 (22:14 +0100)]
posix_spawn* tests: Add support for native Windows.

* tests/test-posix_spawn-open1.c (DATA_FILENAME): Treat native Windows
like Cygwin.
* tests/test-posix_spawn-dup2-stdin.c (main): Don't assume the signals
SIGHUP and SIGPIPE. On native Windows, don't call
posix_spawnattr_setsigmask.
* tests/test-posix_spawn-dup2-stdout.c (main): Likewise.
* tests/test-posix_spawn-fchdir.c (main): Likewise.
* tests/test-posix_spawn-chdir.c (test): Likewise. Accept the child
output from Cygwin's 'pwd' program.
* tests/test-posix_spawn-script.c (main): On native Windows, skip the
executable-shell-script part of the test.
* tests/test-posix_spawnp-script.c (main): Likewise.
* modules/posix_spawn-tests (Depends-on): Add freopen, waitpid.
(configure.ac): Don't define the POSIX_SPAWN_PORTED conditional.
(Makefile.am): Don't test the POSIX_SPAWN_PORTED conditional.
* modules/posix_spawnp-tests (Depends-on): Add  waitpid.
(configure.ac): Don't define the POSIX_SPAWN_PORTED conditional.
(Makefile.am): Don't test the POSIX_SPAWN_PORTED conditional.
* modules/posix_spawn_file_actions_addchdir-tests (Makefile.am): Don't
test the POSIX_SPAWN_PORTED conditional.
* modules/posix_spawn_file_actions_addfchdir-tests (configure.ac):
Define the POSIX_SPAWN_PORTED conditional here.

4 years agosh-filename: Add support for native Windows.
Bruno Haible [Thu, 24 Dec 2020 21:13:49 +0000 (22:13 +0100)]
sh-filename: Add support for native Windows.

* m4/sh-filename.m4 (gl_SH_FILENAME): Treat native Windows like Cygwin.

4 years agocareadlinkat: improve warning line number
Paul Eggert [Thu, 24 Dec 2020 20:06:26 +0000 (12:06 -0800)]
careadlinkat: improve warning line number

This propagates an idea first used in canonicalize-lgpl.
* lib/careadlinkat.c (GCC_BOGUS_WRETURN_LOCAL_ADDR):
New macro.
(careadlinkat): Use it.

4 years ago* canonicalize-lgpl.c: Space after paren.
Paul Eggert [Thu, 24 Dec 2020 19:38:49 +0000 (11:38 -0800)]
* canonicalize-lgpl.c: Space after paren.

4 years agolinkat: use eloop-threshold
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.

4 years agocanonicalize-lgpl: use eloop-threshold
Paul Eggert [Thu, 24 Dec 2020 19:38:48 +0000 (11:38 -0800)]
canonicalize-lgpl: use eloop-threshold

* lib/canonicalize-lgpl.c [!_LIBC]: Include eloop-threshold.h.
(MAXSYMLINKS, __eloop_threshold): Remove.
* modules/canonicalize-lgpl (Depends-on): Add eloop-threshold.

4 years agoeloop-threshold: new module
Paul Eggert [Thu, 24 Dec 2020 19:38:48 +0000 (11:38 -0800)]
eloop-threshold: new module

* config/srclist.txt: Add a comment about it.
* lib/eloop-threshold.h, modules/eloop-threshold: New files.

4 years agocanonicalize: prefer faccessat to stat
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.

4 years agofaccessat: work around F_OK EOVERFLOW bug
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.

4 years agostat failing with EOVERFLOW implies existence
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.

4 years agocanonicalize-lgpl: remove freea macro
Paul Eggert [Thu, 24 Dec 2020 19:38:48 +0000 (11:38 -0800)]
canonicalize-lgpl: remove freea macro

* lib/canonicalize-lgpl.c (freea) [_LIBC]: Remove; not needed.

4 years agocanonicalize, canonicalize-lgpl: fix symlink bug
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.

4 years agoexecute: Treat signalled processes like wait-process does.
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.

4 years agowindows-spawn: Improve errno upon failure on native Windows.
Bruno Haible [Thu, 24 Dec 2020 17:19:08 +0000 (18:19 +0100)]
windows-spawn: Improve errno upon failure on native Windows.

* lib/windows-spawn.c (spawnpvech): Map the CreateProcess errors
ERROR_BAD_FORMAT and ERROR_BAD_EXE_FORMAT to ENOEXEC.
* tests/executable-script.sh: New file.
* tests/test-posix_spawn-script.c (main): Also try executing
executable-script.sh.
* tests/test-posix_spawnp-script.c (main): Likewise.
* tests/test-execute-script.c (main): Likewise.
* tests/test-spawn-pipe-script.c (main): Likewise.
* modules/posix_spawn-tests (Files): Add tests/executable-script.sh.
* modules/posix_spawnp-tests (Files): Likewise.
* modules/execute-tests (Files): Likewise.
* modules/spawn-pipe-tests (Files): Likewise.

4 years agofindprog-in: Improve errno upon failure on native Windows.
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.

4 years agoposix_spawn, posix_spawnp: Fix execution of scripts.
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.

4 years agoAdd unit tests regarding execution of scripts.
Bruno Haible [Thu, 24 Dec 2020 00:14:49 +0000 (01:14 +0100)]
Add unit tests regarding execution of scripts.

* tests/executable-script: New file.
* tests/executable-shell-script: New file.
* tests/test-posix_spawn-script.c: New file.
* tests/test-posix_spawnp-script.c: New file.
* tests/test-execute-script.c: New file.
* tests/test-spawn-pipe-script.c: New file.
* modules/posix_spawn-tests (Files): Add
tests/test-posix_spawn-script.c, tests/executable-script,
tests/executable-shell-script.
(Makefile.am): Compile and run test-posix_spawn-script.
* modules/posix_spawnp-tests (Files): Add
tests/test-posix_spawnp-script.c, tests/executable-script,
tests/executable-shell-script.
(Makefile.am): Compile and run test-posix_spawnp-script.
* modules/execute-tests (Files): Add tests/test-execute-script.c,
tests/executable-script, tests/executable-shell-script.
(Makefile.am): Compile and run test-execute-script.
* modules/spawn-pipe-tests (Files): Add tests/test-spawn-pipe-script.c,
tests/executable-script, tests/executable-shell-script.
(Makefile.am): Compile and run test-spawn-pipe-script.

4 years agoDon't execute scripts without '#!' marker through /bin/sh.
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.

4 years agoposix_spawn[p]: Fix compilation error on Windows (regr. 2020-12-14).
Bruno Haible [Thu, 24 Dec 2020 03:11:02 +0000 (04:11 +0100)]
posix_spawn[p]: Fix compilation error on Windows (regr. 2020-12-14).

Reported by Adrian Ebeling <devl@adrian-ebeling.de> in
<https://lists.gnu.org/archive/html/bug-gnulib/2020-12/msg00189.html>.

* lib/spawni.c (__spawni): Update function parameters.

4 years agoposix_spawn tests: Add two more tests.
Bruno Haible [Wed, 23 Dec 2020 22:26:42 +0000 (23:26 +0100)]
posix_spawn tests: Add two more tests.

* tests/test-posix_spawn-inherit0.c: New file, based on
tests/test-posix_spawn-open2.c.
* tests/test-posix_spawn-inherit1.c: New file, based on
tests/test-posix_spawn-open2.c.
* modules/posix_spawn-tests (Files): Add them.
(Depends-on): Add fflush.
(Makefile.am): Compile and run test-posix_spawn-inherit0 and
test-posix_spawn-inherit1.

4 years agoposix_spawn tests: Add another test.
Bruno Haible [Wed, 23 Dec 2020 22:22:03 +0000 (23:22 +0100)]
posix_spawn tests: Add another test.

* tests/test-posix_spawn-open2.c: New file, based on
tests/test-posix_spawn-open1.c.
* modules/posix_spawn-tests (Files): Add it.
(Makefile.am): Compile and run test-posix_spawn-open1.

4 years agobuild-aux/config.guess
Karl Berry [Wed, 23 Dec 2020 17:10:41 +0000 (09:10 -0800)]
build-aux/config.guess

4 years agoRemove support for broken <wchar.h> in AIX 3.
Bruno Haible [Mon, 21 Dec 2020 01:49:20 +0000 (02:49 +0100)]
Remove support for broken <wchar.h> in AIX 3.

* m4/wcwidth.m4 (gl_FUNC_WCWIDTH): Simplify test programs.

4 years agoRemove support for broken <wchar.h> in BSD/OS and OSF/1.
Bruno Haible [Mon, 21 Dec 2020 01:43:45 +0000 (02:43 +0100)]
Remove support for broken <wchar.h> in BSD/OS and OSF/1.

* lib/wchar.in.h: Don't include <stdio.h>, <time.h>.
* lib/mbchar.h: Likewise.
* lib/mbiter.h: Likewise.
* lib/mbuiter.h: Likewise.
* m4/stdint.m4 (gl_STDINT_INCLUDES): Likewise.
* lib/mbfile.h: Don't include <time.h>.
* lib/mbswidth.h: Update comment.
* lib/stdint.in.h: Don't include <stddef.h>, <stdio.h>, <time.h> before
<wchar.h>.
* lib/wctype.in.h: Likewise.
* m4/btowc.m4 (gl_FUNC_BTOWC): Simplify test programs.
* m4/iswblank.m4 (gl_FUNC_ISWBLANK): Likewise.
* m4/iswdigit.m4 (gl_FUNC_ISWDIGIT): Likewise.
* m4/iswxdigit.m4 (gl_FUNC_ISWXDIGIT): Likewise.
* m4/mbrlen.m4 (gl_FUNC_MBRLEN, gl_MBRLEN_INCOMPLETE_STATE,
gl_MBRLEN_RETVAL, gl_MBRLEN_NUL_RETVAL): Likewise.
* m4/mbrtoc32.m4 (gl_MBRTOC32_SANITYCHECK): Likewise.
* m4/mbrtowc.m4 (gl_FUNC_MBRTOWC, gl_MBRTOWC_INCOMPLETE_STATE,
gl_MBRTOWC_SANITYCHECK, gl_MBRTOWC_NULL_ARG1, gl_MBRTOWC_NULL_ARG2,
gl_MBRTOWC_RETVAL, gl_MBRTOWC_NUL_RETVAL, gl_MBRTOWC_STORES_INCOMPLETE,
AC_FUNC_MBRTOWC): Likewise.
* m4/mbsinit.m4 (gl_FUNC_MBSINIT): Likewise.
* m4/mbsnrtowcs.m4 (gl_MBSNRTOWCS_WORKS_IN_TRADITIONAL_LOCALE):
Likewise.
* m4/mbsrtowcs.m4 (gl_FUNC_MBSRTOWCS, gl_MBSRTOWCS_WORKS): Likewise.
* m4/mbstate_t.m4 (AC_TYPE_MBSTATE_T): Likewise.
* m4/mbswidth.m4 (gl_MBSWIDTH): Likewise.
* m4/printf.m4 (gl_PRINTF_DIRECTIVE_LS): Likewise.
* m4/wchar_h.m4 (gl_WCHAR_H, gl_WCHAR_H_INLINE_OK): Likewise.
* m4/wcrtomb.m4 (gl_FUNC_WCRTOMB): Likewise.
* m4/wcsdup.m4 (gl_FUNC_WCSDUP): Likewise.
* m4/wcsnrtombs.m4 (gl_WCSNRTOMBS_WORKS_IN_TRADITIONAL_LOCALE):
Likewise.
* m4/wcsrtombs.m4 (gl_FUNC_WCSRTOMBS, gl_WCSRTOMBS_TERMINATION,
gl_WCSRTOMBS_NULL): Likewise.
* m4/wcstok.m4 (gl_FUNC_WCSTOK): Likewise.
* m4/wctob.m4 (gl_FUNC_WCTOB): Likewise.
* m4/wctype_h.m4 (gl_WCTYPE_H): Likewise.
* m4/wcwidth.m4 (gl_FUNC_WCWIDTH): Likewise.
* m4/wint_t.m4 (gt_TYPE_WINT_T): Likewise.
* m4/wmemchr.m4 (gl_FUNC_WMEMCHR): Likewise.
* m4/wmemcmp.m4 (gl_FUNC_WMEMCMP): Likewise.
* m4/wmemcpy.m4 (gl_FUNC_WMEMCPY): Likewise.
* m4/wmemmove.m4 (gl_FUNC_WMEMMOVE): Likewise.
* m4/wmemset.m4 (gl_FUNC_WMEMSET): Likewise.

4 years agoisnanf: Fix autoconf test.
Bruno Haible [Mon, 21 Dec 2020 00:17:12 +0000 (01:17 +0100)]
isnanf: Fix autoconf test.

* m4/isnanf.m4 (gl_ISNANF_WORKS): Fix one of the NaN tests.

4 years agoRemove some of the support for obsolete IRIX 4 and 5.
Bruno Haible [Sun, 20 Dec 2020 22:24:54 +0000 (23:24 +0100)]
Remove some of the support for obsolete IRIX 4 and 5.

* m4/mountlist.m4 (AC_FUNC_GETMNTENT): Don't test for getmntent in
libsun.
* tests/init.sh (setup_): Don't talk about IRIX 5.

4 years agofilemode: Remove Cray support.
Bruno Haible [Sun, 20 Dec 2020 21:19:26 +0000 (22:19 +0100)]
filemode: Remove Cray support.

* lib/filemode.c (IS_MIGRATED_FILE): Remove macro.
(filemodestring): Don't produce an 'M' type.
* m4/filemode.m4 (gl_FILEMODE): Don't invoke AC_STRUCT_ST_DM_MODE.
* m4/st_dm_mode.m4: Remove file.
* modules/filemode (Files): Remove it.

4 years agofree-posix: assume glibc 2.33 fixes this.
Paul Eggert [Sun, 20 Dec 2020 21:29:04 +0000 (13:29 -0800)]
free-posix: assume glibc 2.33 fixes this.

* m4/free.m4 (gl_FUNC_FREE): Assume glibc 2.33+ is fixed.
Use compile-time test rather than guessing for cross-builds.

4 years agobackupfile: Fix compilation error on native Windows (regr. 2018-10-23).
Bruno Haible [Sun, 20 Dec 2020 14:10:05 +0000 (15:10 +0100)]
backupfile: Fix compilation error on native Windows (regr. 2018-10-23).

Reported by Adrian Ebeling <adrianebeling@gmx.de> in
<https://lists.gnu.org/archive/html/bug-gnulib/2020-12/msg00156.html>.

* lib/backupfile.c (fpathconf): Define fallback, like for pathconf.

4 years agofloat: Fix compilation error when gnulib's float.h exists twice, part 2.
Bruno Haible [Sun, 20 Dec 2020 13:50:18 +0000 (14:50 +0100)]
float: Fix compilation error when gnulib's float.h exists twice, part 2.

Reported by Santiago Vila <sanvila@unex.es>.

* lib/float.in.h (GNULIB_defined_long_double_union): New macro.

4 years agofloat: Fix compilation error when gnulib's float.h exists twice.
Bruno Haible [Sun, 20 Dec 2020 13:41:29 +0000 (14:41 +0100)]
float: Fix compilation error when gnulib's float.h exists twice.

Reported by Santiago Vila <sanvila@unex.es>.

* lib/float.in.h (GNULIB_defined_long_double_union): New macro.

4 years agofree-posix: Assume future POSIX compliance only on OpenBSD and Solaris.
Bruno Haible [Sat, 19 Dec 2020 19:19:45 +0000 (20:19 +0100)]
free-posix: Assume future POSIX compliance only on OpenBSD and Solaris.

* m4/free.m4 (gl_FUNC_FREE): Guess yes only on OpenBSD and Solaris.
Don't trust _POSIX_VERSION for this test.

4 years agofree-posix: port to GNU/Linux
Paul Eggert [Sat, 19 Dec 2020 16:14:38 +0000 (08:14 -0800)]
free-posix: port to GNU/Linux

* m4/free.m4 (gl_FUNC_FREE): Don’t assume GNU hosts are free of
the bug, as it occurs on Ubuntu 20.10 x86-64 and, I assume, on
other GNU/Linux hosts.

4 years agofree-posix: Add tests.
Bruno Haible [Sat, 19 Dec 2020 12:26:24 +0000 (13:26 +0100)]
free-posix: Add tests.

* tests/test-free.c: New file.
* tests/macros.h (ASSERT_NO_STDIO,
WRITE_MACROEXPANDED_INTEGER_TO_STDERR, WRITE_INTEGER_TO_STDERR,
WRITE_TO_STDERR): New macros.
* modules/free-posix-tests: New file.

4 years agofree-posix: Add C++ declaration test.
Bruno Haible [Fri, 18 Dec 2020 23:28:02 +0000 (00:28 +0100)]
free-posix: Add C++ declaration test.

* tests/test-stdlib-c++.cc (free): New declaration.

4 years agofree-posix: New module, renamed from 'free'.
Bruno Haible [Fri, 18 Dec 2020 23:18:50 +0000 (00:18 +0100)]
free-posix: New module, renamed from 'free'.

* modules/free-posix: Renamed from modules/free.
(configure.ac): Update gl_STDLIB_MODULE_INDICATOR invocation.
* m4/stdlib_h.m4 (gl_STDLIB_H_DEFAULTS): Initialize GNULIB_FREE_POSIX,
not GNULIB_FREE.
* modules/stdlib (Makefile.am): Substitute GNULIB_FREE_POSIX, not
GNULIB_FREE.
* lib/stdlib.in.h (free): Test GNULIB_FREE_POSIX, not GNULIB_FREE.
* doc/posix-functions/free.texi: Mention the module 'free-posix' and
what it does.
* NEWS: Mention that module 'free' no longer exists.
* modules/canonicalize (Depends-on): Add free-posix. Remove free.
* modules/canonicalize-lgpl (Depends-on): Likewise.

4 years agofree: Remove support for obsolete platforms.
Bruno Haible [Fri, 18 Dec 2020 22:58:37 +0000 (23:58 +0100)]
free: Remove support for obsolete platforms.

* m4/free.m4 (gl_FUNC_FREE): Assume free(NULL) works. Don't define
CANNOT_FREE_NULL.
* lib/free.c (rpl_free): Don't test CANNOT_FREE_NULL.
* modules/free (Description): Update.
* doc/posix-functions/free.texi: Don't mention SunOS 4 any more.

4 years agointprops: port to ICC 2021.1 Beta 20201112
Paul Eggert [Fri, 18 Dec 2020 18:18:40 +0000 (10:18 -0800)]
intprops: port to ICC 2021.1 Beta 20201112

* lib/intprops.h (_GL_HAS_BUILTIN_OVERFLOW_P):
Port to ICC 2021.1, which has a non-working __builtin_mul_overflow_p.
Add a clause for other compilers that claim to support
__builtin_mul_overflow_p, since we might as well find out about
slackers other than Clang and ICC.
(INT_MULTIPLY_WRAPV): ICC 2021 has GCC bug 91450, so treat it
like older GCCs even when it claims to be a newer one.

4 years agointprops: Avoid potentially buggy __builtin_add_overflow in GCC 5, 6.
Bruno Haible [Fri, 18 Dec 2020 12:10:27 +0000 (13:10 +0100)]
intprops: Avoid potentially buggy __builtin_add_overflow in GCC 5, 6.

Reported by Stefan Liebler <stli@linux.ibm.com> in
<https://lists.gnu.org/archive/html/bug-gnulib/2020-12/msg00152.html>.

* lib/intprops.h (_GL_HAS_BUILTIN_ADD_OVERFLOW): Don't define for
GCC 5.x and 6.x.
* lib/glob.c (size_add_wrapv): Don't use __builtin_add_overflow for
GCC 5.x and 6.x.

4 years agofree: Fix warning.
Bruno Haible [Thu, 17 Dec 2020 23:41:07 +0000 (00:41 +0100)]
free: Fix warning.

Reported by Pádraig Brady <P@draigBrady.com> in
<https://lists.gnu.org/archive/html/bug-gnulib/2020-12/msg00148.html>.

* lib/stdlib.in.h (free): New declaration.
* m4/stdlib_h.m4 (gl_STDLIB_H): Test whether 'free' is declared.
(gl_STDLIB_H_DEFAULTS): Initialize GNULIB_FREE, REPLACE_FREE.
* modules/stdlib (Makefile.am): Substitute GNULIB_FREE, REPLACE_FREE.
* m4/free.m4 (gl_FUNC_FREE): Set REPLACE_FREE, instead of defining
'free' as a macro here.
* modules/free (Depends-on): Add stdlib.
(configure.ac): Test REPLACE_FREE. Invoke gl_STDLIB_MODULE_INDICATOR.

4 years agocanonicalize-lgpl: fix AIX test failures
Paul Eggert [Thu, 17 Dec 2020 09:22:55 +0000 (01:22 -0800)]
canonicalize-lgpl: fix AIX test failures

This merges the recent canonicalize.c fix into canonicalize-lgpl.c.
Problem reported by Bruno Haible in:
https://lists.gnu.org/r/bug-gnulib/2020-12/msg00138.html
* lib/canonicalize-lgpl.c: Include sys/stat.h.
(__realpath): When testing a file name ending in '/', use stat
rather than readlink, so that it does the right thing on AIX.
* modules/canonicalize-lgpl (Depends-on): Add stat, sys_stat.

4 years agocanonicalize: omit second readlink when not needed
Paul Eggert [Thu, 17 Dec 2020 09:13:40 +0000 (01:13 -0800)]
canonicalize: omit second readlink when not needed

* lib/canonicalize.c (canonicalize_filename_mode_stk):
Omit second readlink when (can_exist != CAN_MISSING
&& startlen != 0 && !logical).  Simplify.

4 years agocanonicalize: remove arbitrary 8192-byte limit
Paul Eggert [Thu, 17 Dec 2020 07:50:34 +0000 (23:50 -0800)]
canonicalize: remove arbitrary 8192-byte limit

Remove canonicalize.c’s arbitrary 8192-byte limit on platforms
like GNU Hurd that do not define the PATH_MAX macro, and similarly
for canonicalize-lgpl.c’s arbitrary 1024-byte limit.  Do this by
using scratch buffers.  Lessen the number of differences between
the two source files, to simplify this and future maintenance.
* lib/canonicalize-lgpl.c (__realpath):
* lib/canonicalize.c (canonicalize_filename_mode_stk):
Use scratch buffers instead of malloc and malloca.  This avoids
the need for alloca, and avoids the need for malloc in most cases.
* lib/canonicalize-lgpl.c, lib/canonicalize.c: Make these files
easier to compare, e.g., by sorting include files and by switching
to the GNU convention of calling file names "file names", not
"path names".  Include stdbool.h, scratch_buffer.h.
* lib/canonicalize-lgpl.c (IDX_MAX) [_LIBC]: New macro.
(malloca) [_LIBC]: Remove.
[!_LIBC]: Do not include malloca.h.
(get_path_max): New function, so that pathconf is called only in
the rare and dubious case when when RESOLVED is not null and
PATH_MAX is not defined.  Invoke pathconf on "/" not the input
file name, as we care about the longest file name starting from
"/" (not from the input file name), and POSIX does not specify
what pathconf does on a non-directory file anyway.  If PATH_MAX is
not defined, do not worry about overriding a path_max of 0, and do
not let path_max exceed IDX_MAX.
(__realpath): Remove an assumption that file name components
cannot exceed 1024 bytes when PATH_MAX is not defined (wrong for
the Hurd, presumably).
When allocating the result, allocate it to just the right size;
this costs nothing when the result is smaller than 1023 bytes,
and for larger results it's probably worth the CPU to call realloc,
as canonicalize.c already does.
* lib/canonicalize.c: Include attribute.h.
Do not include pathmax.h or xgetcwd.h.
(PATH_MAX): Do not define, so file names longer than 8192 bytes
work on platforms with no fixed limit.
(canonicalize_filename_mode_stk): New function, with
the content of the old canonicalize_filename_mode.
Use getcwd instead of xgetcwd, and readlink instead of areadlink,
since the scratch buffers now do memory management for us.
Use rawmemchr instead of adding strlen.
Use mempcpy instead of mempcpy + size.
Assume free preserves errno.
(canonicalize_filename_mode): Use it.
* modules/canonicalize (Depends-on): Remove areadlink, pathmax,
xgetcwd.  Add attribute, free, getcwd, mempcpy, rawmemchr,
scratch_buffer, stdbool, xalloc-die.
* modules/canonicalize-lgpl (Depends-on): Remove alloca-opt,
malloca, realloc-posix.  Add scratch_buffer, stdbool.

4 years agocanonicalize-lgpl: simplify merge to glibc
Paul Eggert [Mon, 14 Dec 2020 19:59:20 +0000 (11:59 -0800)]
canonicalize-lgpl: simplify merge to glibc

This patch lessens the differences between git glibc
stdlib/canonicalize.c and lib/canonicalize-lgpl.c.
The (perhaps wishful) goal is to make them identical.
* lib/canonicalize-lgpl.c [!_LIBC]:
Include <libc-config.h>, not config.h.
Omit an unnecessary (!HAVE_CANONICALIZE_FILE_NAME ||
!FUNC_REALPATH_WORKS || defined _LIBC) #if.
Do not include alloca.h, since we use malloca now.
[_LIBC]: Include <eloop-threshold.h>, and define dummy macros
FILE_SYSTEM_PREFIX_LEN, IS_ABSOLUTE_FILE_NAME, ISSLASH, malloca,
freea so that the mainline code can be kept #ifdef free.
[!_LIBC]: Remove dummy macros for SHLIB_COMPAT, versioned_symbol,
compat_symbol, weak_alias, __set_errno since libc-config.h does that.
Add redirecting macros __mempcpy, __pathconf, __rawmemchr,
__eloop_threshold.  All uses of their definiens changed.
(SIZE_MAX): Remove; no longer needed.
(alloc_failed): Remove, and remove all instances.
No need for alloc_failed now that free preserves errno.
(__realpath): Default path_max to 1024 instead of 8192, as that’s
the glibc tradition and is safer when the 2nd argument is null.
Use __rawmemchr instead of strchr.
Use __mempcpy where appropriate.
Simplify test for overflow so that it does not need SIZE_MAX.
Do not preserve errno around free or freea calls; no longer needed.
Mark __realpath with libc_hidden_def.
* modules/canonicalize-lgpl (Depends-on): Add free, libc-config,
malloc-posix, mempcpy, realloc-posix, rawmemchr.
* modules/free: Now LGPLv2+, for canonicalize-lgpl.

4 years agofree: preserve errno
Paul Eggert [Mon, 14 Dec 2020 19:38:18 +0000 (11:38 -0800)]
free: preserve errno

* lib/free.c (rpl_free): Preserve errno.  Check for null only if
CANNOT_FREE_NULL is defined, as an optimization for POSIX 2008
platforms that do not preserve errno.
* m4/free.m4 (gl_FUNC_FREE): Check whether free preserves errno.
Also, define CANNOT_FREE_NULL if free cannot free NULL.
* modules/free (configure.ac): Also replace 'free' if
it does not preserve errno.

4 years agoidx: simplify IDX_MAX, remove IDX_WIDTH
Paul Eggert [Thu, 17 Dec 2020 07:52:24 +0000 (23:52 -0800)]
idx: simplify IDX_MAX, remove IDX_WIDTH

* lib/idx.h (IDX_MAX): Simplify by removing obsolete reference
to UNSIGNED_IDX_T.
(IDX_WIDTH): Remove, since it’s not used and its value
arguably should be PTRDIFF_WIDTH anyway.

4 years agoposix_spawn_file_actions_addfchdir-tests: Rename test.
Bruno Haible [Thu, 17 Dec 2020 02:00:25 +0000 (03:00 +0100)]
posix_spawn_file_actions_addfchdir-tests: Rename test.

* tests/test-posix_spawn-fchdir.c: Renamed from
tests/test-posix_spawn5.c.
* modules/posix_spawn_file_actions_addfchdir-tests (Files, Makefile.am):
Update.

4 years agoposix_spawn_file_actions_addchdir-tests: Rename test.
Bruno Haible [Thu, 17 Dec 2020 01:56:21 +0000 (02:56 +0100)]
posix_spawn_file_actions_addchdir-tests: Rename test.

* tests/test-posix_spawn-chdir.c: Renamed from
tests/test-posix_spawn4.c.
* modules/posix_spawn_file_actions_addchdir-tests (Files, Makefile.am):
Update.

4 years agoposix_spawn-tests: Rename test.
Bruno Haible [Thu, 17 Dec 2020 01:47:40 +0000 (02:47 +0100)]
posix_spawn-tests: Rename test.

* tests/test-posix_spawn-open1.c: Renamed from
tests/test-posix_spawn3.c.
* modules/posix_spawn-tests (Files, Makefile.am): Update.

4 years agoposix_spawnp-tests: Rename test.
Bruno Haible [Thu, 17 Dec 2020 01:44:31 +0000 (02:44 +0100)]
posix_spawnp-tests: Rename test.

* tests/test-posix_spawn-dup2-stdin.c: Renamed from
tests/test-posix_spawn2.c.
* tests/test-posix_spawn-dup2-stdin.in.sh: Renamed from
tests/test-posix_spawn2.in.sh.
* modules/posix_spawnp-tests (Files, Makefile.am): Update.

4 years agoposix_spawnp-tests: Rename test.
Bruno Haible [Thu, 17 Dec 2020 01:38:08 +0000 (02:38 +0100)]
posix_spawnp-tests: Rename test.

* tests/test-posix_spawn-dup2-stdout.c: Renamed from
tests/test-posix_spawn1.c.
* tests/test-posix_spawn-dup2-stdout.in.sh: Renamed from
tests/test-posix_spawn1.in.sh.
* modules/posix_spawnp-tests (Files, Makefile.am): Update.

4 years agofindprog-in: Allow overriding the current directory.
Bruno Haible [Mon, 14 Dec 2020 19:56:04 +0000 (20:56 +0100)]
findprog-in: Allow overriding the current directory.

* lib/findprog.h (find_in_given_path): Add directory argument.
* lib/findprog-in.c (find_in_given_path): Likewise.
* lib/execute.c (execute): Update caller.
* lib/spawn-pipe.c (create_pipe): Likewise.
* lib/windows-spawn.c (spawnpvech): Likewise.
* NEWS: Mention the change.

4 years agoposix_spawn-internal: Make better use of 'const'.
Bruno Haible [Mon, 14 Dec 2020 18:22:14 +0000 (19:22 +0100)]
posix_spawn-internal: Make better use of 'const'.

* lib/spawn_int.h (__spawni): Does not need write access to the elements
of argv and envp.
* lib/spawni.c (__spawni, script_execute): Likewise.
* lib/spawn.c (posix_spawn): Update caller.
* lib/spawnp.c (posix_spawnp): Likewise.

4 years agospawn: Make it compile on native Windows.
Bruno Haible [Mon, 14 Dec 2020 17:07:28 +0000 (18:07 +0100)]
spawn: Make it compile on native Windows.

* modules/spawn (Depends-on): Add signal-h.

4 years agowindows-spawn: Avoid shadowing a variable.
Bruno Haible [Mon, 14 Dec 2020 17:05:38 +0000 (18:05 +0100)]
windows-spawn: Avoid shadowing a variable.

* lib/windows-spawn.c (spawnpvech): Rename local variable 'flags'.

4 years agostring: port memchr macro to AIX 7.2 XLC
Paul Eggert [Mon, 14 Dec 2020 01:32:34 +0000 (17:32 -0800)]
string: port memchr macro to AIX 7.2 XLC

Its <string.h> defines a memchr macro to help inlining.
* lib/string.in.h (memchr): #undef before #defining.

4 years agocanonicalize: fix AIX test failures
Paul Eggert [Mon, 14 Dec 2020 01:16:01 +0000 (17:16 -0800)]
canonicalize: fix AIX test failures

Problem reported by Bruno Haible in:
https://lists.gnu.org/r/bug-gnulib/2020-12/msg00109.html
* lib/canonicalize.c (canonicalize_filename_mode):
When testing a file name ending in '/', use stat rather than
readlink, so that it does the right thing on AIX.
* modules/canonicalize (Depends-on): Add readlink, to pull in the
recent changes in the Gnulib readlink module.

4 years agoAssume readlink/readlinkat ERANGE fix
Paul Eggert [Mon, 14 Dec 2020 00:56:10 +0000 (16:56 -0800)]
Assume readlink/readlinkat ERANGE fix

* lib/areadlink-with-size.c (areadlink_with_size):
* lib/areadlinkat-with-size.c (areadlinkat_with_size):
* lib/careadlinkat.c (readlink_stk):
Do not worry about readlink or readlinkat failing with errno == ERANGE,
since the Gnulib readlink and readlinkat modules now fix that.