Alexandre Julliard : kernel32: Use the PWD variable to set the initial current directory.

Alexandre Julliard julliard at winehq.org
Thu Oct 15 08:54:39 CDT 2009


Module: wine
Branch: master
Commit: 87894c5f7b5d95d74ae01693dbba25386e872516
URL:    http://source.winehq.org/git/wine.git/?a=commit;h=87894c5f7b5d95d74ae01693dbba25386e872516

Author: Alexandre Julliard <julliard at winehq.org>
Date:   Thu Oct 15 12:05:55 2009 +0200

kernel32: Use the PWD variable to set the initial current directory.

---

 dlls/kernel32/process.c |   17 +++++++++++++++--
 1 files changed, 15 insertions(+), 2 deletions(-)

diff --git a/dlls/kernel32/process.c b/dlls/kernel32/process.c
index eca9e38..7f0a218 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 );




More information about the wine-cvs mailing list