IsExecutableFile 判断是否是可执行程序(支持linux和macos)
(filePath string)
| 18 | |
| 19 | // IsExecutableFile 判断是否是可执行程序(支持linux和macos) |
| 20 | func IsExecutableFile(filePath string) (bool, error) { |
| 21 | fp, err := os.OpenFile(filePath, os.O_RDONLY|syscall.O_NONBLOCK, 0) |
| 22 | if err != nil { |
| 23 | return false, errors.Errorf("open file error") |
| 24 | } |
| 25 | defer fp.Close() |
| 26 | |
| 27 | var magic uint32 = 0 |
| 28 | err = binary.Read(fp, binary.BigEndian, &magic) |
| 29 | if err != nil { |
| 30 | return false, err |
| 31 | } |
| 32 | |
| 33 | isExec := false |
| 34 | if runtime.GOOS == "darwin" { |
| 35 | isExec = magic == 0xCFFAEDFE || magic == 0xCEFAEDFE || magic == 0xFEEDFACF || magic == 0xFEEDFACE |
| 36 | } else if runtime.GOOS == "linux" { |
| 37 | isExec = magic == 0x7F454C46 |
| 38 | } |
| 39 | return isExec, nil |
| 40 | } |
| 41 | |
| 42 | // GetCompiledBinaryFileName 获取testlib的二进制程序前缀名 |
| 43 | func GetCompiledBinaryFileName(typeName, moduleName string) string { |
no test coverage detected