| 165 | |
| 166 | namespace file_system { |
| 167 | bool is_exe(const std::string &path) |
| 168 | { |
| 169 | int fd = open(path.c_str(), O_RDONLY); |
| 170 | if (fd < 0) |
| 171 | return false; |
| 172 | #ifdef COVSCRIPT_PLATFORM_DARWIN |
| 173 | uint32_t header = 0; |
| 174 | #else |
| 175 | uint8_t header[4] = {0}; |
| 176 | #endif |
| 177 | int nread = read(fd, reinterpret_cast<void *>(&header), sizeof(header)); |
| 178 | close(fd); |
| 179 | if (nread < 0) |
| 180 | return false; |
| 181 | #ifdef COVSCRIPT_PLATFORM_DARWIN |
| 182 | if (header == MH_MAGIC || header == MH_CIGAM || header == MH_MAGIC_64 || header == MH_CIGAM_64) |
| 183 | return true; |
| 184 | #else |
| 185 | if (header[0] == 0x7f && header[1] == 'E' && header[2] == 'L' && header[3] == 'F') |
| 186 | return true; |
| 187 | #endif |
| 188 | return false; |
| 189 | } |
| 190 | |
| 191 | bool can_read(const std::string &path) |
| 192 | { |
no test coverage detected