Merge 'fix-is-exe' into HEAD

This commit is contained in:
Johannes Schindelin
2016-10-13 14:27:05 +02:00

15
help.c
View File

@@ -105,7 +105,16 @@ static int is_executable(const char *name)
return 0;
#if defined(GIT_WINDOWS_NATIVE)
{ /* cannot trust the executable bit, peek into the file instead */
/* 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 (ends_with(name, ".exe"))
return S_IXUSR;
{ /* 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);
@@ -113,8 +122,8 @@ static int is_executable(const char *name)
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);
}