diff options
Diffstat (limited to 'louloulibs/utils/xdg.cpp')
-rw-r--r-- | louloulibs/utils/xdg.cpp | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/louloulibs/utils/xdg.cpp b/louloulibs/utils/xdg.cpp new file mode 100644 index 0000000..7a60dd8 --- /dev/null +++ b/louloulibs/utils/xdg.cpp @@ -0,0 +1,20 @@ +#include <utils/xdg.hpp> +#include <cstdlib> + +#include "louloulibs.h" + +std::string xdg_config_path(const std::string& filename) +{ + const char* xdg_config_home = ::getenv("XDG_CONFIG_HOME"); + if (xdg_config_home && xdg_config_home[0] == '/') + return std::string{xdg_config_home} + "/" PROJECT_NAME "/" + filename; + else + { + const char* home = ::getenv("HOME"); + if (home) + return std::string{home} + "/" ".config" "/" PROJECT_NAME "/" + filename; + else + return filename; + } +} + |