diff options
author | Ron Yorston <rmy@pobox.com> | 2020-08-23 10:16:12 +0100 |
---|---|---|
committer | Ron Yorston <rmy@pobox.com> | 2020-08-23 10:16:12 +0100 |
commit | 64ecd10486934c12336dac84c67a1939dce0e096 (patch) | |
tree | 73e8bc6b07176b84295fd07f19828292a240f693 /win32/process.c | |
parent | d6b557547551dd80a389f361a995a97ef5930a63 (diff) | |
download | busybox-w32-64ecd10486934c12336dac84c67a1939dce0e096.tar.gz busybox-w32-64ecd10486934c12336dac84c67a1939dce0e096.tar.bz2 busybox-w32-64ecd10486934c12336dac84c67a1939dce0e096.zip |
win32: code shrink Unix-style path handling
Replace auto_add_system_drive() with alloc_system_drive() which
leaves space for a possible filename extension. This makes it
possible to drop alloc_win32_extension() and auto_win32_extension().
Saves 144 bytes.
Diffstat (limited to 'win32/process.c')
-rw-r--r-- | win32/process.c | 28 |
1 files changed, 9 insertions, 19 deletions
diff --git a/win32/process.c b/win32/process.c index a050ec11d..6e758e601 100644 --- a/win32/process.c +++ b/win32/process.c | |||
@@ -63,7 +63,6 @@ static int | |||
63 | parse_interpreter(const char *cmd, interp_t *interp) | 63 | parse_interpreter(const char *cmd, interp_t *interp) |
64 | { | 64 | { |
65 | char *path, *t; | 65 | char *path, *t; |
66 | const char *sd; | ||
67 | int n; | 66 | int n; |
68 | 67 | ||
69 | while (TRUE) { | 68 | while (TRUE) { |
@@ -89,12 +88,6 @@ parse_interpreter(const char *cmd, interp_t *interp) | |||
89 | if (*t == '\0') | 88 | if (*t == '\0') |
90 | break; | 89 | break; |
91 | 90 | ||
92 | sd = need_system_drive(path); | ||
93 | if (sd && strlen(sd) == 2) { | ||
94 | path -= 2; | ||
95 | memcpy(path, sd, 2); | ||
96 | } | ||
97 | |||
98 | interp->path = path; | 91 | interp->path = path; |
99 | interp->name = t; | 92 | interp->name = t; |
100 | interp->opts = strtok(NULL, "\r\n"); | 93 | interp->opts = strtok(NULL, "\r\n"); |
@@ -323,9 +316,9 @@ mingw_spawn_interpreter(int mode, const char *prog, char *const *argv, | |||
323 | new_argv[nopts+1] = (char *)prog; /* pass absolute path */ | 316 | new_argv[nopts+1] = (char *)prog; /* pass absolute path */ |
324 | memcpy(new_argv+nopts+2, argv+1, sizeof(*argv)*argc); | 317 | memcpy(new_argv+nopts+2, argv+1, sizeof(*argv)*argc); |
325 | 318 | ||
326 | if ((fullpath=alloc_win32_extension(interp.path)) != NULL || | 319 | fullpath = alloc_system_drive(interp.path); |
327 | file_is_executable(interp.path)) { | 320 | if (add_win32_extension(fullpath) || file_is_executable(fullpath)) { |
328 | new_argv[0] = fullpath ? fullpath : interp.path; | 321 | new_argv[0] = fullpath; |
329 | ret = mingw_spawn_interpreter(mode, new_argv[0], new_argv, envp, level); | 322 | ret = mingw_spawn_interpreter(mode, new_argv[0], new_argv, envp, level); |
330 | } else | 323 | } else |
331 | #if ENABLE_FEATURE_PREFER_APPLETS || ENABLE_FEATURE_SH_STANDALONE | 324 | #if ENABLE_FEATURE_PREFER_APPLETS || ENABLE_FEATURE_SH_STANDALONE |
@@ -349,7 +342,6 @@ static intptr_t | |||
349 | mingw_spawn_1(int mode, const char *cmd, char *const *argv, char *const *envp) | 342 | mingw_spawn_1(int mode, const char *cmd, char *const *argv, char *const *envp) |
350 | { | 343 | { |
351 | char *prog; | 344 | char *prog; |
352 | const char *path; | ||
353 | intptr_t ret; | 345 | intptr_t ret; |
354 | 346 | ||
355 | #if ENABLE_FEATURE_PREFER_APPLETS || ENABLE_FEATURE_SH_STANDALONE | 347 | #if ENABLE_FEATURE_PREFER_APPLETS || ENABLE_FEATURE_SH_STANDALONE |
@@ -358,15 +350,13 @@ mingw_spawn_1(int mode, const char *cmd, char *const *argv, char *const *envp) | |||
358 | else | 350 | else |
359 | #endif | 351 | #endif |
360 | if (has_path(cmd)) { | 352 | if (has_path(cmd)) { |
353 | char *path = alloc_system_drive(cmd); | ||
354 | add_win32_extension(path); | ||
355 | ret = mingw_spawn_interpreter(mode, path, argv, envp, 0); | ||
356 | free(path); | ||
361 | #if ENABLE_FEATURE_PREFER_APPLETS || ENABLE_FEATURE_SH_STANDALONE | 357 | #if ENABLE_FEATURE_PREFER_APPLETS || ENABLE_FEATURE_SH_STANDALONE |
362 | const char *oldcmd = cmd; | 358 | if (ret == -1 && unix_path(cmd) && |
363 | #endif | 359 | find_applet_by_name(bb_basename(cmd)) >= 0) { |
364 | cmd = auto_add_system_drive(cmd); | ||
365 | path = auto_win32_extension(cmd); | ||
366 | ret = mingw_spawn_interpreter(mode, path ? path : cmd, argv, envp, 0); | ||
367 | #if ENABLE_FEATURE_PREFER_APPLETS || ENABLE_FEATURE_SH_STANDALONE | ||
368 | if (ret == -1 && cmd != oldcmd && unix_path(oldcmd) && | ||
369 | find_applet_by_name(bb_basename(oldcmd))) { | ||
370 | return mingw_spawn_applet(mode, argv, envp); | 360 | return mingw_spawn_applet(mode, argv, envp); |
371 | } | 361 | } |
372 | #endif | 362 | #endif |