use sys/linux dirent instead of manual iteration

This commit is contained in:
jason
2024-07-30 10:19:09 -04:00
parent 792640df1f
commit c7eb2ae6bb
2 changed files with 12 additions and 32 deletions
+3 -8
View File
@@ -80,17 +80,12 @@ _process_list :: proc(allocator: runtime.Allocator) -> (list: []int, err: Error)
return {}, _get_platform_error(errno)
}
d: ^dirent64
for i := 0; i < buflen; i += int(d.d_reclen) {
d = (^dirent64)(rawptr(&buf[i]))
d_name_cstr := cstring(&d.d_name[0])
#no_bounds_check d_name_str := string(d.d_name[:len(d_name_cstr)])
offset: int
for d in linux.dirent_iterate_buf(buf[:buflen], &offset) {
d_name_str := linux.dirent_name(d)
if pid, ok := strconv.parse_int(d_name_str); ok {
append(&dynamic_list, pid)
} else {
return nil, .Invalid_File
}
}
}