diff --git a/help.c b/help.c index 2a42ec6d1f..ebc2c4280c 100644 --- a/help.c +++ b/help.c @@ -107,10 +107,19 @@ static int is_executable(const char *name) return 0; #if defined(WIN32) || defined(__CYGWIN__) + /* On Windows we cannot use the executable bit. The executable + * state is determined by extension only. We do this first + * because with virus scanners opening an executeable for + * reading is potentially expensive. + */ + if (has_extension(name, ".exe")) + return S_IXUSR; + #if defined(__CYGWIN__) if ((st.st_mode & S_IXUSR) == 0) #endif -{ /* cannot trust the executable bit, peek into the file instead */ +{ /* now that we know it does not have an executable extension, + peek into the file instead */ char buf[3] = { 0 }; int n; int fd = open(name, O_RDONLY); @@ -118,8 +127,8 @@ if ((st.st_mode & S_IXUSR) == 0) if (fd >= 0) { n = read(fd, buf, 2); if (n == 2) - /* DOS executables start with "MZ" */ - if (!strcmp(buf, "#!") || !strcmp(buf, "MZ")) + /* look for a she-bang */ + if (!strcmp(buf, "#!")) st.st_mode |= S_IXUSR; close(fd); }