diff options
author | Ron Yorston <rmy@pobox.com> | 2024-07-14 13:42:40 +0100 |
---|---|---|
committer | Ron Yorston <rmy@pobox.com> | 2024-07-14 13:42:40 +0100 |
commit | e68706f141f9f30e8dfccb3c0fec480dc68dbd32 (patch) | |
tree | 959b6c5fee3266ddaf090dbc7100f5f1c12e76ec | |
parent | 6198a0ff055751d5cda4017a3d4821dc93ad77d1 (diff) | |
download | busybox-w32-e68706f141f9f30e8dfccb3c0fec480dc68dbd32.tar.gz busybox-w32-e68706f141f9f30e8dfccb3c0fec480dc68dbd32.tar.bz2 busybox-w32-e68706f141f9f30e8dfccb3c0fec480dc68dbd32.zip |
win32: code shrink mingw_spawn_interpreter()
Rewrite mingw_spawn_interpreter() to remove a duplicated recursive
call.
Saves 32-48 bytes.
-rw-r--r-- | win32/process.c | 19 |
1 files changed, 8 insertions, 11 deletions
diff --git a/win32/process.c b/win32/process.c index b69a1c02b..57e410a73 100644 --- a/win32/process.c +++ b/win32/process.c | |||
@@ -307,6 +307,7 @@ mingw_spawn_interpreter(int mode, const char *prog, char *const *argv, | |||
307 | interp_t interp; | 307 | interp_t interp; |
308 | char **new_argv; | 308 | char **new_argv; |
309 | char *path = NULL; | 309 | char *path = NULL; |
310 | int is_unix_path; | ||
310 | 311 | ||
311 | if (!parse_interpreter(prog, &interp)) | 312 | if (!parse_interpreter(prog, &interp)) |
312 | return SPAWNVEQ(mode, prog, argv, envp); | 313 | return SPAWNVEQ(mode, prog, argv, envp); |
@@ -321,8 +322,9 @@ mingw_spawn_interpreter(int mode, const char *prog, char *const *argv, | |||
321 | new_argv[1] = interp.opts; | 322 | new_argv[1] = interp.opts; |
322 | new_argv[nopts+1] = (char *)prog; /* pass absolute path */ | 323 | new_argv[nopts+1] = (char *)prog; /* pass absolute path */ |
323 | 324 | ||
325 | is_unix_path = unix_path(interp.path); | ||
324 | #if ENABLE_FEATURE_PREFER_APPLETS && NUM_APPLETS > 1 | 326 | #if ENABLE_FEATURE_PREFER_APPLETS && NUM_APPLETS > 1 |
325 | if (unix_path(interp.path) && find_applet_by_name(interp.name) >= 0) { | 327 | if (is_unix_path && find_applet_by_name(interp.name) >= 0) { |
326 | /* the fake path indicates the index of the script */ | 328 | /* the fake path indicates the index of the script */ |
327 | new_argv[0] = path = xasprintf("%d:/%s", nopts+1, interp.name); | 329 | new_argv[0] = path = xasprintf("%d:/%s", nopts+1, interp.name); |
328 | ret = SPAWNVEQ(mode, bb_busybox_exec_path, new_argv, envp); | 330 | ret = SPAWNVEQ(mode, bb_busybox_exec_path, new_argv, envp); |
@@ -331,20 +333,15 @@ mingw_spawn_interpreter(int mode, const char *prog, char *const *argv, | |||
331 | #endif | 333 | #endif |
332 | 334 | ||
333 | path = file_is_win32_exe(interp.path); | 335 | path = file_is_win32_exe(interp.path); |
336 | if (!path && is_unix_path) | ||
337 | path = find_first_executable(interp.name); | ||
338 | |||
334 | if (path) { | 339 | if (path) { |
335 | new_argv[0] = path; | 340 | new_argv[0] = path; |
336 | ret = mingw_spawn_interpreter(mode, path, new_argv, envp, level); | 341 | ret = mingw_spawn_interpreter(mode, path, new_argv, envp, level); |
337 | goto done; | 342 | } else { |
338 | } | 343 | errno = ENOENT; |
339 | |||
340 | if (unix_path(interp.path)) { | ||
341 | if ((path = find_first_executable(interp.name)) != NULL) { | ||
342 | new_argv[0] = path; | ||
343 | ret = mingw_spawn_interpreter(mode, path, new_argv, envp, level); | ||
344 | goto done; | ||
345 | } | ||
346 | } | 344 | } |
347 | errno = ENOENT; | ||
348 | done: | 345 | done: |
349 | free(path); | 346 | free(path); |
350 | free(new_argv); | 347 | free(new_argv); |