// SPDX-License-Identifier: Apache-2.0 /* * Copyright (C) 2022 Greg Davill */ #if defined (_WIN64) || defined (_WIN32) #include "pathHelper.hpp" #include #include #include #include #include std::string PathHelper::absolutePath(std::string input_path) { /* Attempt to execute cygpath */ std::string cmd = std::string("cygpath -m " + input_path); std::array buffer; std::string result; std::unique_ptr pipe(popen(cmd.c_str(), "r"), pclose); if (!pipe) { /* If cygpath fails to run, return original path */ return input_path; } while (fgets(buffer.data(), buffer.size(), pipe.get()) != nullptr) { result += buffer.data(); } /* Trim trailing newline */ static const std::regex tws{"[[:space:]]*$", std::regex_constants::extended}; return std::regex_replace(result, tws, ""); } #endif