From fc87182d191a2b3daabf260d1ad4b12b157e3cd1 Mon Sep 17 00:00:00 2001
From: Alexandre Julliard <julliard@winehq.org>
Date: Thu, 2 Apr 2009 12:59:32 +0200
Subject: [PATCH] kernel32: Set argv[0] to the full path of the binary when
 starting from Unix.

---
 dlls/kernel32/process.c | 25 +++++++++++++++++++++++++
 1 file changed, 25 insertions(+)

diff --git a/dlls/kernel32/process.c b/dlls/kernel32/process.c
index 286f0ab7d6e..624d4de544d 100644
--- a/dlls/kernel32/process.c
+++ b/dlls/kernel32/process.c
@@ -598,6 +598,30 @@ static void set_library_wargv( char **argv )
 }
 
 
+/***********************************************************************
+ *              update_library_argv0
+ *
+ * Update the argv[0] global variable with the binary we have found.
+ */
+static void update_library_argv0( const WCHAR *argv0 )
+{
+    DWORD len = strlenW( argv0 );
+
+    if (len > strlenW( __wine_main_wargv[0] ))
+    {
+        __wine_main_wargv[0] = RtlAllocateHeap( GetProcessHeap(), 0, (len + 1) * sizeof(WCHAR) );
+    }
+    strcpyW( __wine_main_wargv[0], argv0 );
+
+    len = WideCharToMultiByte( CP_ACP, 0, argv0, -1, NULL, 0, NULL, NULL );
+    if (len > strlen( __wine_main_argv[0] ) + 1)
+    {
+        __wine_main_argv[0] = RtlAllocateHeap( GetProcessHeap(), 0, len );
+    }
+    WideCharToMultiByte( CP_ACP, 0, argv0, -1, __wine_main_argv[0], len, NULL, NULL );
+}
+
+
 /***********************************************************************
  *           build_command_line
  *
@@ -1024,6 +1048,7 @@ void CDECL __wine_kernel_init(void)
             MESSAGE( "wine: cannot find '%s'\n", __wine_main_argv[0] );
             ExitProcess( GetLastError() );
         }
+        update_library_argv0( main_exe_name );
         if (!build_command_line( __wine_main_wargv )) goto error;
         boot_event = start_wineboot();
     }
-- 
GitLab