From 87894c5f7b5d95d74ae01693dbba25386e872516 Mon Sep 17 00:00:00 2001 From: Alexandre Julliard Date: Thu, 15 Oct 2009 12:05:55 +0200 Subject: [PATCH] kernel32: Use the PWD variable to set the initial current directory. --- dlls/kernel32/process.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/dlls/kernel32/process.c b/dlls/kernel32/process.c index eca9e38d40d..7f0a218602c 100644 --- a/dlls/kernel32/process.c +++ b/dlls/kernel32/process.c @@ -759,6 +759,7 @@ static BOOL build_command_line( WCHAR **argv ) static void init_current_directory( CURDIR *cur_dir ) { UNICODE_STRING dir_str; + const char *pwd; char *cwd; int size; @@ -781,13 +782,25 @@ static void init_current_directory( CURDIR *cur_dir ) break; } + /* try to use PWD if it is valid, so that we don't resolve symlinks */ + + pwd = getenv( "PWD" ); if (cwd) { + struct stat st1, st2; + + if (!pwd || stat( pwd, &st1 ) == -1 || + (!stat( cwd, &st2 ) && (st1.st_dev != st2.st_dev || st1.st_ino != st2.st_ino))) + pwd = cwd; + } + + if (pwd) + { WCHAR *dirW; - int lenW = MultiByteToWideChar( CP_UNIXCP, 0, cwd, -1, NULL, 0 ); + int lenW = MultiByteToWideChar( CP_UNIXCP, 0, pwd, -1, NULL, 0 ); if ((dirW = HeapAlloc( GetProcessHeap(), 0, lenW * sizeof(WCHAR) ))) { - MultiByteToWideChar( CP_UNIXCP, 0, cwd, -1, dirW, lenW ); + MultiByteToWideChar( CP_UNIXCP, 0, pwd, -1, dirW, lenW ); RtlInitUnicodeString( &dir_str, dirW ); RtlSetCurrentDirectory_U( &dir_str ); RtlFreeUnicodeString( &dir_str ); -- 2.11.4.GIT