aboutsummaryrefslogtreecommitdiff
path: root/win32/process.c
diff options
context:
space:
mode:
authorRon Yorston <rmy@pobox.com>2023-03-16 10:47:09 +0000
committerRon Yorston <rmy@pobox.com>2023-03-16 10:47:09 +0000
commit184edf9bd672bc93856157098d528eab48948ba9 (patch)
tree183531c00207b293de9a609384e0ef9ff7dbfac5 /win32/process.c
parent385decd6bf62c116565ece1e0992ff7a79d48474 (diff)
downloadbusybox-w32-184edf9bd672bc93856157098d528eab48948ba9.tar.gz
busybox-w32-184edf9bd672bc93856157098d528eab48948ba9.tar.bz2
busybox-w32-184edf9bd672bc93856157098d528eab48948ba9.zip
win32: code shrink detection of executables
Add a function, file_is_win32_exe(), to detect if a path refers to an executable. It tries adding extensions if necessary. Use this in a number of places to replace common code of the form path = alloc_ext_space(cmd); if (add_win32_extension(path) || file_is_executable(path)) Saves 32-48 bytes.
Diffstat (limited to 'win32/process.c')
-rw-r--r--win32/process.c11
1 files changed, 4 insertions, 7 deletions
diff --git a/win32/process.c b/win32/process.c
index 0585f66a6..a0678f50d 100644
--- a/win32/process.c
+++ b/win32/process.c
@@ -328,14 +328,12 @@ mingw_spawn_interpreter(int mode, const char *prog, char *const *argv,
328 } 328 }
329#endif 329#endif
330 330
331 path = alloc_ext_space(interp.path); 331 path = file_is_win32_exe(interp.path);
332 if ((add_win32_extension(path) || file_is_executable(path))) { 332 if (path) {
333 new_argv[0] = path; 333 new_argv[0] = path;
334 ret = mingw_spawn_interpreter(mode, path, new_argv, envp, level); 334 ret = mingw_spawn_interpreter(mode, path, new_argv, envp, level);
335 goto done; 335 goto done;
336 } 336 }
337 free(path);
338 path = NULL;
339 337
340 if (unix_path(interp.path)) { 338 if (unix_path(interp.path)) {
341 if ((path = find_first_executable(interp.name)) != NULL) { 339 if ((path = find_first_executable(interp.name)) != NULL) {
@@ -363,13 +361,12 @@ mingw_spawnvp(int mode, const char *cmd, char *const *argv)
363 return mingw_spawn_applet(mode, argv, NULL); 361 return mingw_spawn_applet(mode, argv, NULL);
364#endif 362#endif
365 if (has_path(cmd)) { 363 if (has_path(cmd)) {
366 path = alloc_ext_space(cmd); 364 path = file_is_win32_exe(cmd);
367 if (add_win32_extension(path) || file_is_executable(path)) { 365 if (path) {
368 ret = mingw_spawn_interpreter(mode, path, argv, NULL, 0); 366 ret = mingw_spawn_interpreter(mode, path, argv, NULL, 0);
369 free(path); 367 free(path);
370 return ret; 368 return ret;
371 } 369 }
372 free(path);
373 if (unix_path(cmd)) 370 if (unix_path(cmd))
374 cmd = bb_basename(cmd); 371 cmd = bb_basename(cmd);
375 } 372 }