Skip to content

Commit

Permalink
Fix minor bug, PWD was incorrectly set on startup
Browse files Browse the repository at this point in the history
darcs-hash:20080116220738-75c98-2b7c886629857540efee8f1cab9da0aa9ed8f76d.gz
  • Loading branch information
liljencrantz committed Jan 16, 2008
1 parent 1a66fc4 commit e10f754
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 18 deletions.
19 changes: 1 addition & 18 deletions builtin.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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] );
Expand Down
14 changes: 14 additions & 0 deletions env.c
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand All @@ -505,6 +517,8 @@ static void env_set_defaults()
free( unam_narrow );
}

env_set_pwd();

}

void env_init()
Expand Down
7 changes: 7 additions & 0 deletions env.h
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit e10f754

Please sign in to comment.