aboutsummaryrefslogtreecommitdiff
path: root/win32/process.c
diff options
context:
space:
mode:
Diffstat (limited to 'win32/process.c')
-rw-r--r--win32/process.c18
1 files changed, 14 insertions, 4 deletions
diff --git a/win32/process.c b/win32/process.c
index 5c818a3c0..e93efa103 100644
--- a/win32/process.c
+++ b/win32/process.c
@@ -259,6 +259,19 @@ mingw_spawn_applet(int mode,
259} 259}
260#endif 260#endif
261 261
262/* Make a copy of an argv array with n extra slots at the start */
263char ** FAST_FUNC
264grow_argv(char **argv, int n)
265{
266 char **new_argv;
267 int argc;
268
269 argc = string_array_len(argv) + 1;
270 new_argv = xmalloc(sizeof(*argv) * (argc + n));
271 memcpy(new_argv + n, argv, sizeof(*argv) * argc);
272 return new_argv;
273}
274
262static intptr_t 275static intptr_t
263mingw_spawn_interpreter(int mode, const char *prog, char *const *argv, 276mingw_spawn_interpreter(int mode, const char *prog, char *const *argv,
264 char *const *envp, int level) 277 char *const *envp, int level)
@@ -267,7 +280,6 @@ mingw_spawn_interpreter(int mode, const char *prog, char *const *argv,
267 int nopts; 280 int nopts;
268 interp_t interp; 281 interp_t interp;
269 char **new_argv; 282 char **new_argv;
270 int argc;
271 char *path = NULL; 283 char *path = NULL;
272 284
273 if (!parse_interpreter(prog, &interp)) 285 if (!parse_interpreter(prog, &interp))
@@ -279,11 +291,9 @@ mingw_spawn_interpreter(int mode, const char *prog, char *const *argv,
279 } 291 }
280 292
281 nopts = interp.opts != NULL; 293 nopts = interp.opts != NULL;
282 argc = string_array_len((char **)argv); 294 new_argv = grow_argv((char **)(argv + 1), nopts + 2);
283 new_argv = xmalloc(sizeof(*argv)*(argc+nopts+2));
284 new_argv[1] = interp.opts; 295 new_argv[1] = interp.opts;
285 new_argv[nopts+1] = (char *)prog; /* pass absolute path */ 296 new_argv[nopts+1] = (char *)prog; /* pass absolute path */
286 memcpy(new_argv+nopts+2, argv+1, sizeof(*argv)*argc);
287 297
288#if ENABLE_FEATURE_PREFER_APPLETS && NUM_APPLETS > 1 298#if ENABLE_FEATURE_PREFER_APPLETS && NUM_APPLETS > 1
289 if (unix_path(interp.path) && find_applet_by_name(interp.name) >= 0) { 299 if (unix_path(interp.path) && find_applet_by_name(interp.name) >= 0) {