diff options
author | Ron Yorston <rmy@pobox.com> | 2012-05-09 11:20:06 +0100 |
---|---|---|
committer | Ron Yorston <rmy@pobox.com> | 2012-05-09 15:00:05 +0100 |
commit | f2459f232790aab0434d1cc6471ea62bc193e636 (patch) | |
tree | 876d184a89f20b9e23d24020dbb3f6f01b519768 /libbb | |
parent | 0c9c04defd7b21aab1f18eaabd2f461b6a425964 (diff) | |
download | busybox-w32-f2459f232790aab0434d1cc6471ea62bc193e636.tar.gz busybox-w32-f2459f232790aab0434d1cc6471ea62bc193e636.tar.bz2 busybox-w32-f2459f232790aab0434d1cc6471ea62bc193e636.zip |
mingw32: make access(2) check file format for executables
Diffstat (limited to 'libbb')
-rw-r--r-- | libbb/execable.c | 26 |
1 files changed, 1 insertions, 25 deletions
diff --git a/libbb/execable.c b/libbb/execable.c index afb957e43..c2a7bf0ca 100644 --- a/libbb/execable.c +++ b/libbb/execable.c | |||
@@ -16,31 +16,7 @@ | |||
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 | if (!stat(name, &s) && S_ISREG(s.st_mode)) { | ||
21 | int len, fd, n; | ||
22 | char buf[100]; | ||
23 | |||
24 | if ((len=strlen(name)) > 4 && | ||
25 | (!strcasecmp(name+len-4, ".exe") || | ||
26 | !strcasecmp(name+len-4, ".com"))) { | ||
27 | return 1; | ||
28 | } | ||
29 | |||
30 | fd = open(name, O_RDONLY); | ||
31 | if (fd < 0) | ||
32 | return 0; | ||
33 | n = read(fd, buf, sizeof(buf)-1); | ||
34 | close(fd); | ||
35 | if (n < 4) /* at least '#!/x' and not error */ | ||
36 | return 0; | ||
37 | |||
38 | return (buf[0] == '#' && buf[1] == '!'); | ||
39 | } | ||
40 | return 0; | ||
41 | #else | ||
42 | 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)); |
43 | #endif | ||
44 | } | 20 | } |
45 | 21 | ||
46 | /* search (*PATHp) for an executable file; | 22 | /* search (*PATHp) for an executable file; |
@@ -76,7 +52,7 @@ char* FAST_FUNC find_execable(const char *filename, char **PATHp) | |||
76 | if (len > 4 && | 52 | if (len > 4 && |
77 | (!strcasecmp(p+len-4, ".exe") || | 53 | (!strcasecmp(p+len-4, ".exe") || |
78 | !strcasecmp(p+len-4, ".com"))) | 54 | !strcasecmp(p+len-4, ".com"))) |
79 | ; /* nothing, already tested by find_execable() */ | 55 | ; /* nothing, already tested by execable_file() */ |
80 | else { | 56 | else { |
81 | char *np = xmalloc(len+4+1); | 57 | char *np = xmalloc(len+4+1); |
82 | memcpy(np, p, len); | 58 | memcpy(np, p, len); |