Commit ac307338 authored by Link Mauve's avatar Link Mauve Committed by louiz’

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
parent a8225dc5
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
#include <iostream> #include <iostream>
#include <memory> #include <memory>
#include <atomic> #include <atomic>
#include <cstdlib>
#include <signal.h> #include <signal.h>
...@@ -68,7 +69,19 @@ int main(int ac, char** av) ...@@ -68,7 +69,19 @@ int main(int ac, char** av)
if (ac > 1) if (ac > 1)
Config::filename = av[1]; Config::filename = av[1];
else 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; Config::file_must_exist = true;
std::cerr << "Using configuration file: " << Config::filename << std::endl; std::cerr << "Using configuration file: " << Config::filename << std::endl;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment