diff --git a/main.cc b/main.cc index 236f396..a932d22 100644 --- a/main.cc +++ b/main.cc @@ -1,11 +1,10 @@ -#include -#include #include #include #include #include #include +#include #include @@ -85,10 +84,10 @@ ThreadPool tpool; static bool ob_check_ts(ConstCharRange tname, const Vector &deps) { auto get_ts = [](ConstCharRange fname) -> time_t { - struct stat st; - if (stat(String(fname).data(), &st) < 0) + ostd::FileInfo fi(fname); + if (fi.type() != ostd::FileType::regular) return 0; - return st.st_mtime; + return fi.mtime(); }; time_t tts = get_ts(tname.data()); if (!tts) return true; @@ -198,15 +197,12 @@ static bool ob_expand_glob(String &ret, ConstCharRange src, bool ne = false); static bool ob_expand_dir(String &ret, ConstCharRange dir, const Vector &parts, ConstCharRange slash) { - DIR *d = opendir(String(dir).data()); + ostd::DirectoryStream d(dir); bool appended = false; - if (!d) + if (!d.is_open()) return false; - struct dirent *dirp; - while ((dirp = readdir(d))) { - ConstCharRange fn = (const char *)dirp->d_name; - if (fn.empty() || (fn == ".") || (fn == "..")) - continue; + for (auto &fi: d.iter()) { + ConstCharRange fn = fi.filename(); /* check if filename matches */ if (!ob_path_matches(fn, parts)) continue; @@ -236,7 +232,6 @@ static bool ob_expand_dir(String &ret, ConstCharRange dir, ret.append(afn); appended = true; } - closedir(d); return appended; }