aboutsummaryrefslogtreecommitdiffhomepage
path: root/env.cpp
diff options
context:
space:
mode:
authorGravatar Peter Ammon <corydoras@ridiculousfish.com>2012-01-14 01:06:47 -0800
committerGravatar Peter Ammon <corydoras@ridiculousfish.com>2012-01-14 01:06:47 -0800
commite8b6d48ad038089e37730990212676e50a8d2352 (patch)
tree18b23c3bff183e9c9a3d3bae9ecbbb49a28f8743 /env.cpp
parent8ba79d6ab9093388df36c06c2b9e2e2b95014cd5 (diff)
Introduce env_var_t to replace empty string as missing environment variable
Diffstat (limited to 'env.cpp')
-rw-r--r--env.cpp25
1 files changed, 19 insertions, 6 deletions
diff --git a/env.cpp b/env.cpp
index 1233a87d..e0d31686 100644
--- a/env.cpp
+++ b/env.cpp
@@ -10,6 +10,7 @@
#include <locale.h>
#include <unistd.h>
#include <signal.h>
+#include <assert.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <pthread.h>
@@ -300,7 +301,7 @@ static int is_locale( const wchar_t *key )
*/
static void handle_locale()
{
- const wcstring lc_all = env_get_string( L"LC_ALL" );
+ const env_var_t lc_all = env_get_string( L"LC_ALL" );
wcstring lang;
int i;
wchar_t *old = wcsdup(wsetlocale( LC_MESSAGES, NULL ));
@@ -321,7 +322,7 @@ static void handle_locale()
}
;
- if( !lc_all.empty() )
+ if( !lc_all.missing() )
{
wsetlocale( LC_ALL, lc_all.c_str() );
}
@@ -669,7 +670,8 @@ void env_init()
/*
Set up SHLVL variable
*/
- const wchar_t *shlvl = env_get_string( L"SHLVL" ).empty()?NULL:env_get_string( L"SHLVL" ).c_str();
+ const wcstring shlvl_str = env_get_string( L"SHLVL" );
+ const wchar_t *shlvl = shlvl_str.empty() ? NULL : shlvl_str.c_str();
if ( shlvl )
{
@@ -1136,7 +1138,18 @@ int env_remove( const wchar_t *key, int var_mode )
return !erased;
}
-wcstring env_get_string( const wchar_t *key )
+env_var_t env_var_t::missing_var(void) {
+ env_var_t result(L"");
+ result.is_missing = true;
+ return result;
+}
+
+const wchar_t *env_var_t::c_str(void) const {
+ assert(! is_missing);
+ return wcstring::c_str();
+}
+
+env_var_t env_get_string( const wchar_t *key )
{
scoped_lock lock(env_lock);
@@ -1231,7 +1244,7 @@ wcstring env_get_string( const wchar_t *key )
if( !item || (wcscmp( item, ENV_NULL )==0))
{
- return wcstring(L"");
+ return env_var_t::missing_var();
}
else
{
@@ -1772,7 +1785,7 @@ char **env_export_arr( int recalc )
hash_table_t vals;
int prev_was_null=1;
int pos=0;
- int i;
+ size_t i;
debug( 4, L"env_export_arr() recalc" );