summaryrefslogtreecommitdiff
path: root/src/basic/recurse-dir.h
Commit message (Collapse)AuthorAgeFilesLines
* recurse-dir: optionally, call callback when entering/leaving toplevel dir, tooLennart Poettering2022-11-091-0/+1
| | | | | | | | | | | | | | | | | So far recurse_dir() will call the callback whenever we enter a directory, and then pass the struct dirent for that directory, and an fd for the directory the dirent is part of (i.e. the parent of the directory we call things for). For the top-level dir the function is invoked for we will not call the callback however, because we have no dirent for that, and not fd for the directory the top-level dir is part of. Let's add a flag to call it anyway, and in that case pass a NULL dirent and -1 as directory fd. This is useful when we want to treat the top-level dir the same as any dir further down. This is done opt-in since the callback must be ablet to handle a NULL dirent and a -1 directory fd.
* dirent-util: add FOREACH macro for iterating through getdents64() buffersLennart Poettering2021-10-251-1/+1
| | | | | | | | We already have a similar loop twice, let's make it easier to read via an iteration macro. (The new macro is a bit more careful even, as it verifies the full dirent fits into the remaining buffer when returning it)
* recuse-dir: rework to use getdents64() instead of readdir()Lennart Poettering2021-10-111-4/+9
| | | | | | | Let's use the underlying Linux API directly, instead of opendir()/readdir(). This makes it possible for us to do a single memory allocation for all directory entries in common cases, instead of one for each entry.
* basic: add new recurse_dir() tool as replacement for nftw()Lennart Poettering2021-10-071-0/+75
libc nftw() shows its age a bit, let's replace it with a more moden infra that is built around openat(), O_PATH, statx(). This makes the interface less prone to races and cleans up the API a bit adding substantially more functionality.