diff options
author | Ron Yorston <rmy@pobox.com> | 2012-05-09 15:16:44 +0100 |
---|---|---|
committer | Ron Yorston <rmy@pobox.com> | 2012-05-09 15:16:44 +0100 |
commit | 4066aff5e481941585c5958460c39a1b1399ce88 (patch) | |
tree | 87f3996a592298e744faa6b17b0af17c3786510a /win32 | |
parent | f2459f232790aab0434d1cc6471ea62bc193e636 (diff) | |
download | busybox-w32-4066aff5e481941585c5958460c39a1b1399ce88.tar.gz busybox-w32-4066aff5e481941585c5958460c39a1b1399ce88.tar.bz2 busybox-w32-4066aff5e481941585c5958460c39a1b1399ce88.zip |
Use win32_execable_file() in test, which and execable.c
Diffstat (limited to 'win32')
-rw-r--r-- | win32/mingw.c | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/win32/mingw.c b/win32/mingw.c index a6c969596..7dda6cd1b 100644 --- a/win32/mingw.c +++ b/win32/mingw.c | |||
@@ -830,3 +830,35 @@ int mingw_access(const char *name, int mode) | |||
830 | 830 | ||
831 | return -1; | 831 | return -1; |
832 | } | 832 | } |
833 | |||
834 | /* check if path can be made into an executable by adding a suffix; | ||
835 | * return an allocated string containing the path if it can; | ||
836 | * return NULL if not. | ||
837 | * | ||
838 | * if path already has a suffix don't even bother trying | ||
839 | */ | ||
840 | char *win32_execable_file(const char *p) | ||
841 | { | ||
842 | char *path; | ||
843 | int len = strlen(p); | ||
844 | |||
845 | if (len > 4 && (!strcasecmp(p+len-4, ".exe") || | ||
846 | !strcasecmp(p+len-4, ".com"))) { | ||
847 | return NULL; | ||
848 | } | ||
849 | |||
850 | if ( (path=malloc(len+5)) != NULL ) { | ||
851 | memcpy(path, p, len); | ||
852 | memcpy(path+len, ".exe", 5); | ||
853 | if (execable_file(path)) { | ||
854 | return path; | ||
855 | } | ||
856 | memcpy(path+len, ".com", 5); | ||
857 | if (execable_file(path)) { | ||
858 | return path; | ||
859 | } | ||
860 | free(path); | ||
861 | } | ||
862 | |||
863 | return NULL; | ||
864 | } | ||