diff options
author | Nguyễn Thái Ngọc Duy <pclouds@gmail.com> | 2010-04-06 09:52:12 +0200 |
---|---|---|
committer | Nguyễn Thái Ngọc Duy <pclouds@gmail.com> | 2010-09-10 19:28:25 +1000 |
commit | 7a7312a3a10b3f580d7e149d814609660703d53b (patch) | |
tree | 01c8532a370bc4c5fced4c7943a99d266c5ad118 | |
parent | c9158195f6bf0a73bdd5d057d8db7f182397f17c (diff) | |
download | busybox-w32-7a7312a3a10b3f580d7e149d814609660703d53b.tar.gz busybox-w32-7a7312a3a10b3f580d7e149d814609660703d53b.tar.bz2 busybox-w32-7a7312a3a10b3f580d7e149d814609660703d53b.zip |
win32: execable.c: support .exe suffix
-rw-r--r-- | libbb/execable.c | 25 |
1 files changed, 24 insertions, 1 deletions
diff --git a/libbb/execable.c b/libbb/execable.c index 5c7ac16a2..96ce9bfb8 100644 --- a/libbb/execable.c +++ b/libbb/execable.c | |||
@@ -16,6 +16,11 @@ | |||
16 | int FAST_FUNC execable_file(const char *name) | 16 | int FAST_FUNC execable_file(const char *name) |
17 | { | 17 | { |
18 | struct stat s; | 18 | struct stat s; |
19 | if (ENABLE_PLATFORM_MINGW32) { | ||
20 | int len = strlen(name); | ||
21 | return len > 4 && !strcasecmp(name+len-4, ".exe") && | ||
22 | !stat(name, &s) && S_ISREG(s.st_mode); | ||
23 | } | ||
19 | return (!access(name, X_OK) && !stat(name, &s) && S_ISREG(s.st_mode)); | 24 | return (!access(name, X_OK) && !stat(name, &s) && S_ISREG(s.st_mode)); |
20 | } | 25 | } |
21 | 26 | ||
@@ -28,13 +33,17 @@ int FAST_FUNC execable_file(const char *name) | |||
28 | * return NULL otherwise; (PATHp is undefined) | 33 | * return NULL otherwise; (PATHp is undefined) |
29 | * in all cases (*PATHp) contents will be trashed (s/:/NUL/). | 34 | * in all cases (*PATHp) contents will be trashed (s/:/NUL/). |
30 | */ | 35 | */ |
36 | #if !ENABLE_PLATFORM_MINGW32 | ||
37 | #define next_path_sep(s) strchr(s, ':') | ||
38 | #endif | ||
39 | |||
31 | char* FAST_FUNC find_execable(const char *filename, char **PATHp) | 40 | char* FAST_FUNC find_execable(const char *filename, char **PATHp) |
32 | { | 41 | { |
33 | char *p, *n; | 42 | char *p, *n; |
34 | 43 | ||
35 | p = *PATHp; | 44 | p = *PATHp; |
36 | while (p) { | 45 | while (p) { |
37 | n = strchr(p, ':'); | 46 | n = next_path_sep(p); |
38 | if (n) | 47 | if (n) |
39 | *n++ = '\0'; | 48 | *n++ = '\0'; |
40 | if (*p != '\0') { /* it's not a PATH="foo::bar" situation */ | 49 | if (*p != '\0') { /* it's not a PATH="foo::bar" situation */ |
@@ -43,6 +52,20 @@ char* FAST_FUNC find_execable(const char *filename, char **PATHp) | |||
43 | *PATHp = n; | 52 | *PATHp = n; |
44 | return p; | 53 | return p; |
45 | } | 54 | } |
55 | if (ENABLE_PLATFORM_MINGW32) { | ||
56 | int len = strlen(p); | ||
57 | if (len > 4 && !strcasecmp(p+len-4, ".exe")) | ||
58 | ; /* nothing, already tested by find_execable() */ | ||
59 | else { | ||
60 | char *np = xmalloc(len+4+1); | ||
61 | memcpy(np, p, len); | ||
62 | memcpy(np+len, ".exe", 5); | ||
63 | if (execable_file(np)) { | ||
64 | *PATHp = n; | ||
65 | return np; | ||
66 | } | ||
67 | } | ||
68 | } | ||
46 | free(p); | 69 | free(p); |
47 | } | 70 | } |
48 | p = n; | 71 | p = n; |