summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorBruno Haible <bruno@clisp.org>2020-12-12 04:18:54 +0100
committerBruno Haible <bruno@clisp.org>2020-12-12 04:18:54 +0100
commitc893594d0c33139efbc8d75e43eaed487116b58b (patch)
tree6e8f5d55f44b65d6e9567822b5da2cbf24351fbf /lib
parent46c7e327c76f115bbdc6eee75fffa382559aa9d8 (diff)
downloadgnulib-c893594d0c33139efbc8d75e43eaed487116b58b.tar.gz
sh-quote, execute, spawn-pipe, etc.: Make better use of 'const'.
* lib/sh-quote.h (shell_quote_argv): Does not need write access to the elements of argv. * lib/sh-quote.c (shell_quote_argv): Likewise. * lib/windows-spawn.h (prepare_spawn): Add 'const' the argument type and the return type. * lib/windows-spawn.c (prepare_spawn): Likewise. * lib/os2-spawn.h (prepare_spawn): Likewise. * lib/os2-spawn.c (prepare_spawn): Likewise. * lib/execute.h (execute): Does not need write access to the elements of prog_argv. * lib/execute.c (execute): Likewise. * lib/spawn-pipe.h (create_pipe_out, create_pipe_in, create_pipe_bidi): Likewise. * lib/spawn-pipe.c (create_pipe, create_pipe_bidi, create_pipe_in, create_pipe_out): Likewise. * lib/pipe-filter.h (pipe_filter_ii_execute, pipe_filter_gi_create): Likewise. * lib/pipe-filter-ii.c (pipe_filter_ii_execute): Likewise. * lib/pipe-filter-gi.c (pipe_filter_gi_create): Likewise. * lib/javaexec.h (execute_fn): Does not need write access to the elements of prog_argv. * lib/javaexec.c (execute_java_class): Update variable types and remove casts to 'char *'. * lib/csharpexec.h (execute_fn): Does not need write access to the elements of prog_argv. * lib/csharpexec.c (execute_csharp_using_mono, execute_csharp_using_sscli): Update variable types and remove casts to 'char *'. * lib/javacomp.c (compile_using_envjavac, compile_using_gcj, compile_using_javac, compile_using_jikes, is_envjavac_gcj, is_envjavac_gcj43, is_gcj_present, is_gcj_43, is_javac_present, is_jikes_present): Update variable types and remove casts to 'char *'. * lib/javaversion.c (execute_and_read_line): Does not need write access to the elements of prog_argv. * lib/csharpcomp.c (compile_csharp_using_mono, compile_csharp_using_sscli): Update variable types and remove casts to 'char *'. * tests/test-sh-quote.c (main): Update variable types and remove casts to 'char *'. * tests/test-execute-main.c (main): Update variable types and remove casts to 'char *'. * tests/test-spawn-pipe-main.c (test_pipe): Update variable types and remove casts to 'char *'. * NEWS: Mention the changes.
Diffstat (limited to 'lib')
-rw-r--r--lib/csharpcomp.c31
-rw-r--r--lib/csharpexec.c18
-rw-r--r--lib/csharpexec.h2
-rw-r--r--lib/execute.c32
-rw-r--r--lib/execute.h2
-rw-r--r--lib/javacomp.c48
-rw-r--r--lib/javaexec.c43
-rw-r--r--lib/javaexec.h2
-rw-r--r--lib/javaversion.c2
-rw-r--r--lib/os2-spawn.c8
-rw-r--r--lib/os2-spawn.h3
-rw-r--r--lib/pipe-filter-gi.c4
-rw-r--r--lib/pipe-filter-ii.c4
-rw-r--r--lib/pipe-filter.h6
-rw-r--r--lib/sh-quote.c4
-rw-r--r--lib/sh-quote.h2
-rw-r--r--lib/spawn-pipe.c45
-rw-r--r--lib/spawn-pipe.h9
-rw-r--r--lib/windows-spawn.c8
-rw-r--r--lib/windows-spawn.h3
20 files changed, 145 insertions, 131 deletions
diff --git a/lib/csharpcomp.c b/lib/csharpcomp.c
index 57d2084b0a..cf4e2a50c5 100644
--- a/lib/csharpcomp.c
+++ b/lib/csharpcomp.c
@@ -76,7 +76,7 @@ compile_csharp_using_mono (const char * const *sources,
"mcs --version >/dev/null 2>/dev/null"
and (to exclude an unrelated 'mcs' program on QNX 6)
"mcs --version 2>/dev/null | grep Mono >/dev/null" */
- char *argv[3];
+ const char *argv[3];
pid_t child;
int fd[1];
int exitstatus;
@@ -121,8 +121,8 @@ compile_csharp_using_mono (const char * const *sources,
if (mcs_present)
{
unsigned int argc;
- char **argv;
- char **argp;
+ const char **argv;
+ const char **argp;
pid_t child;
int fd[1];
FILE *fp;
@@ -136,7 +136,7 @@ compile_csharp_using_mono (const char * const *sources,
argc =
1 + (output_is_library ? 1 : 0) + 1 + libdirs_count + libraries_count
+ (debug ? 1 : 0) + sources_count;
- argv = (char **) xmalloca ((argc + 1) * sizeof (char *));
+ argv = (const char **) xmalloca ((argc + 1) * sizeof (const char *));
argp = argv;
*argp++ = "mcs";
@@ -179,7 +179,7 @@ compile_csharp_using_mono (const char * const *sources,
*argp++ = option;
}
else
- *argp++ = (char *) source_file;
+ *argp++ = source_file;
}
*argp = NULL;
/* Ensure argv length was correctly calculated. */
@@ -232,10 +232,10 @@ compile_csharp_using_mono (const char * const *sources,
i < 1 + (output_is_library ? 1 : 0)
+ 1 + libdirs_count + libraries_count;
i++)
- freea (argv[i]);
+ freea ((char *) argv[i]);
for (i = 0; i < sources_count; i++)
if (argv[argc - sources_count + i] != sources[i])
- freea (argv[argc - sources_count + i]);
+ freea ((char *) argv[argc - sources_count + i]);
freea (argv);
return (exitstatus != 0);
@@ -263,7 +263,7 @@ compile_csharp_using_sscli (const char * const *sources,
/* Test for presence of csc:
"csc -help >/dev/null 2>/dev/null \
&& ! { csc -help 2>/dev/null | grep -i chicken > /dev/null; }" */
- char *argv[3];
+ const char *argv[3];
pid_t child;
int fd[1];
int exitstatus;
@@ -312,20 +312,19 @@ compile_csharp_using_sscli (const char * const *sources,
if (csc_present)
{
unsigned int argc;
- char **argv;
- char **argp;
+ const char **argv;
+ const char **argp;
int exitstatus;
unsigned int i;
argc =
1 + 1 + 1 + libdirs_count + libraries_count
+ (optimize ? 1 : 0) + (debug ? 1 : 0) + sources_count;
- argv = (char **) xmalloca ((argc + 1) * sizeof (char *));
+ argv = (const char **) xmalloca ((argc + 1) * sizeof (const char *));
argp = argv;
*argp++ = "csc";
- *argp++ =
- (char *) (output_is_library ? "-target:library" : "-target:exe");
+ *argp++ = (output_is_library ? "-target:library" : "-target:exe");
{
char *option = (char *) xmalloca (5 + strlen (output_file) + 1);
memcpy (option, "-out:", 5);
@@ -365,7 +364,7 @@ compile_csharp_using_sscli (const char * const *sources,
*argp++ = option;
}
else
- *argp++ = (char *) source_file;
+ *argp++ = source_file;
}
*argp = NULL;
/* Ensure argv length was correctly calculated. */
@@ -384,10 +383,10 @@ compile_csharp_using_sscli (const char * const *sources,
true, true, NULL);
for (i = 2; i < 3 + libdirs_count + libraries_count; i++)
- freea (argv[i]);
+ freea ((char *) argv[i]);
for (i = 0; i < sources_count; i++)
if (argv[argc - sources_count + i] != sources[i])
- freea (argv[argc - sources_count + i]);
+ freea ((char *) argv[argc - sources_count + i]);
freea (argv);
return (exitstatus != 0);
diff --git a/lib/csharpexec.c b/lib/csharpexec.c
index 5e2aa2c753..b6fcc47333 100644
--- a/lib/csharpexec.c
+++ b/lib/csharpexec.c
@@ -100,7 +100,7 @@ execute_csharp_using_mono (const char *assembly_path,
{
/* Test for presence of mono:
"mono --version >/dev/null 2>/dev/null" */
- char *argv[3];
+ const char *argv[3];
int exitstatus;
argv[0] = "mono";
@@ -116,7 +116,8 @@ execute_csharp_using_mono (const char *assembly_path,
if (mono_present)
{
char *old_monopath;
- char **argv = (char **) xmalloca ((2 + nargs + 1) * sizeof (char *));
+ const char **argv =
+ (const char **) xmalloca ((2 + nargs + 1) * sizeof (const char *));
unsigned int i;
bool err;
@@ -124,9 +125,9 @@ execute_csharp_using_mono (const char *assembly_path,
old_monopath = set_monopath (libdirs, libdirs_count, false, verbose);
argv[0] = "mono";
- argv[1] = (char *) assembly_path;
+ argv[1] = assembly_path;
for (i = 0; i <= nargs; i++)
- argv[2 + i] = (char *) args[i];
+ argv[2 + i] = args[i];
if (verbose)
{
@@ -163,7 +164,7 @@ execute_csharp_using_sscli (const char *assembly_path,
{
/* Test for presence of clix:
"clix >/dev/null 2>/dev/null ; test $? = 1" */
- char *argv[2];
+ const char *argv[2];
int exitstatus;
argv[0] = "clix";
@@ -178,7 +179,8 @@ execute_csharp_using_sscli (const char *assembly_path,
if (clix_present)
{
char *old_clixpath;
- char **argv = (char **) xmalloca ((2 + nargs + 1) * sizeof (char *));
+ const char **argv =
+ (const char **) xmalloca ((2 + nargs + 1) * sizeof (const char *));
unsigned int i;
bool err;
@@ -186,9 +188,9 @@ execute_csharp_using_sscli (const char *assembly_path,
old_clixpath = set_clixpath (libdirs, libdirs_count, false, verbose);
argv[0] = "clix";
- argv[1] = (char *) assembly_path;
+ argv[1] = assembly_path;
for (i = 0; i <= nargs; i++)
- argv[2 + i] = (char *) args[i];
+ argv[2 + i] = args[i];
if (verbose)
{
diff --git a/lib/csharpexec.h b/lib/csharpexec.h
index c0bb441521..088ac06ffa 100644
--- a/lib/csharpexec.h
+++ b/lib/csharpexec.h
@@ -21,7 +21,7 @@
#include <stdbool.h>
typedef bool execute_fn (const char *progname,
- const char *prog_path, char **prog_argv,
+ const char *prog_path, const char * const *prog_argv,
void *private_data);
/* Execute a C# program.
diff --git a/lib/execute.c b/lib/execute.c
index 5821e82877..bdc0c0c016 100644
--- a/lib/execute.c
+++ b/lib/execute.c
@@ -97,7 +97,7 @@ nonintr_open (const char *pathname, int oflag, mode_t mode)
int
execute (const char *progname,
- const char *prog_path, char **prog_argv,
+ const char *prog_path, const char * const *prog_argv,
const char *directory,
bool ignore_sigpipe,
bool null_stdin, bool null_stdout, bool null_stderr,
@@ -158,10 +158,10 @@ execute (const char *progname,
/* Native Windows API. */
- char *prog_argv_mem_to_free;
+ char *argv_mem_to_free;
- prog_argv = prepare_spawn (prog_argv, &prog_argv_mem_to_free);
- if (prog_argv == NULL)
+ const char **argv = prepare_spawn (prog_argv, &argv_mem_to_free);
+ if (argv == NULL)
xalloc_die ();
int exitcode = -1;
@@ -188,17 +188,17 @@ execute (const char *progname,
HANDLE stderr_handle =
(HANDLE) _get_osfhandle (null_stderr ? nulloutfd : STDERR_FILENO);
- exitcode = spawnpvech (P_WAIT, prog_path, (const char **) (prog_argv + 1),
- (const char **) environ, directory,
+ exitcode = spawnpvech (P_WAIT, prog_path, argv + 1,
+ (const char * const *) environ, directory,
stdin_handle, stdout_handle, stderr_handle);
if (exitcode == -1 && errno == ENOEXEC)
{
/* prog is not a native executable. Try to execute it as a
shell script. Note that prepare_spawn() has already prepended
- a hidden element "sh.exe" to prog_argv. */
- prog_argv[1] = prog_path;
- exitcode = spawnpvech (P_WAIT, prog_argv[0], (const char **) prog_argv,
- (const char **) environ, directory,
+ a hidden element "sh.exe" to argv. */
+ argv[1] = prog_path;
+ exitcode = spawnpvech (P_WAIT, argv[0], argv,
+ (const char * const *) environ, directory,
stdin_handle, stdout_handle, stderr_handle);
}
}
@@ -208,8 +208,8 @@ execute (const char *progname,
close (nulloutfd);
if (nullinfd >= 0)
close (nullinfd);
- free (prog_argv);
- free (prog_argv_mem_to_free);
+ free (argv);
+ free (argv_mem_to_free);
free (prog_path_to_free);
if (termsigp != NULL)
@@ -277,11 +277,11 @@ execute (const char *progname,
!= 0)))
|| (err = (directory != NULL
? posix_spawn (&child, prog_path, &actions,
- attrs_allocated ? &attrs : NULL, prog_argv,
- environ)
+ attrs_allocated ? &attrs : NULL,
+ (char * const *) prog_argv, environ)
: posix_spawnp (&child, prog_path, &actions,
- attrs_allocated ? &attrs : NULL, prog_argv,
- environ)))
+ attrs_allocated ? &attrs : NULL,
+ (char * const *) prog_argv, environ)))
!= 0))
{
if (actions_allocated)
diff --git a/lib/execute.h b/lib/execute.h
index 34fc989668..908d8c537a 100644
--- a/lib/execute.h
+++ b/lib/execute.h
@@ -46,7 +46,7 @@
It is recommended that no signal is blocked or ignored while execute()
is called. See spawn-pipe.h for the reason. */
extern int execute (const char *progname,
- const char *prog_path, char **prog_argv,
+ const char *prog_path, const char * const *prog_argv,
const char *directory,
bool ignore_sigpipe,
bool null_stdin, bool null_stdout, bool null_stderr,
diff --git a/lib/javacomp.c b/lib/javacomp.c
index c24bb69166..ca7a6fe658 100644
--- a/lib/javacomp.c
+++ b/lib/javacomp.c
@@ -288,7 +288,7 @@ compile_using_envjavac (const char *javac,
bool err;
unsigned int command_length;
char *command;
- char *argv[4];
+ const char *argv[4];
int exitstatus;
unsigned int i;
char *p;
@@ -367,8 +367,8 @@ compile_using_gcj (const char * const *java_sources,
{
bool err;
unsigned int argc;
- char **argv;
- char **argp;
+ const char **argv;
+ const char **argp;
char *fsource_arg;
char *ftarget_arg;
int exitstatus;
@@ -378,7 +378,7 @@ compile_using_gcj (const char * const *java_sources,
2 + (no_assert_option ? 1 : 0) + (fsource_option ? 1 : 0)
+ (ftarget_option ? 1 : 0) + (optimize ? 1 : 0) + (debug ? 1 : 0)
+ (directory != NULL ? 2 : 0) + java_sources_count;
- argv = (char **) xmalloca ((argc + 1) * sizeof (char *));
+ argv = (const char **) xmalloca ((argc + 1) * sizeof (const char *));
argp = argv;
*argp++ = "gcj";
@@ -410,10 +410,10 @@ compile_using_gcj (const char * const *java_sources,
if (directory != NULL)
{
*argp++ = "-d";
- *argp++ = (char *) directory;
+ *argp++ = directory;
}
for (i = 0; i < java_sources_count; i++)
- *argp++ = (char *) java_sources[i];
+ *argp++ = java_sources[i];
*argp = NULL;
/* Ensure argv length was correctly calculated. */
if (argp - argv != argc)
@@ -453,27 +453,27 @@ compile_using_javac (const char * const *java_sources,
{
bool err;
unsigned int argc;
- char **argv;
- char **argp;
+ const char **argv;
+ const char **argp;
int exitstatus;
unsigned int i;
argc =
1 + (source_option ? 2 : 0) + (target_option ? 2 : 0) + (optimize ? 1 : 0)
+ (debug ? 1 : 0) + (directory != NULL ? 2 : 0) + java_sources_count;
- argv = (char **) xmalloca ((argc + 1) * sizeof (char *));
+ argv = (const char **) xmalloca ((argc + 1) * sizeof (const char *));
argp = argv;
*argp++ = "javac";
if (source_option)
{
*argp++ = "-source";
- *argp++ = (char *) source_version;
+ *argp++ = source_version;
}
if (target_option)
{
*argp++ = "-target";
- *argp++ = (char *) target_version;
+ *argp++ = target_version;
}
if (optimize)
*argp++ = "-O";
@@ -482,10 +482,10 @@ compile_using_javac (const char * const *java_sources,
if (directory != NULL)
{
*argp++ = "-d";
- *argp++ = (char *) directory;
+ *argp++ = directory;
}
for (i = 0; i < java_sources_count; i++)
- *argp++ = (char *) java_sources[i];
+ *argp++ = java_sources[i];
*argp = NULL;
/* Ensure argv length was correctly calculated. */
if (argp - argv != argc)
@@ -519,15 +519,15 @@ compile_using_jikes (const char * const *java_sources,
{
bool err;
unsigned int argc;
- char **argv;
- char **argp;
+ const char **argv;
+ const char **argp;
int exitstatus;
unsigned int i;
argc =
1 + (optimize ? 1 : 0) + (debug ? 1 : 0) + (directory != NULL ? 2 : 0)
+ java_sources_count;
- argv = (char **) xmalloca ((argc + 1) * sizeof (char *));
+ argv = (const char **) xmalloca ((argc + 1) * sizeof (const char *));
argp = argv;
*argp++ = "jikes";
@@ -538,10 +538,10 @@ compile_using_jikes (const char * const *java_sources,
if (directory != NULL)
{
*argp++ = "-d";
- *argp++ = (char *) directory;
+ *argp++ = directory;
}
for (i = 0; i < java_sources_count; i++)
- *argp++ = (char *) java_sources[i];
+ *argp++ = java_sources[i];
*argp = NULL;
/* Ensure argv length was correctly calculated. */
if (argp - argv != argc)
@@ -635,7 +635,7 @@ is_envjavac_gcj (const char *javac)
"$JAVAC --version 2>/dev/null | sed -e 1q | grep gcj > /dev/null" */
unsigned int command_length;
char *command;
- char *argv[4];
+ const char *argv[4];
pid_t child;
int fd[1];
FILE *fp;
@@ -717,7 +717,7 @@ is_envjavac_gcj43 (const char *javac)
| sed -e '/^4\.[012]/d' | grep '^[4-9]' >/dev/null" */
unsigned int command_length;
char *command;
- char *argv[4];
+ const char *argv[4];
pid_t child;
int fd[1];
FILE *fp;
@@ -1406,7 +1406,7 @@ is_gcj_present (void)
"gcj --version 2> /dev/null | \
sed -e 's,^[^0-9]*,,' -e 1q | \
sed -e '/^3\.[01]/d' | grep '^[3-9]' > /dev/null" */
- char *argv[3];
+ const char *argv[3];
pid_t child;
int fd[1];
int exitstatus;
@@ -1522,7 +1522,7 @@ is_gcj_43 (void)
"gcj --version 2> /dev/null | \
sed -e 's,^[^0-9]*,,' -e 1q | \
sed -e '/^4\.[012]/d' | grep '^[4-9]'" */
- char *argv[3];
+ const char *argv[3];
pid_t child;
int fd[1];
int exitstatus;
@@ -1871,7 +1871,7 @@ is_javac_present (void)
if (!javac_tested)
{
/* Test for presence of javac: "javac 2> /dev/null ; test $? -le 2" */
- char *argv[2];
+ const char *argv[2];
int exitstatus;
argv[0] = "javac";
@@ -2138,7 +2138,7 @@ is_jikes_present (void)
if (!jikes_tested)
{
/* Test for presence of jikes: "jikes 2> /dev/null ; test $? = 1" */
- char *argv[2];
+ const char *argv[2];
int exitstatus;
argv[0] = "jikes";
diff --git a/lib/javaexec.c b/lib/javaexec.c
index d486fb8715..613c7fc7aa 100644
--- a/lib/javaexec.c
+++ b/lib/javaexec.c
@@ -96,7 +96,8 @@ execute_java_class (const char *class_name,
{
char *exe_pathname = xconcatenated_filename (exe_dir, class_name, EXEEXT);
char *old_classpath;
- char **argv = (char **) xmalloca ((1 + nargs + 1) * sizeof (char *));
+ const char **argv =
+ (const char **) xmalloca ((1 + nargs + 1) * sizeof (const char *));
unsigned int i;
/* Set CLASSPATH. */
@@ -106,7 +107,7 @@ execute_java_class (const char *class_name,
argv[0] = exe_pathname;
for (i = 0; i <= nargs; i++)
- argv[1 + i] = (char *) args[i];
+ argv[1 + i] = args[i];
if (verbose)
{
@@ -136,7 +137,7 @@ execute_java_class (const char *class_name,
char *old_classpath;
unsigned int command_length;
char *command;
- char *argv[4];
+ const char *argv[4];
const char * const *arg;
char *p;
@@ -202,7 +203,7 @@ execute_java_class (const char *class_name,
if (!gij_tested)
{
/* Test for presence of gij: "gij --version > /dev/null" */
- char *argv[3];
+ const char *argv[3];
int exitstatus;
argv[0] = "gij";
@@ -218,7 +219,8 @@ execute_java_class (const char *class_name,
if (gij_present)
{
char *old_classpath;
- char **argv = (char **) xmalloca ((2 + nargs + 1) * sizeof (char *));
+ const char **argv =
+ (const char **) xmalloca ((2 + nargs + 1) * sizeof (const char *));
unsigned int i;
/* Set CLASSPATH. */
@@ -227,9 +229,9 @@ execute_java_class (const char *class_name,
verbose);
argv[0] = "gij";
- argv[1] = (char *) class_name;
+ argv[1] = class_name;
for (i = 0; i <= nargs; i++)
- argv[2 + i] = (char *) args[i];
+ argv[2 + i] = args[i];
if (verbose)
{
@@ -256,7 +258,7 @@ execute_java_class (const char *class_name,
if (!java_tested)
{
/* Test for presence of java: "java -version 2> /dev/null" */
- char *argv[3];
+ const char *argv[3];
int exitstatus;
argv[0] = "java";
@@ -272,7 +274,8 @@ execute_java_class (const char *class_name,
if (java_present)
{
char *old_classpath;
- char **argv = (char **) xmalloca ((2 + nargs + 1) * sizeof (char *));
+ const char **argv =
+ (const char **) xmalloca ((2 + nargs + 1) * sizeof (const char *));
unsigned int i;
/* Set CLASSPATH. We don't use the "-classpath ..." option because
@@ -283,9 +286,9 @@ execute_java_class (const char *class_name,
verbose);
argv[0] = "java";
- argv[1] = (char *) class_name;
+ argv[1] = class_name;
for (i = 0; i <= nargs; i++)
- argv[2 + i] = (char *) args[i];
+ argv[2 + i] = args[i];
if (verbose)
{
@@ -312,7 +315,7 @@ execute_java_class (const char *class_name,
if (!jre_tested)
{
/* Test for presence of jre: "jre 2> /dev/null ; test $? = 1" */
- char *argv[2];
+ const char *argv[2];
int exitstatus;
argv[0] = "jre";
@@ -327,7 +330,8 @@ execute_java_class (const char *class_name,
if (jre_present)
{
char *old_classpath;
- char **argv = (char **) xmalloca ((2 + nargs + 1) * sizeof (char *));
+ const char **argv =
+ (const char **) xmalloca ((2 + nargs + 1) * sizeof (const char *));
unsigned int i;
/* Set CLASSPATH. We don't use the "-classpath ..." option because
@@ -338,9 +342,9 @@ execute_java_class (const char *class_name,
verbose);
argv[0] = "jre";
- argv[1] = (char *) class_name;
+ argv[1] = class_name;
for (i = 0; i <= nargs; i++)
- argv[2 + i] = (char *) args[i];
+ argv[2 + i] = args[i];
if (verbose)
{
@@ -369,7 +373,7 @@ execute_java_class (const char *class_name,
if (!jview_tested)
{
/* Test for presence of jview: "jview -? >nul ; test $? = 1" */
- char *argv[3];
+ const char *argv[3];
int exitstatus;
argv[0] = "jview";
@@ -385,7 +389,8 @@ execute_java_class (const char *class_name,
if (jview_present)
{
char *old_classpath;
- char **argv = (char **) xmalloca ((2 + nargs + 1) * sizeof (char *));
+ const char **argv =
+ (const char **) xmalloca ((2 + nargs + 1) * sizeof (const char *));
unsigned int i;
/* Set CLASSPATH. */
@@ -394,9 +399,9 @@ execute_java_class (const char *class_name,
verbose);
argv[0] = "jview";
- argv[1] = (char *) class_name;
+ argv[1] = class_name;
for (i = 0; i <= nargs; i++)
- argv[2 + i] = (char *) args[i];
+ argv[2 + i] = args[i];
if (verbose)
{
diff --git a/lib/javaexec.h b/lib/javaexec.h
index c17a6947ca..9480e73251 100644
--- a/lib/javaexec.h
+++ b/lib/javaexec.h
@@ -21,7 +21,7 @@
#include <stdbool.h>
typedef bool execute_fn (const char *progname,
- const char *prog_path, char **prog_argv,
+ const char *prog_path, const char * const *prog_argv,
void *private_data);
/* Execute a Java class.
diff --git a/lib/javaversion.c b/lib/javaversion.c
index e50c499c9b..2bfb08f662 100644
--- a/lib/javaversion.c
+++ b/lib/javaversion.c
@@ -52,7 +52,7 @@ struct locals
static bool
execute_and_read_line (const char *progname,
- const char *prog_path, char **prog_argv,
+ const char *prog_path, const char * const *prog_argv,
void *private_data)
{
struct locals *l = (struct locals *) private_data;
diff --git a/lib/os2-spawn.c b/lib/os2-spawn.c
index 53a35f6dff..ac425a32d8 100644
--- a/lib/os2-spawn.c
+++ b/lib/os2-spawn.c
@@ -92,11 +92,11 @@ undup_safer_noinherit (int tempfd, int origfd)
}
}
-char **
-prepare_spawn (char **argv, char **mem_to_free)
+const char **
+prepare_spawn (const char * const *argv, char **mem_to_free)
{
size_t argc;
- char **new_argv;
+ const char **new_argv;
size_t i;
/* Count number of arguments. */
@@ -104,7 +104,7 @@ prepare_spawn (char **argv, char **mem_to_free)
;
/* Allocate new argument vector. */
- new_argv = (char **) malloc ((1 + argc + 1) * sizeof (char *));
+ new_argv = (const char **) malloc ((1 + argc + 1) * sizeof (const char *));
if (new_argv == NULL)
return NULL;
diff --git a/lib/os2-spawn.h b/lib/os2-spawn.h
index 4c8c6a89fd..419f7f967d 100644
--- a/lib/os2-spawn.h
+++ b/lib/os2-spawn.h
@@ -27,6 +27,7 @@ extern int dup_safer_noinherit (int fd);
extern void undup_safer_noinherit (int tempfd, int origfd);
/* Prepares an argument vector before calling spawn(). */
-extern char ** prepare_spawn (char **argv, char **mem_to_free);
+extern const char ** prepare_spawn (const char * const *argv,
+ char **mem_to_free);
#endif /* _OS2_SPAWN_H */
diff --git a/lib/pipe-filter-gi.c b/lib/pipe-filter-gi.c
index 7528053c6b..80617d7dec 100644
--- a/lib/pipe-filter-gi.c
+++ b/lib/pipe-filter-gi.c
@@ -485,7 +485,7 @@ filter_retcode (struct pipe_filter_gi *filter)
struct pipe_filter_gi *
pipe_filter_gi_create (const char *progname,
- const char *prog_path, const char **prog_argv,
+ const char *prog_path, const char * const *prog_argv,
bool null_stderr, bool exit_on_error,
prepare_read_fn prepare_read,
done_read_fn done_read,
@@ -497,7 +497,7 @@ pipe_filter_gi_create (const char *progname,
(struct pipe_filter_gi *) xmalloc (sizeof (struct pipe_filter_gi));
/* Open a bidirectional pipe to a subprocess. */
- filter->child = create_pipe_bidi (progname, prog_path, (char **) prog_argv,
+ filter->child = create_pipe_bidi (progname, prog_path, prog_argv,
NULL, null_stderr, true, exit_on_error,
filter->fd);
filter->progname = progname;
diff --git a/lib/pipe-filter-ii.c b/lib/pipe-filter-ii.c
index 384a59bf68..2342088c10 100644
--- a/lib/pipe-filter-ii.c
+++ b/lib/pipe-filter-ii.c
@@ -255,7 +255,7 @@ reader_thread_func (void *thread_arg)
int
pipe_filter_ii_execute (const char *progname,
- const char *prog_path, const char **prog_argv,
+ const char *prog_path, const char * const *prog_argv,
bool null_stderr, bool exit_on_error,
prepare_write_fn prepare_write,
done_write_fn done_write,
@@ -270,7 +270,7 @@ pipe_filter_ii_execute (const char *progname,
#endif
/* Open a bidirectional pipe to a subprocess. */
- child = create_pipe_bidi (progname, prog_path, (char **) prog_argv,
+ child = create_pipe_bidi (progname, prog_path, prog_argv,
NULL, null_stderr, true, exit_on_error,
fd);
if (child == -1)
diff --git a/lib/pipe-filter.h b/lib/pipe-filter.h
index 9e2c966a5f..71ef70b387 100644
--- a/lib/pipe-filter.h
+++ b/lib/pipe-filter.h
@@ -133,7 +133,8 @@ typedef void (*done_read_fn) (void *data_read, size_t num_bytes_read,
- the positive exit code of the subprocess if that failed. */
extern int
pipe_filter_ii_execute (const char *progname,
- const char *prog_path, const char **prog_argv,
+ const char *prog_path,
+ const char * const *prog_argv,
bool null_stderr, bool exit_on_error,
prepare_write_fn prepare_write,
done_write_fn done_write,
@@ -179,7 +180,8 @@ struct pipe_filter_gi;
Return the freshly created 'struct pipe_filter_gi'. */
extern struct pipe_filter_gi *
pipe_filter_gi_create (const char *progname,
- const char *prog_path, const char **prog_argv,
+ const char *prog_path,
+ const char * const *prog_argv,
bool null_stderr, bool exit_on_error,
prepare_read_fn prepare_read,
done_read_fn done_read,
diff --git a/lib/sh-quote.c b/lib/sh-quote.c
index 1508d4e465..8181c7a25e 100644
--- a/lib/sh-quote.c
+++ b/lib/sh-quote.c
@@ -69,11 +69,11 @@ shell_quote (const char *string)
/* Returns a freshly allocated string containing all argument strings, quoted,
separated through spaces. */
char *
-shell_quote_argv (char * const *argv)
+shell_quote_argv (const char * const *argv)
{
if (*argv != NULL)
{
- char * const *argp;
+ const char * const *argp;
size_t length;
char *command;
char *p;
diff --git a/lib/sh-quote.h b/lib/sh-quote.h
index 8b06355835..9c6f2aa82a 100644
--- a/lib/sh-quote.h
+++ b/lib/sh-quote.h
@@ -40,7 +40,7 @@ extern char * shell_quote (const char *string);
/* Returns a freshly allocated string containing all argument strings, quoted,
separated through spaces. */
-extern char * shell_quote_argv (char * const *argv);
+extern char * shell_quote_argv (const char * const *argv);
#ifdef __cplusplus
}
diff --git a/lib/spawn-pipe.c b/lib/spawn-pipe.c
index c73872bf82..ba07d20ebc 100644
--- a/lib/spawn-pipe.c
+++ b/lib/spawn-pipe.c
@@ -123,7 +123,8 @@ nonintr_open (const char *pathname, int oflag, mode_t mode)
*/
static pid_t
create_pipe (const char *progname,
- const char *prog_path, char **prog_argv,
+ const char *prog_path,
+ const char * const *prog_argv,
const char *directory,
bool pipe_stdin, bool pipe_stdout,
const char *prog_stdin, const char *prog_stdout,
@@ -187,7 +188,7 @@ create_pipe (const char *progname,
using the low-level functions CreatePipe(), DuplicateHandle(),
CreateProcess() and _open_osfhandle(); see the GNU make and GNU clisp
and cvs source code. */
- char *prog_argv_mem_to_free;
+ char *argv_mem_to_free;
int ifd[2];
int ofd[2];
int child;
@@ -195,8 +196,8 @@ create_pipe (const char *progname,
int stdinfd;
int stdoutfd;
- prog_argv = prepare_spawn (prog_argv, &prog_argv_mem_to_free);
- if (prog_argv == NULL)
+ const char **argv = prepare_spawn (prog_argv, &argv_mem_to_free);
+ if (argv == NULL)
xalloc_die ();
if (pipe_stdout)
@@ -281,17 +282,17 @@ create_pipe (const char *progname,
HANDLE stderr_handle =
(HANDLE) _get_osfhandle (null_stderr ? nulloutfd : STDERR_FILENO);
- child = spawnpvech (P_NOWAIT, prog_path, (const char **) (prog_argv + 1),
- (const char **) environ, directory,
+ child = spawnpvech (P_NOWAIT, prog_path, argv + 1,
+ (const char * const *) environ, directory,
stdin_handle, stdout_handle, stderr_handle);
if (child == -1 && errno == ENOEXEC)
{
/* prog is not a native executable. Try to execute it as a
shell script. Note that prepare_spawn() has already prepended
- a hidden element "sh.exe" to prog_argv. */
- prog_argv[1] = prog_path;
- child = spawnpvech (P_NOWAIT, prog_argv[0], (const char **) prog_argv,
- (const char **) environ, directory,
+ a hidden element "sh.exe" to argv. */
+ argv[1] = prog_path;
+ child = spawnpvech (P_NOWAIT, argv[0], argv,
+ (const char * const *) environ, directory,
stdin_handle, stdout_handle, stderr_handle);
}
}
@@ -357,14 +358,14 @@ create_pipe (const char *progname,
but it inherits all open()ed or dup2()ed file handles (which is what
we want in the case of STD*_FILENO). */
{
- child = _spawnvpe (P_NOWAIT, prog_path, (const char **) (prog_argv + 1),
+ child = _spawnvpe (P_NOWAIT, prog_path, argv + 1,
(const char **) environ);
if (child == -1 && errno == ENOEXEC)
{
/* prog is not a native executable. Try to execute it as a
shell script. Note that prepare_spawn() has already prepended
- a hidden element "sh.exe" to prog_argv. */
- child = _spawnvpe (P_NOWAIT, prog_argv[0], (const char **) prog_argv,
+ a hidden element "sh.exe" to argv. */
+ child = _spawnvpe (P_NOWAIT, argv[0], argv,
(const char **) environ);
}
}
@@ -391,8 +392,8 @@ create_pipe (const char *progname,
close (ifd[1]);
# endif
- free (prog_argv);
- free (prog_argv_mem_to_free);
+ free (argv);
+ free (argv_mem_to_free);
free (prog_path_to_free);
if (child == -1)
@@ -501,11 +502,11 @@ create_pipe (const char *progname,
!= 0)))
|| (err = (directory != NULL
? posix_spawn (&child, prog_path, &actions,
- attrs_allocated ? &attrs : NULL, prog_argv,
- environ)
+ attrs_allocated ? &attrs : NULL,
+ (char * const *) prog_argv, environ)
: posix_spawnp (&child, prog_path, &actions,
- attrs_allocated ? &attrs : NULL, prog_argv,
- environ)))
+ attrs_allocated ? &attrs : NULL,
+ (char * const *) prog_argv, environ)))
!= 0))
{
if (actions_allocated)
@@ -570,7 +571,7 @@ create_pipe (const char *progname,
*/
pid_t
create_pipe_bidi (const char *progname,
- const char *prog_path, char **prog_argv,
+ const char *prog_path, const char * const *prog_argv,
const char *directory,
bool null_stderr,
bool slave_process, bool exit_on_error,
@@ -592,7 +593,7 @@ create_pipe_bidi (const char *progname,
*/
pid_t
create_pipe_in (const char *progname,
- const char *prog_path, char **prog_argv,
+ const char *prog_path, const char * const *prog_argv,
const char *directory,
const char *prog_stdin, bool null_stderr,
bool slave_process, bool exit_on_error,
@@ -617,7 +618,7 @@ create_pipe_in (const char *progname,
*/
pid_t
create_pipe_out (const char *progname,
- const char *prog_path, char **prog_argv,
+ const char *prog_path, const char * const *prog_argv,
const char *directory,
const char *prog_stdout, bool null_stderr,
bool slave_process, bool exit_on_error,
diff --git a/lib/spawn-pipe.h b/lib/spawn-pipe.h
index 02856a81b7..a624822578 100644
--- a/lib/spawn-pipe.h
+++ b/lib/spawn-pipe.h
@@ -96,7 +96,8 @@ extern "C" {
* signal and the EPIPE error code.
*/
extern pid_t create_pipe_out (const char *progname,
- const char *prog_path, char **prog_argv,
+ const char *prog_path,
+ const char * const *prog_argv,
const char *directory,
const char *prog_stdout, bool null_stderr,
bool slave_process, bool exit_on_error,
@@ -110,7 +111,8 @@ extern pid_t create_pipe_out (const char *progname,
*
*/
extern pid_t create_pipe_in (const char *progname,
- const char *prog_path, char **prog_argv,
+ const char *prog_path,
+ const char * const *prog_argv,
const char *directory,
const char *prog_stdin, bool null_stderr,
bool slave_process, bool exit_on_error,
@@ -139,7 +141,8 @@ extern pid_t create_pipe_in (const char *progname,
* input. But you are currently busy reading from it.
*/
extern pid_t create_pipe_bidi (const char *progname,
- const char *prog_path, char **prog_argv,
+ const char *prog_path,
+ const char * const *prog_argv,
const char *directory,
bool null_stderr,
bool slave_process, bool exit_on_error,
diff --git a/lib/windows-spawn.c b/lib/windows-spawn.c
index d252f32980..88a6b4dba4 100644
--- a/lib/windows-spawn.c
+++ b/lib/windows-spawn.c
@@ -122,11 +122,11 @@ quoted_arg_string (const char *string, char *mem)
return p;
}
-char **
-prepare_spawn (char **argv, char **mem_to_free)
+const char **
+prepare_spawn (const char * const *argv, char **mem_to_free)
{
size_t argc;
- char **new_argv;
+ const char **new_argv;
size_t i;
/* Count number of arguments. */
@@ -134,7 +134,7 @@ prepare_spawn (char **argv, char **mem_to_free)
;
/* Allocate new argument vector. */
- new_argv = (char **) malloc ((1 + argc + 1) * sizeof (char *));
+ new_argv = (const char **) malloc ((1 + argc + 1) * sizeof (const char *));
/* Add an element upfront that can be used when argv[0] turns out to be a
script, not a program.
diff --git a/lib/windows-spawn.h b/lib/windows-spawn.h
index ddbbffa0be..77720d5559 100644
--- a/lib/windows-spawn.h
+++ b/lib/windows-spawn.h
@@ -62,7 +62,8 @@
allocated as well. In case of memory allocation failure, NULL is returned,
with errno set.
*/
-extern char ** prepare_spawn (char **argv, char **mem_to_free);
+extern const char ** prepare_spawn (const char * const *argv,
+ char **mem_to_free);
/* Creates a subprocess.
MODE is either P_WAIT or P_NOWAIT.