ntdll: Allocate the return buffer in the caller for wine_nt_to_unix_file_name().

Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Alexandre Julliard 2020-07-09 09:59:08 +02:00
parent d0a16b7dc9
commit 368e3a93b8
6 changed files with 29 additions and 10 deletions

View File

@ -276,18 +276,30 @@ DWORD /*BOOLEAN*/ WINAPI KERNEL32_Wow64EnableWow64FsRedirection( BOOLEAN enable
char * CDECL wine_get_unix_file_name( LPCWSTR dosW )
{
UNICODE_STRING nt_name;
ANSI_STRING unix_name;
NTSTATUS status;
SIZE_T size = 256;
char *buffer;
if (!RtlDosPathNameToNtPathName_U( dosW, &nt_name, NULL, NULL )) return NULL;
status = wine_nt_to_unix_file_name( &nt_name, &unix_name, FILE_OPEN_IF );
for (;;)
{
if (!(buffer = HeapAlloc( GetProcessHeap(), 0, size )))
{
RtlFreeUnicodeString( &nt_name );
return NULL;
}
status = wine_nt_to_unix_file_name( &nt_name, buffer, &size, FILE_OPEN_IF );
if (status != STATUS_BUFFER_TOO_SMALL) break;
HeapFree( GetProcessHeap(), 0, buffer );
}
RtlFreeUnicodeString( &nt_name );
if (status && status != STATUS_NO_SUCH_FILE)
{
HeapFree( GetProcessHeap(), 0, buffer );
SetLastError( RtlNtStatusToDosError( status ) );
return NULL;
}
return unix_name.Buffer;
return buffer;
}

View File

@ -110,10 +110,10 @@ NTSTATUS WINAPI DECLSPEC_HOTPATCH NtQueryDirectoryFile( HANDLE handle, HANDLE ev
* element doesn't have to exist; in that case STATUS_NO_SUCH_FILE is
* returned, but the unix name is still filled in properly.
*/
NTSTATUS CDECL wine_nt_to_unix_file_name( const UNICODE_STRING *nameW, ANSI_STRING *unix_name_ret,
NTSTATUS CDECL wine_nt_to_unix_file_name( const UNICODE_STRING *nameW, char *nameA, SIZE_T *size,
UINT disposition )
{
return unix_funcs->nt_to_unix_file_name( nameW, unix_name_ret, disposition );
return unix_funcs->nt_to_unix_file_name( nameW, nameA, size, disposition );
}

View File

@ -1604,5 +1604,5 @@
@ cdecl __wine_get_unix_codepage()
# Filesystem
@ cdecl wine_nt_to_unix_file_name(ptr ptr long)
@ cdecl wine_nt_to_unix_file_name(ptr ptr ptr long)
@ cdecl wine_unix_to_nt_file_name(ptr ptr)

View File

@ -3427,12 +3427,19 @@ NTSTATUS nt_to_unix_file_name( const UNICODE_STRING *nameW, char **unix_name_ret
* element doesn't have to exist; in that case STATUS_NO_SUCH_FILE is
* returned, but the unix name is still filled in properly.
*/
NTSTATUS CDECL wine_nt_to_unix_file_name( const UNICODE_STRING *nameW, ANSI_STRING *unix_name_ret,
NTSTATUS CDECL wine_nt_to_unix_file_name( const UNICODE_STRING *nameW, char *nameA, SIZE_T *size,
UINT disposition )
{
char *buffer = NULL;
NTSTATUS status = nt_to_unix_file_name( nameW, &buffer, disposition );
if (buffer) RtlInitAnsiString( unix_name_ret, buffer );
if (buffer)
{
if (*size > strlen(buffer)) strcpy( nameA, buffer );
else status = STATUS_BUFFER_TOO_SMALL;
*size = strlen(buffer) + 1;
RtlFreeHeap( GetProcessHeap(), 0, buffer );
}
return status;
}

View File

@ -332,7 +332,7 @@ struct unix_funcs
void (CDECL *server_init_process_done)( void *relay );
/* file functions */
NTSTATUS (CDECL *nt_to_unix_file_name)( const UNICODE_STRING *nameW, ANSI_STRING *unix_name_ret,
NTSTATUS (CDECL *nt_to_unix_file_name)( const UNICODE_STRING *nameW, char *nameA, SIZE_T *size,
UINT disposition );
NTSTATUS (CDECL *unix_to_nt_file_name)( const ANSI_STRING *name, UNICODE_STRING *nt );
void (CDECL *set_show_dot_files)( BOOL enable );

View File

@ -3371,7 +3371,7 @@ NTSYSAPI void WINAPI TpWaitForWork(TP_WORK *,BOOL);
/* Wine internal functions */
NTSYSAPI NTSTATUS CDECL wine_nt_to_unix_file_name( const UNICODE_STRING *nameW, ANSI_STRING *unix_name_ret,
NTSYSAPI NTSTATUS CDECL wine_nt_to_unix_file_name( const UNICODE_STRING *nameW, char *nameA, SIZE_T *size,
UINT disposition );
NTSYSAPI NTSTATUS CDECL wine_unix_to_nt_file_name( const ANSI_STRING *name, UNICODE_STRING *nt );