| 129 | } |
| 130 | |
| 131 | int is_executable(const char *name) |
| 132 | { |
| 133 | struct stat st; |
| 134 | |
| 135 | if (stat(name, &st) || /* stat, not lstat */ |
| 136 | !S_ISREG(st.st_mode)) |
| 137 | return 0; |
| 138 | |
| 139 | #if defined(GIT_WINDOWS_NATIVE) |
| 140 | /* |
| 141 | * On Windows there is no executable bit. The file extension |
| 142 | * indicates whether it can be run as an executable, and Git |
| 143 | * has special-handling to detect scripts and launch them |
| 144 | * through the indicated script interpreter. We test for the |
| 145 | * file extension first because virus scanners may make |
| 146 | * it quite expensive to open many files. |
| 147 | */ |
| 148 | if (ends_with(name, ".exe")) |
| 149 | return S_IXUSR; |
| 150 | |
| 151 | { |
| 152 | /* |
| 153 | * Now that we know it does not have an executable extension, |
| 154 | * peek into the file instead. |
| 155 | */ |
| 156 | char buf[3] = { 0 }; |
| 157 | int n; |
| 158 | int fd = open(name, O_RDONLY); |
| 159 | st.st_mode &= ~S_IXUSR; |
| 160 | if (fd >= 0) { |
| 161 | n = read(fd, buf, 2); |
| 162 | if (n == 2) |
| 163 | /* look for a she-bang */ |
| 164 | if (!strcmp(buf, "#!")) |
| 165 | st.st_mode |= S_IXUSR; |
| 166 | close(fd); |
| 167 | } |
| 168 | } |
| 169 | #endif |
| 170 | return st.st_mode & S_IXUSR; |
| 171 | } |
| 172 | |
| 173 | #ifndef locate_in_PATH |
| 174 | /* |
no test coverage detected