]> Savannah Git Hosting - gnulib.git/commitdiff
posix_spawn-internal: Make better use of 'const'.
authorBruno Haible <bruno@clisp.org>
Mon, 14 Dec 2020 18:22:14 +0000 (19:22 +0100)
committerBruno Haible <bruno@clisp.org>
Mon, 14 Dec 2020 18:22:14 +0000 (19:22 +0100)
* 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.

ChangeLog
lib/spawn.c
lib/spawn_int.h
lib/spawni.c
lib/spawnp.c

index 21cc216e20749079fe385d6377c5acf824d1093a..f909f61222256abd2caece97b2e4146bb8382221 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2020-12-14  Bruno Haible  <bruno@clisp.org>
+
+       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.
+
 2020-12-14  Bruno Haible  <bruno@clisp.org>
 
        spawn: Make it compile on native Windows.
index c139b71a6e6dfa1741536fd892ac43adb49908bd..b658453a10f5ce8678ba3c44e88a13dce33d949d 100644 (file)
@@ -29,5 +29,6 @@ posix_spawn (pid_t *pid, const char *path,
              const posix_spawnattr_t *attrp, char *const argv[],
              char *const envp[])
 {
-  return __spawni (pid, path, file_actions, attrp, argv, envp, 0);
+  return __spawni (pid, path, file_actions, attrp,
+                   (const char * const *) argv, (const char * const *) envp, 0);
 }
index 7c063b6b7eda3c8a7af9e18982d623c8e2db8446..60a94ddd55ac792081ec848a590db611173b5d28 100644 (file)
@@ -68,5 +68,5 @@ extern int __posix_spawn_file_actions_realloc (posix_spawn_file_actions_t *
 #endif
 extern int __spawni (pid_t *pid, const char *path,
                      const posix_spawn_file_actions_t *file_actions,
-                     const posix_spawnattr_t *attrp, char *const argv[],
-                     char *const envp[], int use_path);
+                     const posix_spawnattr_t *attrp, const char *const argv[],
+                     const char *const envp[], int use_path);
index 07bbec70a54362b2f146a2433cba1d83cb4079be..1e20a9726f773d8738565a2566671109e226b50d 100644 (file)
@@ -109,7 +109,8 @@ __spawni (pid_t *pid, const char *file,
    the shell to interpret it as a script.  */
 static void
 internal_function
-script_execute (const char *file, char *const argv[], char *const envp[])
+script_execute (const char *file, const char *const argv[],
+                const char *const envp[])
 {
   /* Count the arguments.  */
   int argc = 0;
@@ -118,9 +119,10 @@ script_execute (const char *file, char *const argv[], char *const envp[])
 
   /* Construct an argument list for the shell.  */
   {
-    char **new_argv = (char **) alloca ((argc + 1) * sizeof (char *));
-    new_argv[0] = (char *) _PATH_BSHELL;
-    new_argv[1] = (char *) file;
+    const char **new_argv =
+      (const char **) alloca ((argc + 1) * sizeof (const char *));
+    new_argv[0] = _PATH_BSHELL;
+    new_argv[1] = file;
     while (argc > 1)
       {
         new_argv[argc] = argv[argc - 1];
@@ -128,7 +130,7 @@ script_execute (const char *file, char *const argv[], char *const envp[])
       }
 
     /* Execute the shell.  */
-    execve (new_argv[0], new_argv, envp);
+    execve (new_argv[0], (char * const *) new_argv, (char * const *) envp);
   }
 }
 
@@ -138,8 +140,8 @@ script_execute (const char *file, char *const argv[], char *const envp[])
 int
 __spawni (pid_t *pid, const char *file,
           const posix_spawn_file_actions_t *file_actions,
-          const posix_spawnattr_t *attrp, char *const argv[],
-          char *const envp[], int use_path)
+          const posix_spawnattr_t *attrp, const char *const argv[],
+          const char *const envp[], int use_path)
 {
   pid_t new_pid;
   char *path, *p, *name;
@@ -303,7 +305,7 @@ __spawni (pid_t *pid, const char *file,
   if (! use_path || strchr (file, '/') != NULL)
     {
       /* The FILE parameter is actually a path.  */
-      execve (file, argv, envp);
+      execve (file, (char * const *) argv, (char * const *) envp);
 
       if (errno == ENOEXEC)
         script_execute (file, argv, envp);
@@ -354,7 +356,7 @@ __spawni (pid_t *pid, const char *file,
         startp = (char *) memcpy (name - (p - path), path, p - path);
 
       /* Try to execute this name.  If it works, execv will not return.  */
-      execve (startp, argv, envp);
+      execve (startp, (char * const *) argv, (char * const *) envp);
 
       if (errno == ENOEXEC)
         script_execute (startp, argv, envp);
index 0f03e79bcae824b7b983f1480e7366a0cc370c3f..91c54a1c2a2d2fe9b1f240a9d5cd384896cde81e 100644 (file)
@@ -29,5 +29,6 @@ posix_spawnp (pid_t *pid, const char *file,
               const posix_spawnattr_t *attrp, char *const argv[],
               char *const envp[])
 {
-  return __spawni (pid, file, file_actions, attrp, argv, envp, 1);
+  return __spawni (pid, file, file_actions, attrp,
+                   (const char * const *) argv, (const char * const *) envp, 1);
 }