diff options
author | Ron Yorston <rmy@pobox.com> | 2023-04-28 14:05:59 +0100 |
---|---|---|
committer | Ron Yorston <rmy@pobox.com> | 2023-04-28 14:05:59 +0100 |
commit | 5d417695bcd5af331acf69690312deff61b233d0 (patch) | |
tree | 71f632f40cc05e9ac1f3dea798c34c887b6a8bba /win32/process.c | |
parent | e790046619f539356b950a5b07cba2f477401b4b (diff) | |
download | busybox-w32-5d417695bcd5af331acf69690312deff61b233d0.tar.gz busybox-w32-5d417695bcd5af331acf69690312deff61b233d0.tar.bz2 busybox-w32-5d417695bcd5af331acf69690312deff61b233d0.zip |
win32: code shrink copying of argv
There are two places where a copy of an argv array is made with
extra space at the start. Move this code into a function.
Saves 56-64 bytes.
Diffstat (limited to '')
-rw-r--r-- | win32/process.c | 18 |
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 */ | ||
263 | char ** FAST_FUNC | ||
264 | grow_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 | |||
262 | static intptr_t | 275 | static intptr_t |
263 | mingw_spawn_interpreter(int mode, const char *prog, char *const *argv, | 276 | mingw_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) { |