Comment by stabbles
17 hours ago
What comes closest is scandir [1], which gives you an iterator of direntries, and can be used to avoid lstat syscalls for each file.
Otherwise you can open a dir and pass its fd to openat together with a relative path to a file, to reduce the kernel overhead of resolving absolute paths for each file.
This is a (3) man page which means it's not a syscall. Have you checked it doesn't call lstat on each file?
Fair, https://www.man7.org/linux/man-pages/man2/getdents64.2.html is a better link. You'd have to call lstat when d_type is DT_UNKNOWN
in what way does scandir avoid stat syscalls?
Because you get an iterator over `struct dirent`, which includes `d_type` for popular filesystems.
Notice that this avoids `lstat` calls; for symlinks you may still need to do a stat call if you want to stat the target.