blob: 6e315633491cf0a7fa7de6b3156c05b019552e69 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
|
package common
import "core:fmt"
import "core:os"
import "core:strings"
import "core:path/filepath"
when ODIN_OS == .Windows {
delimiter :: ";"
} else {
delimiter :: ":"
}
//TODO(daniel): This is temporary and should not be needed after os2
File_Mode_User_Executable :: os.File_Mode(1 << 8)
lookup_in_path :: proc(name: string) -> (string, bool) {
path := os.get_env("PATH", context.temp_allocator)
for directory in strings.split_iterator(&path, delimiter) {
when ODIN_OS == .Windows {
name := fmt.tprintf("%v/%v.exe", directory, name)
if os.exists(name) {
return name, true
}
} else {
name := fmt.tprintf("%v/%v", directory, name)
if os.exists(name) {
if info, err := os.stat(name, context.temp_allocator); err == os.ERROR_NONE && (File_Mode_User_Executable & info.mode) != 0 {
return name, true
}
}
}
}
return "", false
}
|