From a17da7e193452c994df9a72a9faf4956e1869731 Mon Sep 17 00:00:00 2001 From: Vassil Vassilev Date: Fri, 21 Jul 2023 22:33:33 +0000 Subject: [PATCH] Fix windows builds by not using dirent.h --- src/xinspect.hpp | 38 ++++++++++++++------------------------ 1 file changed, 14 insertions(+), 24 deletions(-) diff --git a/src/xinspect.hpp b/src/xinspect.hpp index 64231bb3..356b03f7 100644 --- a/src/xinspect.hpp +++ b/src/xinspect.hpp @@ -12,7 +12,6 @@ #include #include -#include #include @@ -24,6 +23,9 @@ #include "xdemangle.hpp" #include "xparser.hpp" +#include "llvm/Support/FileSystem.h" +#include "llvm/Support/Path.h" + namespace xcpp { struct node_predicate @@ -100,30 +102,18 @@ namespace xcpp static nl::json read_tagconfs(const char* path) { nl::json result = nl::json::array(); - DIR* directory = opendir(path); - if (directory == nullptr) - { - return result; - } - dirent* item = readdir(directory); - while (item != nullptr) - { - std::string extension = "json"; - if (item->d_type == DT_REG) - { - std::string fname = item->d_name; - - if (fname.find(extension, (fname.length() - extension.length())) != std::string::npos) - { - std::ifstream i(path + ('/' + fname)); - nl::json entry; - i >> entry; - result.emplace_back(std::move(entry)); - } - } - item = readdir(directory); + std::error_code EC; + for (llvm::sys::fs::directory_iterator File(path, EC), FileEnd; + File != FileEnd && !EC; File.increment(EC)) { + llvm::StringRef FilePath = File->path(); + llvm::StringRef FileName = llvm::sys::path::filename(FilePath); + if (!FileName.endswith("json")) + continue; + std::ifstream i(FilePath.str()); + nl::json entry; + i >> entry; + result.emplace_back(std::move(entry)); } - closedir(directory); return result; }