Fixed bug with unset environment variable.

When either HOME or XDG_CONFIG_HOME are unset getenv() can return NULL.
C++ strings don't like being set to NULL, so we need to check for this
case.

Bryan: Edited Sconstruct and commit message.

Signed-off-by: Josh Larson <theMutatedShrimp@gmail.com>
Signed-off-by: Bryan Schumaker <bjschuma@gmail.com>
This commit is contained in:
Josh Larson 2012-02-07 23:11:54 -05:00 committed by Bryan Schumaker
parent fe7bf9e445
commit 0d63656df8
2 changed files with 11 additions and 3 deletions

View File

@ -3,7 +3,7 @@ import sys
MAJOR = 5
MINOR = 5
BUG = 2
BUG = 3
EXTRA = ""
DEBUG = False

View File

@ -18,10 +18,18 @@ using namespace std;
static string SARIA_DIR = "/saria";
#endif /* DEBUG */
string get_saria_env(const char *env_name, string default_env)
{
char *result = getenv(env_name);
if (result)
return string(result);
return default_env;
}
string get_saria_dir()
{
string saria = getenv("HOME");
string xdg = getenv("XDG_CONFIG_HOME");
string saria = get_saria_env("HOME", "");
string xdg = get_saria_env("XDG_CONFIG_HOME", "~/.config");
if (xdg == "")
saria += "/.config";