]> Savannah Git Hosting - gnulib.git/commitdiff
execvp: New module.
authorBruno Haible <bruno@clisp.org>
Sat, 26 Dec 2020 13:28:16 +0000 (14:28 +0100)
committerBruno Haible <bruno@clisp.org>
Sat, 26 Dec 2020 13:28:16 +0000 (14:28 +0100)
* 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.

ChangeLog
doc/posix-functions/execvp.texi
lib/execvp.c [new file with mode: 0644]
m4/execvp.m4 [new file with mode: 0644]
modules/execvp [new file with mode: 0644]

index 1f9acd2c677d62310ffa82d7a5ea23398ccd7d1f..5d204952ffa7c98e7979b8ba5764b388aa2fc507 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,12 @@
 2020-12-26  Bruno Haible  <bruno@clisp.org>
 
+       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.
+
        execvpe: Add tests.
        * tests/test-execvpe-main.c: New file.
        * tests/test-execvpe.sh: New file.
index 24a3f063ea2507e6a2718d2972d50a99fcc0c71f..0c242b28aa423c35b9608d4e068de79c5b93d6ee 100644 (file)
@@ -4,10 +4,22 @@
 
 POSIX specification:@* @url{https://pubs.opengroup.org/onlinepubs/9699919799/functions/execvp.html}
 
-Gnulib module: ---
+Gnulib module: execvp
 
 Portability problems fixed by Gnulib:
 @itemize
+@item
+On Windows platforms (excluding Cygwin), this function does not pass
+command-line arguments correctly if they contain space, tab, backslash,
+or double-quote characters.
+@item
+On Windows platforms (excluding Cygwin), this function spawns an asynchronous
+child process and then exits the current process immediately.  As a
+consequence, the parent of the current process 1. may incorrectly proceed
+as if its child had exited, and 2. will never see the child's exit status.
+@item
+On Windows platforms (excluding Cygwin), the return type of this function is
+@code{intptr_t}, not @code{int}.
 @end itemize
 
 Portability problems not fixed by Gnulib:
@@ -15,8 +27,4 @@ Portability problems not fixed by Gnulib:
 @item
 On some platforms, a script without executable permission is still run:
 Cygwin 1.5.x.
-@item
-On Windows platforms (excluding Cygwin), this function operates by spawning
-and then by exiting the current process, which means the current
-process's parent may incorrectly proceed as if its child had exited.
 @end itemize
diff --git a/lib/execvp.c b/lib/execvp.c
new file mode 100644 (file)
index 0000000..db0fcb7
--- /dev/null
@@ -0,0 +1,35 @@
+/* execvp() function: Execute a program, replacing the current process.
+   Copyright (C) 2020 Free Software Foundation, Inc.
+
+   This program is free software: you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <https://www.gnu.org/licenses/>.  */
+
+/* Written by Bruno Haible <bruno@clisp.org>, 2020.  */
+
+#include <config.h>
+
+/* Specification.  */
+#include <unistd.h>
+
+int
+execvp (const char *program, char * const *argv)
+{
+  /* Pass the environment explicitly.  This is needed if the program has
+     modified the environment using putenv() or [un]setenv().  On Windows,
+     processes have two environments, one in the "environment block" of the
+     process and managed through SetEnvironmentVariable(), and one inside the
+     process, in the location retrieved by the 'environ' macro.  If we were
+     to pass NULL, the child process would inherit a copy of the environment
+     block - ignoring the effects of putenv() and [un]setenv().  */
+  return execvpe (program, argv, environ);
+}
diff --git a/m4/execvp.m4 b/m4/execvp.m4
new file mode 100644 (file)
index 0000000..833b987
--- /dev/null
@@ -0,0 +1,15 @@
+# execvp.m4 serial 1
+dnl Copyright (C) 2020 Free Software Foundation, Inc.
+dnl This file is free software; the Free Software Foundation
+dnl gives unlimited permission to copy and/or distribute it,
+dnl with or without modifications, as long as this notice is preserved.
+
+AC_DEFUN([gl_FUNC_EXECVP],
+[
+  AC_REQUIRE([gl_UNISTD_H_DEFAULTS])
+  AC_REQUIRE([AC_CANONICAL_HOST])
+
+  case "$host_os" in
+    mingw*) REPLACE_EXECVP=1 ;;
+  esac
+])
diff --git a/modules/execvp b/modules/execvp
new file mode 100644 (file)
index 0000000..df2d313
--- /dev/null
@@ -0,0 +1,29 @@
+Description:
+execvp() function: Execute a program, replacing the current process.
+
+Files:
+lib/execvp.c
+m4/execvp.m4
+
+Depends-on:
+unistd
+environ         [test $REPLACE_EXECVP = 1]
+execvpe         [test $REPLACE_EXECVP = 1]
+
+configure.ac:
+gl_FUNC_EXECVP
+if test $REPLACE_EXECVP = 1; then
+  AC_LIBOBJ([execvp])
+fi
+gl_UNISTD_MODULE_INDICATOR([execvp])
+
+Makefile.am:
+
+Include:
+<unistd.h>
+
+License:
+LGPLv2+
+
+Maintainer:
+all