summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorFlorent Le Coz <louiz@louiz.org>2015-09-18 09:18:33 +0200
committerFlorent Le Coz <louiz@louiz.org>2015-09-18 09:20:15 +0200
commitea0b2f2bb871e7760d1936bb9b193655682df413 (patch)
tree07be7f5a0ea2f62904273e1b2bbf19a72c8e40f6 /src
parent73573ebb2abb2aea119a6c99e2bf4a302f2ba834 (diff)
downloadbiboumi-ea0b2f2bb871e7760d1936bb9b193655682df413.tar.gz
biboumi-ea0b2f2bb871e7760d1936bb9b193655682df413.tar.bz2
biboumi-ea0b2f2bb871e7760d1936bb9b193655682df413.tar.xz
biboumi-ea0b2f2bb871e7760d1936bb9b193655682df413.zip
Create a xdg_path function
Diffstat (limited to 'src')
-rw-r--r--src/main.cpp16
-rw-r--r--src/test.cpp22
2 files changed, 24 insertions, 14 deletions
diff --git a/src/main.cpp b/src/main.cpp
index 159dcbe..5c9e071 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -4,11 +4,11 @@
#include <config/config.hpp>
#include <logger/logger.hpp>
#include <utils/reload.hpp>
+#include <utils/xdg.hpp>
#include <iostream>
#include <memory>
#include <atomic>
-#include <cstdlib>
#include <signal.h>
@@ -69,19 +69,7 @@ int main(int ac, char** av)
if (ac > 1)
Config::filename = av[1];
else
- {
- const char* xdg_config_home = getenv("XDG_CONFIG_HOME");
- if (xdg_config_home && xdg_config_home[0] == '/')
- Config::filename = std::string{xdg_config_home} + "/" "biboumi" "/" "biboumi.cfg";
- else
- {
- const char* home = getenv("HOME");
- if (home)
- Config::filename = std::string{home} + "/" ".config" "/" "biboumi" "/" "biboumi.cfg";
- else
- Config::filename = "biboumi.cfg";
- }
- }
+ Config::filename = xdg_path("biboumi.cfg");
Config::file_must_exist = true;
std::cerr << "Using configuration file: " << Config::filename << std::endl;
diff --git a/src/test.cpp b/src/test.cpp
index 842dfed..b8737e6 100644
--- a/src/test.cpp
+++ b/src/test.cpp
@@ -402,6 +402,28 @@ int main()
assert(iid6.is_channel);
assert(!iid6.is_user);
}
+ {
+
+ {
+ std::cout << color << "Testing the xdg_path function…" << reset << std::endl;
+ std::string res;
+
+ ::unsetenv("XDG_CONFIG_HOME");
+ ::unsetenv("HOME");
+ res = xdg_config_path("coucou.txt");
+ std::cout << res << std::endl;
+ assert(res == "coucou.txt");
+
+ ::setenv("HOME", "/home/user", 1);
+ res = xdg_config_path("coucou.txt");
+ std::cout << res << std::endl;
+ assert(res == "/home/user/.config/biboumi/coucou.txt");
+
+ ::setenv("XDG_CONFIG_HOME", "/some_weird_dir", 1);
+ res = xdg_config_path("coucou.txt");
+ std::cout << res << std::endl;
+ assert(res == "/some_weird_dir/biboumi/coucou.txt");
+ }
return 0;
}