Skip to content

Commit 3e929c5

Browse files
committed
core:path/filepath -> os2
1 parent 077f94d commit 3e929c5

File tree

6 files changed

+37
-81
lines changed

6 files changed

+37
-81
lines changed

core/mem/virtual/doc.odin

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ virtual.Arena usage
55
66
Example:
77
// Source: https://github.com/odin-lang/examples/blob/master/arena_allocator/arena_allocator.odin
8-
import "core:fmt"
9-
import "core:os"
8+
import "core:fmt"
9+
import os "core:os/os2"
1010
1111
// virtual package implements a multi-purpose arena allocator. If you are on a
1212
// platform that does not support virtual memory, then there is also a similar
@@ -26,14 +26,14 @@ Example:
2626
// See arena_init_buffer for an arena that does not use virtual memory,
2727
// instead it relies on you feeding it a buffer.
2828
29-
f1, f1_ok := os.read_entire_file("file1.txt", arena_alloc)
30-
ensure(f1_ok)
29+
f1, f1_err := os.read_entire_file("file1.txt", arena_alloc)
30+
ensure(f1_err == nil)
3131
32-
f2, f2_ok := os.read_entire_file("file2.txt", arena_alloc)
33-
ensure(f2_ok)
32+
f2, f2_err := os.read_entire_file("file2.txt", arena_alloc)
33+
ensure(f2_err == nil)
3434
35-
f3, f3_ok := os.read_entire_file("file3.txt", arena_alloc)
36-
ensure(f3_ok)
35+
f3, f3_err := os.read_entire_file("file3.txt", arena_alloc)
36+
ensure(f3_err == nil)
3737
3838
res := make([]string, 3, arena_alloc)
3939
res[0] = string(f1)

core/odin/parser/parse_files.odin

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
package odin_parser
22

3-
import "core:odin/tokenizer"
4-
import "core:odin/ast"
5-
import "core:path/filepath"
6-
import "core:fmt"
7-
import "core:os"
8-
import "core:slice"
9-
import "core:strings"
3+
import "core:odin/tokenizer"
4+
import "core:odin/ast"
5+
import "core:path/filepath"
6+
import "core:fmt"
7+
import os "core:os/os2"
8+
import "core:slice"
9+
import "core:strings"
1010

1111
collect_package :: proc(path: string) -> (pkg: ^ast.Package, success: bool) {
1212
NO_POS :: tokenizer.Pos{}
@@ -28,14 +28,13 @@ collect_package :: proc(path: string) -> (pkg: ^ast.Package, success: bool) {
2828
pkg.fullpath = pkg_path
2929

3030
for match in matches {
31-
src: []byte
3231
fullpath, ok := filepath.abs(match)
3332
if !ok {
3433
return
3534
}
3635

37-
src, ok = os.read_entire_file(fullpath)
38-
if !ok {
36+
src, src_err := os.read_entire_file(fullpath, context.allocator)
37+
if src_err != nil {
3938
delete(fullpath)
4039
return
4140
}

core/path/filepath/match.odin

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
#+build !js
33
package filepath
44

5-
import "core:os"
6-
import "core:slice"
7-
import "core:strings"
8-
import "core:unicode/utf8"
5+
import os "core:os/os2"
6+
import "core:slice"
7+
import "core:strings"
8+
import "core:unicode/utf8"
99

1010
Match_Error :: enum {
1111
None,
@@ -286,28 +286,23 @@ _glob :: proc(dir, pattern: string, matches: ^[dynamic]string, allocator := cont
286286
defer os.close(d)
287287

288288
{
289-
file_info, ferr := os.fstat(d)
290-
defer os.file_info_delete(file_info)
289+
file_info, ferr := os.fstat(d, allocator)
290+
defer os.file_info_delete(file_info, allocator)
291291

292292
if ferr != nil {
293293
return
294294
}
295-
if !file_info.is_dir {
295+
if file_info.type != .Directory {
296296
return
297297
}
298298
}
299299

300300

301-
fis, _ := os.read_dir(d, -1)
301+
fis, _ := os.read_dir(d, -1, allocator)
302302
slice.sort_by(fis, proc(a, b: os.File_Info) -> bool {
303303
return a.name < b.name
304304
})
305-
defer {
306-
for fi in fis {
307-
os.file_info_delete(fi)
308-
}
309-
delete(fis)
310-
}
305+
defer os.file_info_slice_delete(fis, allocator)
311306

312307
for fi in fis {
313308
n := fi.name
@@ -359,4 +354,4 @@ clean_glob_path_windows :: proc(path: string, temp_buf: []byte) -> (prefix_len:
359354
vol_len = len(path) -1
360355
}
361356
return vol_len, path[:len(path)-1]
362-
}
357+
}

core/path/filepath/path_windows.odin

Lines changed: 5 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
package filepath
22

3-
import "core:strings"
4-
import "base:runtime"
5-
import "core:os"
6-
import win32 "core:sys/windows"
3+
import "core:strings"
4+
import "base:runtime"
5+
import os "core:os/os2"
76

87
SEPARATOR :: '\\'
98
SEPARATOR_STRING :: `\`
@@ -33,50 +32,12 @@ is_UNC :: proc(path: string) -> bool {
3332
}
3433

3534
is_abs :: proc(path: string) -> bool {
36-
if is_reserved_name(path) {
37-
return true
38-
}
39-
l := volume_name_len(path)
40-
if l == 0 {
41-
return false
42-
}
43-
44-
path := path
45-
path = path[l:]
46-
if path == "" {
47-
return false
48-
}
49-
return is_slash(path[0])
50-
}
51-
52-
@(private)
53-
temp_full_path :: proc(name: string) -> (path: string, err: os.Error) {
54-
ta := context.temp_allocator
55-
56-
name := name
57-
if name == "" {
58-
name = "."
59-
}
60-
61-
p := win32.utf8_to_utf16(name, ta)
62-
n := win32.GetFullPathNameW(cstring16(raw_data(p)), 0, nil, nil)
63-
if n == 0 {
64-
return "", os.get_last_error()
65-
}
66-
67-
buf := make([]u16, n, ta)
68-
n = win32.GetFullPathNameW(cstring16(raw_data(p)), u32(len(buf)), cstring16(raw_data(buf)), nil)
69-
if n == 0 {
70-
delete(buf)
71-
return "", os.get_last_error()
72-
}
73-
74-
return win32.utf16_to_utf8(buf[:n], ta)
35+
return os.is_absolute_path(path)
7536
}
7637

7738
abs :: proc(path: string, allocator := context.allocator) -> (string, bool) {
7839
runtime.DEFAULT_TEMP_ALLOCATOR_TEMP_GUARD(ignore = allocator == context.temp_allocator)
79-
full_path, err := temp_full_path(path)
40+
full_path, err := os.get_absolute_path(path, context.temp_allocator)
8041
if err != nil {
8142
return "", false
8243
}

core/path/filepath/walk.odin

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
#+build !js
33
package filepath
44

5-
import "core:os"
6-
import "core:slice"
5+
import os "core:os/os2"
6+
import "core:slice"
77

88
// Walk_Proc is the type of the procedure called for each file or directory visited by 'walk'
99
// The 'path' parameter contains the parameter to walk as a prefix (this is the same as info.fullpath except on 'root')
@@ -40,7 +40,7 @@ walk :: proc(root: string, walk_proc: Walk_Proc, user_data: rawptr) -> os.Error
4040

4141
@(private)
4242
_walk :: proc(info: os.File_Info, walk_proc: Walk_Proc, user_data: rawptr) -> (err: os.Error, skip_dir: bool) {
43-
if !info.is_dir {
43+
if info.type != .Directory {
4444
if info.fullpath == "" && info.name == "" {
4545
// ignore empty things
4646
return
@@ -62,7 +62,7 @@ _walk :: proc(info: os.File_Info, walk_proc: Walk_Proc, user_data: rawptr) -> (e
6262
for fi in fis {
6363
err, skip_dir = _walk(fi, walk_proc, user_data)
6464
if err != nil || skip_dir {
65-
if !fi.is_dir || !skip_dir {
65+
if fi.type != .Directory || !skip_dir {
6666
return
6767
}
6868
}

examples/all/all_main.odin

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ package all
111111
@(require) import "core:prof/spall"
112112

113113
@(require) import "core:os"
114+
@(require) import "core:os/os2"
114115

115116
@(require) import "core:path/slashpath"
116117
@(require) import "core:path/filepath"

0 commit comments

Comments
 (0)