Create a xdg_path function

This commit is contained in:
Florent Le Coz
2015-09-18 09:20:15 +02:00
parent 73573ebb2a
commit ea0b2f2bb8
5 changed files with 59 additions and 15 deletions
+2 -1
View File
@@ -5,4 +5,5 @@
#cmakedefine POLLER ${POLLER}
#cmakedefine BOTAN_FOUND
#cmakedefine CARES_FOUND
#cmakedefine SOFTWARE_VERSION "${SOFTWARE_VERSION}"
#cmakedefine SOFTWARE_VERSION "${SOFTWARE_VERSION}"
#cmakedefine PROJECT_NAME "${PROJECT_NAME}"
+20
View File
@@ -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;
}
}
+13
View File
@@ -0,0 +1,13 @@
#ifndef XDG_HPP_INCLUDED
#define XDG_HPP_INCLUDED
#include <string>
/**
* Returns a path for the given filename, according to the XDG base
* directory specification, see
* http://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html
*/
std::string xdg_config_path(const std::string& filename);
#endif /* XDG_HPP_INCLUDED */