Skip to content

Commit 76f8e43

Browse files
committed
Fix windows builds by not using dirent.h
1 parent 9716ef4 commit 76f8e43

File tree

2 files changed

+14
-26
lines changed

2 files changed

+14
-26
lines changed

src/xinspect.hpp

Lines changed: 14 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
#include <fstream>
1313
#include <string>
1414

15-
#include <dirent.h>
1615

1716
#include <pugixml.hpp>
1817

@@ -24,6 +23,9 @@
2423
#include "xdemangle.hpp"
2524
#include "xparser.hpp"
2625

26+
#include "llvm/Support/FileSystem.h"
27+
#include "llvm/Support/Path.h"
28+
2729
namespace xcpp
2830
{
2931
struct node_predicate
@@ -100,30 +102,18 @@ namespace xcpp
100102
static nl::json read_tagconfs(const char* path)
101103
{
102104
nl::json result = nl::json::array();
103-
DIR* directory = opendir(path);
104-
if (directory == nullptr)
105-
{
106-
return result;
107-
}
108-
dirent* item = readdir(directory);
109-
while (item != nullptr)
110-
{
111-
std::string extension = "json";
112-
if (item->d_type == DT_REG)
113-
{
114-
std::string fname = item->d_name;
115-
116-
if (fname.find(extension, (fname.length() - extension.length())) != std::string::npos)
117-
{
118-
std::ifstream i(path + ('/' + fname));
119-
nl::json entry;
120-
i >> entry;
121-
result.emplace_back(std::move(entry));
122-
}
123-
}
124-
item = readdir(directory);
105+
std::error_code EC;
106+
for (llvm::sys::fs::directory_iterator File(path, EC), FileEnd;
107+
File != FileEnd && !EC; File.increment(EC)) {
108+
llvm::StringRef FilePath = File->path();
109+
llvm::StringRef FileName = llvm::sys::path::filename(FilePath);
110+
if (!FileName.endswith("json"))
111+
continue;
112+
std::ifstream i(FilePath.str());
113+
nl::json entry;
114+
i >> entry;
115+
result.emplace_back(std::move(entry));
125116
}
126-
closedir(directory);
127117
return result;
128118
}
129119

src/xinterpreter.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,6 @@
5252
#include <string>
5353
#include <vector>
5454

55-
#include <dirent.h>
56-
5755
std::string DiagnosticOutput;
5856
llvm::raw_string_ostream DiagnosticsOS(DiagnosticOutput);
5957
auto DiagPrinter = std::make_unique<clang::TextDiagnosticPrinter>(DiagnosticsOS, new clang::DiagnosticOptions());

0 commit comments

Comments
 (0)