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:
parent
fe7bf9e445
commit
0d63656df8
|
@ -3,7 +3,7 @@ import sys
|
|||
|
||||
MAJOR = 5
|
||||
MINOR = 5
|
||||
BUG = 2
|
||||
BUG = 3
|
||||
EXTRA = ""
|
||||
DEBUG = False
|
||||
|
||||
|
|
|
@ -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";
|
||||
|
|
Loading…
Reference in New Issue