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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
|
#+build js wasm32, js wasm64p32
#+private
package os
// None of this does anything on js/wasm.
// It's only here so importing `core:os` on wasm panics cleanly,
// without spamming about all sorts of missing procs and types.
import "base:runtime"
_Path_Separator :: '/'
_Path_Separator_String :: "/"
_Path_List_Separator :: ':'
_is_path_separator :: proc(c: byte) -> (ok: bool) {
return c == _Path_Separator
}
_mkdir :: proc(name: string, perm: int) -> (err: Error) {
return .Unsupported
}
_mkdir_all :: proc(path: string, perm: int) -> (err: Error) {
return .Unsupported
}
_remove_all :: proc(path: string) -> (err: Error) {
return .Unsupported
}
_get_working_directory :: proc(allocator: runtime.Allocator) -> (dir: string, err: Error) {
return "", .Unsupported
}
_set_working_directory :: proc(dir: string) -> (err: Error) {
return .Unsupported
}
_get_executable_path :: proc(allocator: runtime.Allocator) -> (path: string, err: Error) {
return "", .Unsupported
}
_are_paths_identical :: proc(a, b: string) -> bool {
return false
}
_clean_path_handle_start :: proc(path: string, buffer: []u8) -> (rooted: bool, start: int) {
return
}
_is_absolute_path :: proc(path: string) -> bool {
return false
}
_get_absolute_path :: proc(path: string, allocator: runtime.Allocator) -> (absolute_path: string, err: Error) {
return "", .Unsupported
}
_get_relative_path_handle_start :: proc(base, target: string) -> bool {
return false
}
_get_common_path_len :: proc(base, target: string) -> int {
i := 0
end := min(len(base), len(target))
for j in 0..=end {
if j == end || _is_path_separator(base[j]) {
if base[i:j] == target[i:j] {
i = j
} else {
break
}
}
}
return i
}
_split_path :: proc(path: string) -> (dir, file: string) {
i := len(path) - 1
for i >= 0 && !_is_path_separator(path[i]) {
i -= 1
}
if i == 0 {
return path[:i+1], path[i+1:]
} else if i > 0 {
return path[:i], path[i+1:]
}
return "", path
}
|