Skip to content

Commit

Permalink
Fix getenv returning NULL
Browse files Browse the repository at this point in the history
  • Loading branch information
clementgallet committed Feb 8, 2019
1 parent d7618eb commit 5ca20a5
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions src/program/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -191,8 +191,11 @@ int main(int argc, char **argv)
context.libtaspath += "/libtas.so";

/* Create the working directories */
context.config.configdir = getenv("XDG_CONFIG_HOME");
if (context.config.configdir.empty()) {
char *path = getenv("XDG_CONFIG_HOME");
if (path) {
context.config.configdir = path;
}
else {
context.config.configdir = getenv("HOME");
context.config.configdir += "/.config";
}
Expand All @@ -213,8 +216,12 @@ int main(int argc, char **argv)
/* If the config file set custom directories for the remaining working dir,
* we create these directories (if not already created).
* Otherwise, we set and create the default ones. */
std::string data_dir = getenv("XDG_DATA_HOME");
if (data_dir.empty()) {
std::string data_dir;
path = getenv("XDG_DATA_HOME");
if (path) {
data_dir = path;
}
else {
data_dir = getenv("HOME");
data_dir += "/.local/share";
}
Expand Down

0 comments on commit 5ca20a5

Please sign in to comment.