From e4f5bc69e29b88796b13eb117dde098695dad9b9 Mon Sep 17 00:00:00 2001 From: axel Date: Fri, 11 May 2007 05:11:28 +1000 Subject: Make sure that the PWD and HOME variables are always in canonical form darcs-hash:20070510191128-ac50b-dd51a75617d62e4f403094ddc7527a82c5de3103.gz --- path.c | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) (limited to 'path.c') diff --git a/path.c b/path.c index 469c702c..7cb3e0a5 100644 --- a/path.c +++ b/path.c @@ -266,3 +266,38 @@ wchar_t *path_get_config( void *context) } +wchar_t *path_make_canonical( void *context, const wchar_t *path ) +{ + wchar_t *res = halloc_wcsdup( context, path ); + wchar_t *in, *out; + + in = out = res; + + while( *in ) + { + if( *in == L'/' ) + { + while( *(in+1) == L'/' ) + { + in++; + } + } + *out = *in; + + out++; + in++; + } + + while( 1 ) + { + if( out == res ) + break; + if( *(out-1) != L'/' ) + break; + out--; + } + *out = 0; + + return res; +} + -- cgit v1.2.3