Fix minor bug, PWD was incorrectly set on startup

darcs-hash:20080116220738-75c98-2b7c886629857540efee8f1cab9da0aa9ed8f76d.gz
This commit is contained in:
liljencrantz 2008-01-17 08:07:38 +10:00
parent 1a66fc4c5d
commit e10f75483f
3 changed files with 22 additions and 18 deletions

View file

@ -2554,23 +2554,6 @@ static int builtin_exit( wchar_t **argv )
return ec; return ec;
} }
/**
Helper function for builtin_cd, used for seting the current working
directory
*/
static int set_pwd( wchar_t *env)
{
wchar_t dir_path[4096];
wchar_t *res = wgetcwd( dir_path, 4096 );
if( !res )
{
builtin_wperror( L"wgetcwd" );
return STATUS_BUILTIN_OK;
}
env_set( env, dir_path, ENV_EXPORT | ENV_GLOBAL );
return 1;
}
/** /**
The cd builtin. Changes the current directory to the one specified The cd builtin. Changes the current directory to the one specified
or to $HOME if none is specified. The directory can be relative to or to $HOME if none is specified. The directory can be relative to
@ -2674,7 +2657,7 @@ static int builtin_cd( wchar_t **argv )
res = 1; res = 1;
} }
else if( !set_pwd(L"PWD") ) else if( !env_set_pwd(L"PWD") )
{ {
res=1; res=1;
sb_printf( sb_err, _( L"%ls: Could not set PWD variable\n" ), argv[0] ); sb_printf( sb_err, _( L"%ls: Could not set PWD variable\n" ), argv[0] );

14
env.c
View file

@ -480,6 +480,18 @@ static void setup_path()
al_destroy( &l ); al_destroy( &l );
} }
int env_set_pwd()
{
wchar_t dir_path[4096];
wchar_t *res = wgetcwd( dir_path, 4096 );
if( !res )
{
return 0;
}
env_set( L"PWD", dir_path, ENV_EXPORT | ENV_GLOBAL );
return 1;
}
/** /**
Set up default values for various variables if not defined. Set up default values for various variables if not defined.
*/ */
@ -505,6 +517,8 @@ static void env_set_defaults()
free( unam_narrow ); free( unam_narrow );
} }
env_set_pwd();
} }
void env_init() void env_init()

7
env.h
View file

@ -132,4 +132,11 @@ char **env_export_arr( int recalc );
*/ */
void env_get_names( array_list_t *l, int flags ); void env_get_names( array_list_t *l, int flags );
/**
Update the PWD variable
directory
*/
int env_set_pwd();
#endif #endif