From e10f75483fcbf44a813e9fd446529bccc1e52eee Mon Sep 17 00:00:00 2001 From: liljencrantz Date: Thu, 17 Jan 2008 08:07:38 +1000 Subject: [PATCH] Fix minor bug, PWD was incorrectly set on startup darcs-hash:20080116220738-75c98-2b7c886629857540efee8f1cab9da0aa9ed8f76d.gz --- builtin.c | 19 +------------------ env.c | 14 ++++++++++++++ env.h | 7 +++++++ 3 files changed, 22 insertions(+), 18 deletions(-) diff --git a/builtin.c b/builtin.c index 37b4fad..ba6f3a0 100644 --- a/builtin.c +++ b/builtin.c @@ -2554,23 +2554,6 @@ static int builtin_exit( wchar_t **argv ) 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 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; } - else if( !set_pwd(L"PWD") ) + else if( !env_set_pwd(L"PWD") ) { res=1; sb_printf( sb_err, _( L"%ls: Could not set PWD variable\n" ), argv[0] ); diff --git a/env.c b/env.c index c0f1215..3212518 100644 --- a/env.c +++ b/env.c @@ -480,6 +480,18 @@ static void setup_path() 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. */ @@ -505,6 +517,8 @@ static void env_set_defaults() free( unam_narrow ); } + env_set_pwd(); + } void env_init() diff --git a/env.h b/env.h index 3297d5a..311c234 100644 --- a/env.h +++ b/env.h @@ -132,4 +132,11 @@ char **env_export_arr( int recalc ); */ void env_get_names( array_list_t *l, int flags ); +/** + Update the PWD variable + directory +*/ +int env_set_pwd(); + + #endif