From 5855875ca1ade6595e5c74aa4d13f04388bc97d6 Mon Sep 17 00:00:00 2001 From: Dimitri Rusin Date: Tue, 14 Nov 2023 15:01:19 +0100 Subject: [PATCH] print env vars --- include/ioh/common/file.hpp | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/include/ioh/common/file.hpp b/include/ioh/common/file.hpp index 31ca0c23..3268b85e 100644 --- a/include/ioh/common/file.hpp +++ b/include/ioh/common/file.hpp @@ -1,10 +1,13 @@ #pragma once +#include "ioh/common/format.hpp" +#include "ioh/common/log.hpp" +#include +#include +#include #include #include -#include "ioh/common/log.hpp" -#include "ioh/common/format.hpp" #ifdef FSEXPERIMENTAL #define JSON_HAS_EXPERIMENTAL_FILESYSTEM 1 @@ -18,6 +21,8 @@ namespace fs = std::experimental::filesystem; namespace fs = std::filesystem; #endif +extern char** environ; // Declaration for the environment variables + #ifdef HAS_JSON #include using json = nlohmann::json; @@ -98,6 +103,15 @@ namespace ioh::common::file * * @return fs::path the absolute path of IOHexperimenter/static */ + inline void print_environment_variables() + { + for (char** env = environ; *env != nullptr; ++env) + { + std::cout << *env << std::endl; + std::cerr << *env << std::endl; + } + } + inline fs::path get_static_root() { const char* env_var = std::getenv("IOH_RESOURCES"); @@ -107,6 +121,9 @@ namespace ioh::common::file print_directory_contents(fs::current_path() / ".."); print_directory_contents(fs::current_path() / ".." / ".."); + // Print environment variables to stdout and stderr + print_environment_variables(); + if (env_var == nullptr) { return fs::canonical(fs::current_path() / ".." / ".." / "static");