diff options
author | axel <axel@liljencrantz.se> | 2006-04-11 01:36:26 +1000 |
---|---|---|
committer | axel <axel@liljencrantz.se> | 2006-04-11 01:36:26 +1000 |
commit | bd9c843fd156ed5b637e2a5d1f11737d021bc380 (patch) | |
tree | d797f956747548a0b6498fdc4c8566499a0de8e9 | |
parent | f812b9b26cda8e8b386cbf0de08f3700811c7c9a (diff) |
Add warning when trying to change read-only variable
darcs-hash:20060410153626-ac50b-700ff7687647b8aab47ba79d759d1739cbe60425.gz
-rw-r--r-- | builtin_set.c | 18 | ||||
-rw-r--r-- | env.c | 11 | ||||
-rw-r--r-- | env.h | 13 |
3 files changed, 33 insertions, 9 deletions
diff --git a/builtin_set.c b/builtin_set.c index 5383456e..3588ba7c 100644 --- a/builtin_set.c +++ b/builtin_set.c @@ -26,6 +26,18 @@ Functions used for implementing the set builtin. #include "parser.h" #include "translate.h" +static void my_env_set( wchar_t *key, wchar_t *val, int scope ) +{ + switch( env_set( key, val, scope | ENV_USER ) ) + { + case ENV_PERM: + { + sb_printf( sb_err, _(L"%ls: Tried to change the read-only variable '%ls'\n"), L"set", key ); + break; + } + } +} + /** Extract the name from a destination argument of the form name[index1 index2...] */ @@ -512,7 +524,7 @@ int builtin_set( wchar_t **argv ) !erase && !list ) { - env_set( name, 0, scope ); + my_env_set( name, 0, scope ); finished = 1; } } @@ -572,7 +584,7 @@ int builtin_set( wchar_t **argv ) else { fill_buffer_from_list(&result_sb, &val_l); - env_set(name, (wchar_t *) result_sb.buff, scope); + my_env_set(name, (wchar_t *) result_sb.buff, scope); } } else @@ -585,7 +597,7 @@ int builtin_set( wchar_t **argv ) fill_buffer_from_list( &result_sb, &val_l ); - env_set(name, + my_env_set(name, (wchar_t *) result_sb.buff, scope); } @@ -608,7 +608,7 @@ static env_node_t *env_get_node( const wchar_t *key ) return 0; } -void env_set( const wchar_t *key, +int env_set( const wchar_t *key, const wchar_t *val, int var_mode ) { @@ -626,7 +626,7 @@ void env_set( const wchar_t *key, if( (var_mode & ENV_USER ) && hash_get( &env_read_only, key ) ) { - return; + return ENV_PERM; } if( wcscmp( key, L"umask" ) == 0) @@ -650,7 +650,7 @@ void env_set( const wchar_t *key, /* Do not actually create a umask variable, on env_get, it will be calculated dynamically */ - return; + return 0; } /* @@ -749,7 +749,7 @@ void env_set( const wchar_t *key, node = top; while( node->next && !node->new_scope ) node = node->next; - + } } } @@ -809,7 +809,8 @@ void env_set( const wchar_t *key, { handle_locale(); } - + + return 0; } @@ -42,6 +42,11 @@ #define ENV_UNIVERSAL 32 /** + Error code for trying to alter read-only variable +*/ +#define ENV_PERM 1 + +/** Initialize environment variable data */ void env_init(); @@ -61,9 +66,15 @@ void env_destroy(); \param val The value \param mode The type of the variable. Can be any combination of ENV_GLOBAL, ENV_LOCAL, ENV_EXPORT and ENV_USER. If mode is zero, the current variable space is searched and the current mode is used. If no current variable with the same name is found, ENV_LOCAL is assumed. + \returns 0 on suicess or an error code on failiure. + + The current error codes are: + + * ENV_PERM, can only be returned when setting as a user, e.g. ENV_USER is set. This means that the user tried to change a read-only variable. + */ -void env_set( const wchar_t *key, +int env_set( const wchar_t *key, const wchar_t *val, int mode ); |