mirror of
https://github.com/Ed94/Odin.git
synced 2026-08-05 07:08:48 +00:00
os2: don't rely on PATH_MAX in posix read_directory implementation
This commit is contained in:
+15
-10
@@ -7,13 +7,13 @@ import "core:sys/posix"
|
|||||||
Read_Directory_Iterator_Impl :: struct {
|
Read_Directory_Iterator_Impl :: struct {
|
||||||
dir: posix.DIR,
|
dir: posix.DIR,
|
||||||
idx: int,
|
idx: int,
|
||||||
|
fullpath: [dynamic]byte,
|
||||||
// NOTE: could there be paths bigger than this, maybe, probably, but why does it exist then?
|
|
||||||
fullpath: [posix.PATH_MAX]byte,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@(require_results)
|
@(require_results)
|
||||||
_read_directory_iterator :: proc(it: ^Read_Directory_Iterator) -> (fi: File_Info, index: int, ok: bool) {
|
_read_directory_iterator :: proc(it: ^Read_Directory_Iterator) -> (fi: File_Info, index: int, ok: bool) {
|
||||||
|
fimpl := (^File_Impl)(it.f.impl)
|
||||||
|
|
||||||
index = it.impl.idx
|
index = it.impl.idx
|
||||||
it.impl.idx += 1
|
it.impl.idx += 1
|
||||||
|
|
||||||
@@ -29,6 +29,7 @@ _read_directory_iterator :: proc(it: ^Read_Directory_Iterator) -> (fi: File_Info
|
|||||||
if cname == "." || cname == ".." {
|
if cname == "." || cname == ".." {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
sname := string(cname)
|
||||||
|
|
||||||
stat: posix.stat_t
|
stat: posix.stat_t
|
||||||
if posix.fstatat(posix.dirfd(it.impl.dir), cname, &stat, { .SYMLINK_NOFOLLOW }) != .OK {
|
if posix.fstatat(posix.dirfd(it.impl.dir), cname, &stat, { .SYMLINK_NOFOLLOW }) != .OK {
|
||||||
@@ -37,13 +38,11 @@ _read_directory_iterator :: proc(it: ^Read_Directory_Iterator) -> (fi: File_Info
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
fimpl := (^File_Impl)(it.f.impl)
|
n := len(fimpl.name)+1
|
||||||
|
non_zero_resize(&it.impl.fullpath, n+len(sname))
|
||||||
|
n += copy(it.impl.fullpath[n:], sname)
|
||||||
|
|
||||||
n := copy(it.impl.fullpath[:], fimpl.name)
|
fi = internal_stat(stat, string(it.impl.fullpath[:]))
|
||||||
n += copy(it.impl.fullpath[n:], "/")
|
|
||||||
n += copy(it.impl.fullpath[n:], string(cname))
|
|
||||||
|
|
||||||
fi = internal_stat(stat, string(it.impl.fullpath[:n]))
|
|
||||||
ok = true
|
ok = true
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -55,10 +54,15 @@ _read_directory_iterator_create :: proc(f: ^File) -> (iter: Read_Directory_Itera
|
|||||||
err = .Invalid_File
|
err = .Invalid_File
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl := (^File_Impl)(f.impl)
|
||||||
|
|
||||||
iter.f = f
|
iter.f = f
|
||||||
iter.impl.idx = 0
|
iter.impl.idx = 0
|
||||||
|
|
||||||
impl := (^File_Impl)(f.impl)
|
iter.impl.fullpath.allocator = file_allocator()
|
||||||
|
append(&iter.impl.fullpath, impl.name)
|
||||||
|
append(&iter.impl.fullpath, "/")
|
||||||
|
|
||||||
iter.impl.dir = posix.fdopendir(impl.fd)
|
iter.impl.dir = posix.fdopendir(impl.fd)
|
||||||
if iter.impl.dir == nil {
|
if iter.impl.dir == nil {
|
||||||
@@ -75,4 +79,5 @@ _read_directory_iterator_destroy :: proc(it: ^Read_Directory_Iterator) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
posix.closedir(it.impl.dir)
|
posix.closedir(it.impl.dir)
|
||||||
|
delete(it.impl.fullpath)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user