aboutsummaryrefslogtreecommitdiff
path: root/libbb/executable.c
diff options
context:
space:
mode:
Diffstat (limited to 'libbb/executable.c')
-rw-r--r--libbb/executable.c22
1 files changed, 20 insertions, 2 deletions
diff --git a/libbb/executable.c b/libbb/executable.c
index 09bed1eaf..263141912 100644
--- a/libbb/executable.c
+++ b/libbb/executable.c
@@ -15,7 +15,12 @@
15int FAST_FUNC file_is_executable(const char *name) 15int FAST_FUNC file_is_executable(const char *name)
16{ 16{
17 struct stat s; 17 struct stat s;
18#if !ENABLE_PLATFORM_MINGW32
18 return (!access(name, X_OK) && !stat(name, &s) && S_ISREG(s.st_mode)); 19 return (!access(name, X_OK) && !stat(name, &s) && S_ISREG(s.st_mode));
20#else
21 /* expand WIN32 implementation of access(2) */
22 return (!stat(name, &s) && S_ISREG(s.st_mode) && (s.st_mode & S_IXUSR));
23#endif
19} 24}
20 25
21/* search (*PATHp) for an executable file; 26/* search (*PATHp) for an executable file;
@@ -40,8 +45,9 @@ char* FAST_FUNC find_executable(const char *name, const char **PATHp)
40 if (!p) 45 if (!p)
41 return NULL; 46 return NULL;
42 while (1) { 47 while (1) {
43 const char *end = strchrnul(p, ':'); 48 const char *end = strchrnul(p, PATH_SEP);
44 int sz = end - p; 49 int sz = end - p;
50 int ex;
45 51
46 if (sz != 0) { 52 if (sz != 0) {
47 p = xasprintf("%.*s/%s", sz, p, name); 53 p = xasprintf("%.*s/%s", sz, p, name);
@@ -55,7 +61,19 @@ char* FAST_FUNC find_executable(const char *name, const char **PATHp)
55// With -a, both skip over all colons: xxx::::yyy is the same as xxx::yyy, 61// With -a, both skip over all colons: xxx::::yyy is the same as xxx::yyy,
56// current dir is not tried the second time. 62// current dir is not tried the second time.
57 } 63 }
58 if (file_is_executable(p)) { 64#if ENABLE_PLATFORM_MINGW32
65 {
66 char *w = file_is_win32_exe(p);
67 ex = w != NULL;
68 if (ex) {
69 free(p);
70 p = w;
71 }
72 }
73#else
74 ex = file_is_executable(p);
75#endif
76 if (ex) {
59 *PATHp = (*end ? end+1 : NULL); 77 *PATHp = (*end ? end+1 : NULL);
60 return p; 78 return p;
61 } 79 }