-
Notifications
You must be signed in to change notification settings - Fork 0
/
ConfigHelpers.cpp
43 lines (34 loc) · 1006 Bytes
/
ConfigHelpers.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#include "ConfigHelpers.h"
#include <glib.h>
std::deque<std::string> ConfigDirs()
{
std::deque<std::string> dirs;
#ifdef SNAPCRAFT_BUILD
if(const gchar* data = g_getenv("SNAP"))
dirs.push_back(std::string(data) + "/etc");
if(const gchar* common = g_getenv("SNAP_COMMON"))
dirs.push_back(common);
#else
const gchar * const *systemConfigDirs = g_get_system_config_dirs();
while(*systemConfigDirs) {
dirs.push_back(*systemConfigDirs);
++systemConfigDirs;
}
const gchar* configDir = g_get_user_config_dir();
if(configDir)
dirs.push_back(configDir);
#endif
return dirs;
}
std::string FullPath(const std::string& configDir, const std::string& path)
{
std::string fullPath;
if(!g_path_is_absolute(path.c_str())) {
gchar* tmpPath =
g_build_filename(configDir.c_str(), path.c_str(), NULL);
fullPath = tmpPath;
g_free(tmpPath);
} else
fullPath = path;
return fullPath;
}