diff options
Diffstat (limited to 'src/runtime_paths.cpp')
-rw-r--r-- | src/runtime_paths.cpp | 41 |
1 files changed, 24 insertions, 17 deletions
diff --git a/src/runtime_paths.cpp b/src/runtime_paths.cpp index db3ccd3f..17167e9a 100644 --- a/src/runtime_paths.cpp +++ b/src/runtime_paths.cpp @@ -14,15 +14,15 @@ along with Ingen. If not, see <http://www.gnu.org/licenses/>. */ -#include "ingen/runtime_paths.hpp" +#include <ingen/runtime_paths.hpp> + +#include <ingen/FilePath.hpp> -#include "ingen/FilePath.hpp" -#include "ingen/filesystem.hpp" #include "ingen_config.h" -#include <algorithm> #include <cstdlib> #include <dlfcn.h> +#include <filesystem> #include <sstream> #include <string> @@ -45,7 +45,8 @@ static const char* const library_suffix = ".so"; #endif static std::vector<FilePath> -parse_search_path(const char* search_path, std::vector<FilePath> defaults) +parse_search_path(const char* search_path, + const std::vector<FilePath>& defaults) { if (!search_path) { return defaults; @@ -65,12 +66,12 @@ parse_search_path(const char* search_path, std::vector<FilePath> defaults) * Passing a function defined in a module etc. will not work! */ void -set_bundle_path_from_code(void* function) +set_bundle_path_from_code(void (*function)()) { Dl_info dli; - dladdr(function, &dli); + dladdr(reinterpret_cast<void*>(function), &dli); -#ifdef BUNDLE +#if INGEN_BUNDLED char bin_loc[PATH_MAX]; realpath(dli.dli_fname, bin_loc); #else @@ -92,7 +93,7 @@ find_in_search_path(const std::string& name, { for (const auto& dir : search_path) { FilePath path = dir / name; - if (filesystem::exists(path)) { + if (std::filesystem::exists(path)) { return path; } } @@ -117,7 +118,7 @@ data_file_path(const std::string& name) std::vector<FilePath> ingen_module_dirs() { -#ifdef BUNDLE +#if INGEN_BUNDLED const FilePath default_dir = FilePath(bundle_path) / INGEN_MODULE_DIR; #else const FilePath default_dir = INGEN_MODULE_DIR; @@ -138,22 +139,28 @@ FilePath user_config_dir() { if (const char* xdg_config_home = getenv("XDG_CONFIG_HOME")) { - return FilePath(xdg_config_home); - } else if (const char* home = getenv("HOME")) { + return {xdg_config_home}; + } + + if (const char* home = getenv("HOME")) { return FilePath(home) / ".config"; } - return FilePath(); + + return {}; } FilePath user_data_dir() { if (const char* xdg_data_home = getenv("XDG_DATA_HOME")) { - return FilePath(xdg_data_home); - } else if (const char* home = getenv("HOME")) { + return {xdg_data_home}; + } + + if (const char* home = getenv("HOME")) { return FilePath(home) / ".local/share"; } - return FilePath(); + + return {}; } std::vector<FilePath> @@ -186,7 +193,7 @@ data_dirs() std::vector<FilePath> paths = system_data_dirs(); const FilePath user_dir = user_data_dir(); -#ifdef BUNDLE +#if INGEN_BUNDLED paths.insert(paths.begin(), bundle_path / INGEN_DATA_DIR); #endif |