os2: skip . and .. in read dir

This commit is contained in:
Laytan Laats
2024-08-14 01:44:37 +02:00
parent bd808f9ec6
commit de9abe1f7b
+5 -5
View File
@@ -17,6 +17,7 @@ _read_directory_iterator :: proc(it: ^Read_Directory_Iterator) -> (fi: File_Info
index = it.impl.idx
it.impl.idx += 1
for {
entry := posix.readdir(it.impl.dir)
if entry == nil {
// NOTE(laytan): would be good to have an `error` field on the `Read_Directory_Iterator`
@@ -25,11 +26,9 @@ _read_directory_iterator :: proc(it: ^Read_Directory_Iterator) -> (fi: File_Info
}
cname := cstring(raw_data(entry.d_name[:]))
// NOTE: these shouldn't be given back, but how?
// if cname == "." || cname == ".." {
// continue
// }
if cname == "." || cname == ".." {
continue
}
stat: posix.stat_t
if posix.fstatat(posix.dirfd(it.impl.dir), cname, &stat, { .SYMLINK_NOFOLLOW }) != .OK {
@@ -48,6 +47,7 @@ _read_directory_iterator :: proc(it: ^Read_Directory_Iterator) -> (fi: File_Info
ok = true
return
}
}
@(require_results)
_read_directory_iterator_create :: proc(f: ^File) -> (iter: Read_Directory_Iterator, err: Error) {