Jacek Caban : winex11: Directly use wine_nt_to_unix_file_name to get Unix path name.

Alexandre Julliard julliard at winehq.org
Tue May 3 15:39:24 CDT 2022


Module: wine
Branch: master
Commit: 12326097116b1e60b191e274d9199814323610c1
URL:    https://source.winehq.org/git/wine.git/?a=commit;h=12326097116b1e60b191e274d9199814323610c1

Author: Jacek Caban <jacek at codeweavers.com>
Date:   Sun May  1 21:07:09 2022 +0200

winex11: Directly use wine_nt_to_unix_file_name to get Unix path name.

Signed-off-by: Jacek Caban <jacek at codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>

---

 dlls/winex11.drv/clipboard.c | 80 ++++++++++++++++++++++++++++++++++++++++++--
 1 file changed, 77 insertions(+), 3 deletions(-)

diff --git a/dlls/winex11.drv/clipboard.c b/dlls/winex11.drv/clipboard.c
index 430bc6c1c81..30534af6bf3 100644
--- a/dlls/winex11.drv/clipboard.c
+++ b/dlls/winex11.drv/clipboard.c
@@ -76,6 +76,8 @@
 #include <time.h>
 #include <assert.h>
 
+#include "ntstatus.h"
+#define WIN32_NO_STATUS
 #include "x11drv.h"
 
 #ifdef HAVE_X11_EXTENSIONS_XFIXES_H
@@ -598,6 +600,78 @@ static WCHAR *get_dos_file_name( const char *path )
 }
 
 
+/***********************************************************************
+ *           get_nt_pathname
+ *
+ * Simplified version of RtlDosPathNameToNtPathName_U.
+ */
+static BOOL get_nt_pathname( const WCHAR *name, UNICODE_STRING *nt_name )
+{
+    static const WCHAR ntprefixW[] = {'\\','?','?','\\'};
+    static const WCHAR uncprefixW[] = {'U','N','C','\\'};
+    size_t len = lstrlenW( name );
+    WCHAR *ptr;
+
+    nt_name->MaximumLength = (len + 8) * sizeof(WCHAR);
+    if (!(ptr = malloc( nt_name->MaximumLength ))) return FALSE;
+    nt_name->Buffer = ptr;
+
+    memcpy( ptr, ntprefixW, sizeof(ntprefixW) );
+    ptr += ARRAYSIZE(ntprefixW);
+    if (name[0] == '\\' && name[1] == '\\')
+    {
+        if ((name[2] == '.' || name[2] == '?') && name[3] == '\\')
+        {
+            name += 4;
+            len -= 4;
+        }
+        else
+        {
+            memcpy( ptr, uncprefixW, sizeof(uncprefixW) );
+            ptr += ARRAYSIZE(uncprefixW);
+            name += 2;
+            len -= 2;
+        }
+    }
+    memcpy( ptr, name, (len + 1) * sizeof(WCHAR) );
+    ptr += len;
+    nt_name->Length = (ptr - nt_name->Buffer) * sizeof(WCHAR);
+    return TRUE;
+}
+
+
+/* based on wine_get_unix_file_name */
+char *get_unix_file_name( const WCHAR *dosW )
+{
+    UNICODE_STRING nt_name;
+    OBJECT_ATTRIBUTES attr;
+    NTSTATUS status;
+    ULONG size = 256;
+    char *buffer;
+
+    if (!get_nt_pathname( dosW, &nt_name )) return NULL;
+    InitializeObjectAttributes( &attr, &nt_name, 0, 0, NULL );
+    for (;;)
+    {
+        if (!(buffer = malloc( size )))
+        {
+            free( nt_name.Buffer );
+            return NULL;
+        }
+        status = wine_nt_to_unix_file_name( &attr, buffer, &size, FILE_OPEN_IF );
+        if (status != STATUS_BUFFER_TOO_SMALL) break;
+        free( buffer );
+    }
+    free( nt_name.Buffer );
+    if (status)
+    {
+        free( buffer );
+        return NULL;
+    }
+    return buffer;
+}
+
+
 /***********************************************************************
  *           uri_to_dos
  *
@@ -1421,7 +1495,7 @@ static BOOL export_hdrop( Display *display, Window win, Atom prop, Atom target,
         UINT uriSize;
         UINT u;
 
-        unixFilename = wine_get_unix_file_name( ptr );
+        unixFilename = get_unix_file_name( ptr );
         if (unixFilename == NULL) goto failed;
         ptr += lstrlenW( ptr ) + 1;
 
@@ -1439,7 +1513,7 @@ static BOOL export_hdrop( Display *display, Window win, Atom prop, Atom target,
             }
             else
             {
-                HeapFree(GetProcessHeap(), 0, unixFilename);
+                free( unixFilename );
                 goto failed;
             }
         }
@@ -1455,7 +1529,7 @@ static BOOL export_hdrop( Display *display, Window win, Atom prop, Atom target,
         }
         textUriList[next++] = '\r';
         textUriList[next++] = '\n';
-        HeapFree(GetProcessHeap(), 0, unixFilename);
+        free( unixFilename );
     }
     put_property( display, win, prop, target, 8, textUriList, next );
     free( textUriList );




More information about the wine-cvs mailing list