summaryrefslogtreecommitdiff
path: root/louloulibs/utils/xdg.cpp
blob: 7a60dd800ac401bac9e7cb3088cbb652ea1beb11 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
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;
    }
}