Skip to content

Commit

Permalink
Fix windows builds by not using dirent.h
Browse files Browse the repository at this point in the history
  • Loading branch information
vgvassilev committed Jul 21, 2023
1 parent 62f2f3a commit a17da7e
Showing 1 changed file with 14 additions and 24 deletions.
38 changes: 14 additions & 24 deletions src/xinspect.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
#include <fstream>
#include <string>

#include <dirent.h>

#include <pugixml.hpp>

Expand All @@ -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
Expand Down Expand Up @@ -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;
}

Expand Down

0 comments on commit a17da7e

Please sign in to comment.