diff --git a/env.c b/env.c index a58f75f8c..0f5d4bb4a 100644 --- a/env.c +++ b/env.c @@ -343,43 +343,57 @@ void env_init() if( !path ) { env_set( L"PATH", L"/bin" ARRAY_SEP_STR L"/usr/bin", ENV_EXPORT | ENV_GLOBAL ); + path = env_get( L"PATH" ); } else { - int i; + int i, j; array_list_t l; - int has_bin=0, has_usr_bin=0; al_init( &l ); expand_variable_array( path, &l ); - for( i=0; i 0) && (el[len-1]==L'/') ) + len--; + if( (wcslen( path_el[j] ) == len) && (wcsncmp( el, path_el[j], len)==0) ) + { + has_el = 1; + } + } + + if( !has_el ) + { + string_buffer_t b; + sb_init( &b ); + sb_append2( &b, path, + ARRAY_SEP_STR, + path_el[j], + (void *)0 ); + + env_set( L"PATH", (wchar_t *)b.buff, ENV_GLOBAL | ENV_EXPORT ); + sb_destroy( &b ); + path = env_get( L"PATH" ); + } } - if( !( has_bin && has_usr_bin ) ) - { - string_buffer_t b; - sb_init( &b ); - sb_append( &b, path ); - if( !has_bin ) - sb_append( &b, ARRAY_SEP_STR L"/bin" ); - if( !has_usr_bin ) - sb_append( &b, ARRAY_SEP_STR L"/usr/bin" ); - - env_set( L"PATH", (wchar_t *)b.buff, ENV_GLOBAL | ENV_EXPORT ); - sb_destroy( &b ); - } - al_foreach( &l, (void (*)(const void *))&free ); al_destroy( &l );