MCPcopy Create free account
hub / github.com/LanceLRQ/deer-executor / IsExecutableFile

Function IsExecutableFile

common/utils/binary.go:20–40  ·  view source on GitHub ↗

IsExecutableFile 判断是否是可执行程序(支持linux和macos)

(filePath string)

Source from the content-addressed store, hash-verified

18
19// IsExecutableFile 判断是否是可执行程序(支持linux和macos)
20func 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的二进制程序前缀名
43func GetCompiledBinaryFileName(typeName, moduleName string) string {

Callers 1

compileJudgerProgramMethod · 0.92

Calls 1

ErrorfMethod · 0.80

Tested by

no test coverage detected