1
mirror of https://github.com/topjohnwu/Magisk synced 2024-11-11 17:38:25 +01:00

Templatize function callbacks

This commit is contained in:
topjohnwu 2020-11-03 01:16:55 -08:00
parent ffb4224640
commit 4c94f90e5d

View File

@ -45,18 +45,20 @@ int mkdirs(string path, mode_t mode) {
return 0; return 0;
} }
static void post_order_walk(int dirfd, const function<void(int, dirent *)> &&fn) { template <typename Func>
static void post_order_walk(int dirfd, const Func &fn) {
auto dir = xopen_dir(dirfd); auto dir = xopen_dir(dirfd);
if (!dir) return; if (!dir) return;
for (dirent *entry; (entry = xreaddir(dir.get()));) { for (dirent *entry; (entry = xreaddir(dir.get()));) {
if (entry->d_type == DT_DIR) if (entry->d_type == DT_DIR)
post_order_walk(xopenat(dirfd, entry->d_name, O_RDONLY | O_CLOEXEC), std::move(fn)); post_order_walk(xopenat(dirfd, entry->d_name, O_RDONLY | O_CLOEXEC), fn);
fn(dirfd, entry); fn(dirfd, entry);
} }
} }
static void pre_order_walk(int dirfd, const function<bool(int, dirent *)> &&fn) { template <typename Func>
static void pre_order_walk(int dirfd, const Func &fn) {
auto dir = xopen_dir(dirfd); auto dir = xopen_dir(dirfd);
if (!dir) return; if (!dir) return;
@ -64,7 +66,7 @@ static void pre_order_walk(int dirfd, const function<bool(int, dirent *)> &&fn)
if (!fn(dirfd, entry)) if (!fn(dirfd, entry))
continue; continue;
if (entry->d_type == DT_DIR) if (entry->d_type == DT_DIR)
pre_order_walk(xopenat(dirfd, entry->d_name, O_RDONLY | O_CLOEXEC), std::move(fn)); pre_order_walk(xopenat(dirfd, entry->d_name, O_RDONLY | O_CLOEXEC), fn);
} }
} }