← Back to context

Comment by stabbles

13 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.

[1] https://man7.org/linux/man-pages/man3/scandir.3.html

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.