diff options
author | Ron Yorston <rmy@pobox.com> | 2018-03-01 09:00:33 +0000 |
---|---|---|
committer | Ron Yorston <rmy@pobox.com> | 2018-03-01 09:00:33 +0000 |
commit | 9427d06e8813a3bf0a9ef4a5b964e0206a083294 (patch) | |
tree | 30c2fde1d439ab4157602da753cb478eae440ceb | |
parent | f5783ef14f9ad96ae483f16e639953d0212ca7d0 (diff) | |
download | busybox-w32-9427d06e8813a3bf0a9ef4a5b964e0206a083294.tar.gz busybox-w32-9427d06e8813a3bf0a9ef4a5b964e0206a083294.tar.bz2 busybox-w32-9427d06e8813a3bf0a9ef4a5b964e0206a083294.zip |
win32: make has_exec_format static
The only other caller (in spawnveq) has been removed.
-rw-r--r-- | include/mingw.h | 1 | ||||
-rw-r--r-- | win32/mingw.c | 110 |
2 files changed, 55 insertions, 56 deletions
diff --git a/include/mingw.h b/include/mingw.h index b0e1fa53c..c662f4baf 100644 --- a/include/mingw.h +++ b/include/mingw.h | |||
@@ -478,7 +478,6 @@ int has_bat_suffix(const char *p); | |||
478 | int has_exe_suffix(const char *p); | 478 | int has_exe_suffix(const char *p); |
479 | int has_exe_suffix_or_dot(const char *name); | 479 | int has_exe_suffix_or_dot(const char *name); |
480 | char *add_win32_extension(const char *p); | 480 | char *add_win32_extension(const char *p); |
481 | int has_exec_format(const char *name); | ||
482 | 481 | ||
483 | int err_win_to_posix(DWORD winerr); | 482 | int err_win_to_posix(DWORD winerr); |
484 | 483 | ||
diff --git a/win32/mingw.c b/win32/mingw.c index 260bc82d7..a58cb7b01 100644 --- a/win32/mingw.c +++ b/win32/mingw.c | |||
@@ -282,6 +282,61 @@ static inline int get_file_attr(const char *fname, WIN32_FILE_ATTRIBUTE_DATA *fd | |||
282 | } | 282 | } |
283 | } | 283 | } |
284 | 284 | ||
285 | /* | ||
286 | * Examine a file's contents to determine if it can be executed. This | ||
287 | * should be a last resort: in most cases it's much more efficient to | ||
288 | * check the file extension. | ||
289 | * | ||
290 | * We look for two types of file: shell scripts and binary executables. | ||
291 | */ | ||
292 | static int has_exec_format(const char *name) | ||
293 | { | ||
294 | int fd, n, sig; | ||
295 | unsigned int offset; | ||
296 | unsigned char buf[1024]; | ||
297 | |||
298 | fd = open(name, O_RDONLY); | ||
299 | if (fd < 0) | ||
300 | return 0; | ||
301 | n = read(fd, buf, sizeof(buf)-1); | ||
302 | close(fd); | ||
303 | if (n < 4) /* at least '#!/x' and not error */ | ||
304 | return 0; | ||
305 | |||
306 | /* shell script */ | ||
307 | if (buf[0] == '#' && buf[1] == '!') { | ||
308 | return 1; | ||
309 | } | ||
310 | |||
311 | /* | ||
312 | * Poke about in file to see if it's a PE binary. I've just copied | ||
313 | * the magic from the file command. | ||
314 | */ | ||
315 | if (buf[0] == 'M' && buf[1] == 'Z') { | ||
316 | offset = (buf[0x19] << 8) + buf[0x18]; | ||
317 | if (offset > 0x3f) { | ||
318 | offset = (buf[0x3f] << 24) + (buf[0x3e] << 16) + | ||
319 | (buf[0x3d] << 8) + buf[0x3c]; | ||
320 | if (offset < sizeof(buf)-100) { | ||
321 | if (memcmp(buf+offset, "PE\0\0", 4) == 0) { | ||
322 | sig = (buf[offset+25] << 8) + buf[offset+24]; | ||
323 | if (sig == 0x10b || sig == 0x20b) { | ||
324 | sig = (buf[offset+23] << 8) + buf[offset+22]; | ||
325 | if ((sig & 0x2000) != 0) { | ||
326 | /* DLL */ | ||
327 | return 0; | ||
328 | } | ||
329 | sig = buf[offset+92]; | ||
330 | return (sig == 1 || sig == 2 || sig == 3 || sig == 7); | ||
331 | } | ||
332 | } | ||
333 | } | ||
334 | } | ||
335 | } | ||
336 | |||
337 | return 0; | ||
338 | } | ||
339 | |||
285 | /* We keep the do_lstat code in a separate function to avoid recursion. | 340 | /* We keep the do_lstat code in a separate function to avoid recursion. |
286 | * When a path ends with a slash, the stat will fail with ENOENT. In | 341 | * When a path ends with a slash, the stat will fail with ENOENT. In |
287 | * this case, we strip the trailing slashes and stat again. | 342 | * this case, we strip the trailing slashes and stat again. |
@@ -1069,61 +1124,6 @@ char *add_win32_extension(const char *p) | |||
1069 | return NULL; | 1124 | return NULL; |
1070 | } | 1125 | } |
1071 | 1126 | ||
1072 | /* | ||
1073 | * Examine a file's contents to determine if it can be executed. This | ||
1074 | * should be a last resort: in most cases it's much more efficient to | ||
1075 | * check the file extension. | ||
1076 | * | ||
1077 | * We look for two types of file: shell scripts and binary executables. | ||
1078 | */ | ||
1079 | int has_exec_format(const char *name) | ||
1080 | { | ||
1081 | int fd, n, sig; | ||
1082 | unsigned int offset; | ||
1083 | unsigned char buf[1024]; | ||
1084 | |||
1085 | fd = open(name, O_RDONLY); | ||
1086 | if (fd < 0) | ||
1087 | return 0; | ||
1088 | n = read(fd, buf, sizeof(buf)-1); | ||
1089 | close(fd); | ||
1090 | if (n < 4) /* at least '#!/x' and not error */ | ||
1091 | return 0; | ||
1092 | |||
1093 | /* shell script */ | ||
1094 | if (buf[0] == '#' && buf[1] == '!') { | ||
1095 | return 1; | ||
1096 | } | ||
1097 | |||
1098 | /* | ||
1099 | * Poke about in file to see if it's a PE binary. I've just copied | ||
1100 | * the magic from the file command. | ||
1101 | */ | ||
1102 | if (buf[0] == 'M' && buf[1] == 'Z') { | ||
1103 | offset = (buf[0x19] << 8) + buf[0x18]; | ||
1104 | if (offset > 0x3f) { | ||
1105 | offset = (buf[0x3f] << 24) + (buf[0x3e] << 16) + | ||
1106 | (buf[0x3d] << 8) + buf[0x3c]; | ||
1107 | if (offset < sizeof(buf)-100) { | ||
1108 | if (memcmp(buf+offset, "PE\0\0", 4) == 0) { | ||
1109 | sig = (buf[offset+25] << 8) + buf[offset+24]; | ||
1110 | if (sig == 0x10b || sig == 0x20b) { | ||
1111 | sig = (buf[offset+23] << 8) + buf[offset+22]; | ||
1112 | if ((sig & 0x2000) != 0) { | ||
1113 | /* DLL */ | ||
1114 | return 0; | ||
1115 | } | ||
1116 | sig = buf[offset+92]; | ||
1117 | return (sig == 1 || sig == 2 || sig == 3 || sig == 7); | ||
1118 | } | ||
1119 | } | ||
1120 | } | ||
1121 | } | ||
1122 | } | ||
1123 | |||
1124 | return 0; | ||
1125 | } | ||
1126 | |||
1127 | #undef opendir | 1127 | #undef opendir |
1128 | DIR *mingw_opendir(const char *path) | 1128 | DIR *mingw_opendir(const char *path) |
1129 | { | 1129 | { |