aboutsummaryrefslogtreecommitdiff
path: root/libbb/executable.c
diff options
context:
space:
mode:
Diffstat (limited to 'libbb/executable.c')
-rw-r--r--libbb/executable.c27
1 files changed, 27 insertions, 0 deletions
diff --git a/libbb/executable.c b/libbb/executable.c
index 29d2a2c85..8e2f99732 100644
--- a/libbb/executable.c
+++ b/libbb/executable.c
@@ -28,6 +28,10 @@ int FAST_FUNC file_is_executable(const char *name)
28 * in all cases (*PATHp) contents are temporarily modified 28 * in all cases (*PATHp) contents are temporarily modified
29 * but are restored on return (s/:/NUL/ and back). 29 * but are restored on return (s/:/NUL/ and back).
30 */ 30 */
31#if !ENABLE_PLATFORM_MINGW32
32#define next_path_sep(s) strchr(s, ':')
33#endif
34
31char* FAST_FUNC find_executable(const char *filename, char **PATHp) 35char* FAST_FUNC find_executable(const char *filename, char **PATHp)
32{ 36{
33 /* About empty components in $PATH: 37 /* About empty components in $PATH:
@@ -39,23 +43,46 @@ char* FAST_FUNC find_executable(const char *filename, char **PATHp)
39 * following the rest of the list. 43 * following the rest of the list.
40 */ 44 */
41 char *p, *n; 45 char *p, *n;
46#if ENABLE_PLATFORM_MINGW32
47 char *w;
48#endif
42 49
43 p = *PATHp; 50 p = *PATHp;
44 while (p) { 51 while (p) {
45 int ex; 52 int ex;
53#if ENABLE_PLATFORM_MINGW32
54 char sep;
46 55
56 n = (char*)next_path_sep(p);
57 if (n) {
58 sep = *n;
59 *n = '\0';
60 }
61#else
47 n = strchr(p, ':'); 62 n = strchr(p, ':');
48 if (n) *n = '\0'; 63 if (n) *n = '\0';
64#endif
49 p = concat_path_file( 65 p = concat_path_file(
50 p[0] ? p : ".", /* handle "::" case */ 66 p[0] ? p : ".", /* handle "::" case */
51 filename 67 filename
52 ); 68 );
53 ex = file_is_executable(p); 69 ex = file_is_executable(p);
70#if ENABLE_PLATFORM_MINGW32
71 if (n) *n++ = sep;
72#else
54 if (n) *n++ = ':'; 73 if (n) *n++ = ':';
74#endif
55 if (ex) { 75 if (ex) {
56 *PATHp = n; 76 *PATHp = n;
57 return p; 77 return p;
58 } 78 }
79#if ENABLE_PLATFORM_MINGW32
80 else if ((w=file_is_win32_executable(p))) {
81 *PATHp = n;
82 free(p);
83 return w;
84 }
85#endif
59 free(p); 86 free(p);
60 p = n; 87 p = n;
61 } /* on loop exit p == NULL */ 88 } /* on loop exit p == NULL */