Give USER and HOME default values if undefined

darcs-hash:20061019113844-ac50b-def2288d589f479779166ed64903e99c8c8ab71a.gz
This commit is contained in:
axel
2006-10-19 21:38:44 +10:00
parent 8b3bcd2c4c
commit f6815629fc

27
env.c
View File

@@ -452,6 +452,27 @@ static void setup_path()
al_destroy( &l );
}
static void env_set_defaults()
{
if( !env_get( L"USER" ) )
{
struct passwd *pw = getpwuid( getuid());
wchar_t *unam = str2wcs( pw->pw_name );
env_set( L"USER", unam, ENV_GLOBAL );
free( unam );
}
if( !env_get( L"HOME" ) )
{
wchar_t *unam = env_get( L"USER" );
char *unam_narrow = wcs2str( unam );
struct passwd *pw = getpwnam( unam_narrow );
wchar_t *dir = str2wcs( pw->pw_dir );
env_set( L"HOME", dir, ENV_GLOBAL );
free( dir );
free( unam_narrow );
}
}
void env_init()
{
char **p;
@@ -570,7 +591,11 @@ void env_init()
env_get( L"USER" ),
&start_fishd,
&universal_callback );
/*
Set correct defaults for e.g. USER and HOME variables
*/
env_set_defaults();
}
void env_destroy()