mirror of
https://github.com/fish-shell/fish-shell
synced 2024-12-27 05:13:10 +00:00
Add warning when trying to change read-only variable
darcs-hash:20060410153626-ac50b-700ff7687647b8aab47ba79d759d1739cbe60425.gz
This commit is contained in:
parent
f812b9b26c
commit
bd9c843fd1
3 changed files with 33 additions and 9 deletions
|
@ -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);
|
||||
}
|
||||
|
|
7
env.c
7
env.c
|
@ -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;
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -810,6 +810,7 @@ void env_set( const wchar_t *key,
|
|||
handle_locale();
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
|
13
env.h
13
env.h
|
@ -41,6 +41,11 @@
|
|||
*/
|
||||
#define ENV_UNIVERSAL 32
|
||||
|
||||
/**
|
||||
Error code for trying to alter read-only variable
|
||||
*/
|
||||
#define ENV_PERM 1
|
||||
|
||||
/**
|
||||
Initialize environment variable data
|
||||
*/
|
||||
|
@ -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 );
|
||||
|
||||
|
|
Loading…
Reference in a new issue