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-04-20 19:14:31 +0200 |
commit | 3ad9f036e14f328e79b6f06fc4f9b39bb29b2747 (patch) | |
tree | 9f936c53fd0f5bc01ce651971c3332fca4ecd541 /libbb | |
parent | 6a37ba9eff6456116d933a0bdc7c85802cc33b10 (diff) | |
download | busybox-w32-3ad9f036e14f328e79b6f06fc4f9b39bb29b2747.tar.gz busybox-w32-3ad9f036e14f328e79b6f06fc4f9b39bb29b2747.tar.bz2 busybox-w32-3ad9f036e14f328e79b6f06fc4f9b39bb29b2747.zip |
win32: execable.c: support .exe suffix
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Diffstat (limited to 'libbb')
-rw-r--r-- | libbb/execable.c | 26 |
1 files changed, 25 insertions, 1 deletions
diff --git a/libbb/execable.c b/libbb/execable.c index 5c7ac16a2..b2ec16713 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,21 @@ 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", 4); | ||
63 | np[len+4] = '0'; | ||
64 | if (execable_file(np)) { | ||
65 | *PATHp = n; | ||
66 | return np; | ||
67 | } | ||
68 | } | ||
69 | } | ||
46 | free(p); | 70 | free(p); |
47 | } | 71 | } |
48 | p = n; | 72 | p = n; |