kernel32: Use the PWD variable to set the initial current directory.
authorAlexandre Julliard <julliard@winehq.org>
Thu, 15 Oct 2009 10:05:55 +0000 (12:05 +0200)
committerAlexandre Julliard <julliard@winehq.org>
Thu, 15 Oct 2009 10:06:23 +0000 (12:06 +0200)
dlls/kernel32/process.c

index eca9e38d40d445b6a21c23deb4edd23339218f7d..7f0a218602cce7b772cda2a411c2a017c4695296 100644 (file)
@@ -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 );