From 0d63656df8ecee64f0d15d7d04a6503833accefe Mon Sep 17 00:00:00 2001 From: Josh Larson Date: Tue, 7 Feb 2012 23:11:54 -0500 Subject: [PATCH] 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 Signed-off-by: Bryan Schumaker --- Sconstruct | 2 +- libsaria/path/dir.cpp | 12 ++++++++++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/Sconstruct b/Sconstruct index e922b0be..ce9ca6b7 100644 --- a/Sconstruct +++ b/Sconstruct @@ -3,7 +3,7 @@ import sys MAJOR = 5 MINOR = 5 -BUG = 2 +BUG = 3 EXTRA = "" DEBUG = False diff --git a/libsaria/path/dir.cpp b/libsaria/path/dir.cpp index ef6ff6ac..f8bebff1 100644 --- a/libsaria/path/dir.cpp +++ b/libsaria/path/dir.cpp @@ -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";