summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEmmanuel Gil Peyrot <linkmauve@linkmauve.fr>2015-04-30 09:56:13 +0200
committerFlorent Le Coz <louiz@louiz.org>2015-05-04 16:50:35 +0200
commitac30733800b69dcb1589adcba6a42b20fa763e8f (patch)
tree53b0d07359563439e09eb3fa8ca81436e1bd73f8
parenta8225dc54c019788722bda3bda8d55151c1ccdef (diff)
downloadbiboumi-ac30733800b69dcb1589adcba6a42b20fa763e8f.tar.gz
biboumi-ac30733800b69dcb1589adcba6a42b20fa763e8f.tar.bz2
biboumi-ac30733800b69dcb1589adcba6a42b20fa763e8f.tar.xz
biboumi-ac30733800b69dcb1589adcba6a42b20fa763e8f.zip
Search for the config file in $XDG_CONFIG_DIR/biboumi.
This environment variable points to the location the user expects to find every program’s config file, or if it isn’t set, ~/.config/biboumi (with a fallback to . if $HOME isn’t set). fix #2553
-rw-r--r--src/main.cpp15
1 files changed, 14 insertions, 1 deletions
diff --git a/src/main.cpp b/src/main.cpp
index 62a28a5..80462cb 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -8,6 +8,7 @@
#include <iostream>
#include <memory>
#include <atomic>
+#include <cstdlib>
#include <signal.h>
@@ -68,7 +69,19 @@ int main(int ac, char** av)
if (ac > 1)
Config::filename = av[1];
else
- Config::filename = "biboumi.cfg";
+ {
+ const char* xdg_config_home = getenv("XDG_CONFIG_HOME");
+ if (xdg_config_home)
+ 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::file_must_exist = true;
std::cerr << "Using configuration file: " << Config::filename << std::endl;