From 36fbfef74c0df8d76b50121b96e3fe8849e8e734 Mon Sep 17 00:00:00 2001 From: ridiculousfish Date: Sun, 25 Sep 2022 12:52:44 -0700 Subject: [PATCH] Switch uses of dir_t to dir_iter_t dir_t was a thin wrapper around readdir; switch to the new dir_iter_t API and remove dir_t. --- src/function.cpp | 7 +++---- src/wutil.cpp | 16 ---------------- src/wutil.h | 9 --------- 3 files changed, 3 insertions(+), 29 deletions(-) diff --git a/src/function.cpp b/src/function.cpp index 8f0e8353a..21ce8f1b6 100644 --- a/src/function.cpp +++ b/src/function.cpp @@ -118,12 +118,11 @@ static void autoload_names(std::unordered_set &names, bool get_hidden) for (i = 0; i < path_list.size(); i++) { const wcstring &ndir_str = path_list.at(i); - dir_t dir(ndir_str); + dir_iter_t dir(ndir_str); if (!dir.valid()) continue; - wcstring name; - while (dir.read(name)) { - const wchar_t *fn = name.c_str(); + while (const auto *entry = dir.next()) { + const wchar_t *fn = entry->name.c_str(); const wchar_t *suffix; if (!get_hidden && fn[0] == L'_') continue; diff --git a/src/wutil.cpp b/src/wutil.cpp index e0925fb97..60d49d23b 100644 --- a/src/wutil.cpp +++ b/src/wutil.cpp @@ -328,22 +328,6 @@ const dir_iter_t::entry_t *dir_iter_t::next() { return &entry_; } -dir_t::dir_t(const wcstring &path) { - const cstring tmp = wcs2string(path); - this->dir = opendir(tmp.c_str()); -} - -dir_t::~dir_t() { - if (this->dir != nullptr) { - closedir(this->dir); - this->dir = nullptr; - } -} - -bool dir_t::valid() const { return this->dir != nullptr; } - -bool dir_t::read(wcstring &name) const { return wreaddir(this->dir, name); } - int wstat(const wcstring &file_name, struct stat *buf) { const cstring tmp = wcs2string(file_name); return stat(tmp.c_str(), buf); diff --git a/src/wutil.h b/src/wutil.h index 96fd57c54..35f446567 100644 --- a/src/wutil.h +++ b/src/wutil.h @@ -260,15 +260,6 @@ class dir_iter_t : noncopyable_t { entry_t entry_; }; -/// RAII wrapper for DIR* -struct dir_t { - DIR *dir; - bool valid() const; - bool read(wcstring &name) const; - dir_t(const wcstring &path); - ~dir_t(); -}; - #ifndef HASH_FILE_ID #define HASH_FILE_ID 1 namespace std {