os/os2: recursive directory walker, expose errors in read_directory, file clone

Adds a directory walker, a method of exposing and retrieving errors from
the existing read directory iterator, allows reusing of the existing
read directory iterator, and adds a file clone procedure
This commit is contained in:
Laytan Laats
2025-02-24 20:40:44 +01:00
parent d0d5cf800e
commit 0e4140a602
14 changed files with 687 additions and 88 deletions
+31
View File
@@ -0,0 +1,31 @@
package tests_core_os_os2
import os "core:os/os2"
import "core:testing"
import "core:path/filepath"
@(test)
test_clone :: proc(t: ^testing.T) {
f, err := os.open(filepath.join({#directory, "file.odin"}, context.temp_allocator))
testing.expect_value(t, err, nil)
testing.expect(t, f != nil)
clone: ^os.File
clone, err = os.clone(f)
testing.expect_value(t, err, nil)
testing.expect(t, clone != nil)
testing.expect_value(t, os.name(clone), os.name(f))
testing.expect(t, os.fd(clone) != os.fd(f))
os.close(f)
buf: [128]byte
n: int
n, err = os.read(clone, buf[:])
testing.expect_value(t, err, nil)
testing.expect(t, n > 13)
testing.expect_value(t, string(buf[:13]), "package tests")
os.close(clone)
}