winex11: Directly use wine_nt_to_unix_file_name to get Unix path name.

Signed-off-by: Jacek Caban <jacek@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Jacek Caban 2022-05-01 21:07:09 +02:00 committed by Alexandre Julliard
parent c0a8b2dbd5
commit 1232609711
1 changed files with 77 additions and 3 deletions

View File

@ -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 );