From 2b21e5f7c6a3e94816bb55a16be3e8a8f277d16d Mon Sep 17 00:00:00 2001 From: Steffen Vogel Date: Mon, 13 Sep 2021 19:14:22 +0200 Subject: [PATCH] remove dependency on std::filesystem --- common | 2 +- include/villas/config.hpp | 5 +---- lib/CMakeLists.txt | 4 ---- lib/config.cpp | 37 ++++++++++++++++++++++++++++--------- tests/unit/config.cpp | 2 -- 5 files changed, 30 insertions(+), 20 deletions(-) diff --git a/common b/common index dd9304ca0..3e062fdc0 160000 --- a/common +++ b/common @@ -1 +1 @@ -Subproject commit dd9304ca059efffe053b74159ca32b16a5eb4597 +Subproject commit 3e062fdc0f311d9eb4bc541b7a292def71f87cb0 diff --git a/include/villas/config.hpp b/include/villas/config.hpp index fba5ae197..10dcc9b3d 100644 --- a/include/villas/config.hpp +++ b/include/villas/config.hpp @@ -29,13 +29,10 @@ #include #include -#include #include #include -namespace fs = std::filesystem; - namespace villas { namespace node { @@ -76,7 +73,7 @@ protected: json_t * walkStrings(json_t *in, str_walk_fcn_t cb); /** Get the include dirs */ - std::list getIncludeDirs(FILE *f) const; + std::list getIncludeDirectories(FILE *f) const; public: json_t *root; diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt index f6794c749..dd58441af 100644 --- a/lib/CMakeLists.txt +++ b/lib/CMakeLists.txt @@ -40,10 +40,6 @@ if(UNIX AND NOT APPLE) list(APPEND LIBRARIES "rt") endif() -if(CMAKE_CXX_COMPILER_ID STREQUAL GNU) - list(APPEND LIBRARIES "-lstdc++fs") -endif() - set(LIB_SRC config_helper.cpp config.cpp diff --git a/lib/config.cpp b/lib/config.cpp index 8bd9431f7..bdb25d447 100644 --- a/lib/config.cpp +++ b/lib/config.cpp @@ -21,6 +21,7 @@ * along with this program. If not, see . *********************************************************************************/ +#include #include #include @@ -122,16 +123,34 @@ json_t * Config::decode(FILE *f) return root; } -std::list Config::getIncludeDirs(FILE *f) const +std::list Config::getIncludeDirectories(FILE *f) const { - auto uri = fs::read_symlink(fs::path("/proc/self/fd") / std::to_string(fileno(f))); - if (isLocalFile(uri)) { - return { - uri.parent_path() - }; + int ret, fd; + char buf[PATH_MAX]; + char *dir; + + std::list dirs; + + dir = getcwd(buf, sizeof(buf)); + if (dir != nullptr) + dirs.push_back(dir); + + fd = fileno(f); + if (fd < 0) + throw SystemError("Failed to get file descriptor"); + + auto path = fmt::format("/proc/self/fd/{}", fd); + + ret = readlink(path.c_str(), buf, sizeof(buf)); + if (ret > 0) { + buf[ret] = 0; + if (isLocalFile(buf)) { + dir = dirname(buf); + dirs.push_back(dir); + } } - else - return { }; + + return dirs; } #ifdef WITH_CONFIG @@ -145,7 +164,7 @@ json_t * Config::libconfigDecode(FILE *f) config_set_auto_convert(&cfg, 1); /* Setup libconfig include path. */ - auto inclDirs = getIncludeDirs(f); + auto inclDirs = getIncludeDirectories(f); if (inclDirs.size() > 0) { logger->info("Setting include dir to: {}", inclDirs.front()); diff --git a/tests/unit/config.cpp b/tests/unit/config.cpp index 77e318089..e9f8928d3 100644 --- a/tests/unit/config.cpp +++ b/tests/unit/config.cpp @@ -22,13 +22,11 @@ #include #include -#include #include #include #include -namespace fs = std::filesystem; using namespace villas::node; // cppcheck-suppress syntaxError