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 index = it.impl.idx
it.impl.idx += 1 it.impl.idx += 1
for {
entry := posix.readdir(it.impl.dir) entry := posix.readdir(it.impl.dir)
if entry == nil { if entry == nil {
// NOTE(laytan): would be good to have an `error` field on the `Read_Directory_Iterator` // 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[:])) cname := cstring(raw_data(entry.d_name[:]))
if cname == "." || cname == ".." {
// NOTE: these shouldn't be given back, but how? continue
// if cname == "." || cname == ".." { }
// continue
// }
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 {
@@ -48,6 +47,7 @@ _read_directory_iterator :: proc(it: ^Read_Directory_Iterator) -> (fi: File_Info
ok = true ok = true
return return
} }
}
@(require_results) @(require_results)
_read_directory_iterator_create :: proc(f: ^File) -> (iter: Read_Directory_Iterator, err: Error) { _read_directory_iterator_create :: proc(f: ^File) -> (iter: Read_Directory_Iterator, err: Error) {