Commit 285830f5 authored by Alexandre Julliard's avatar Alexandre Julliard

ntdll: Add a helper to initialize a UNICODE_STRING on the Unix side.

parent 6d565910
......@@ -168,9 +168,7 @@ static NTSTATUS open_nls_data_file( ULONG type, ULONG id, HANDLE *file )
wcscpy( buffer, type == NLS_SECTION_SORTKEYS ? sortdirW : systemdirW );
p = strrchr( path, '/' ) + 1;
ascii_to_unicode( buffer + wcslen(buffer), p, strlen(p) + 1 );
valueW.Buffer = buffer;
valueW.Length = wcslen( buffer ) * sizeof(WCHAR);
valueW.MaximumLength = sizeof( buffer );
init_unicode_string( &valueW, buffer );
InitializeObjectAttributes( &attr, &valueW, 0, 0, NULL );
status = open_unix_file( file, path, GENERIC_READ, &attr, 0, FILE_SHARE_READ,
......@@ -1645,9 +1643,7 @@ NTSTATUS WINAPI NtGetNlsSectionPtr( ULONG type, ULONG id, void *unknown, void **
if ((status = get_nls_section_name( type, id, name ))) return status;
nameW.Buffer = name;
nameW.Length = wcslen(name) * sizeof(WCHAR);
nameW.MaximumLength = sizeof(name);
init_unicode_string( &nameW, name );
InitializeObjectAttributes( &attr, &nameW, 0, 0, NULL );
if ((status = NtOpenSection( &handle, SECTION_MAP_READ, &attr )))
{
......
......@@ -1974,8 +1974,7 @@ static NTSTATUS get_mountmgr_fs_info( HANDLE handle, int fd, struct mountmgr_uni
else
drive->letter = 'a' + letter;
string.Buffer = (WCHAR *)MOUNTMGR_DEVICE_NAME;
string.Length = sizeof(MOUNTMGR_DEVICE_NAME) - sizeof(WCHAR);
init_unicode_string( &string, MOUNTMGR_DEVICE_NAME );
InitializeObjectAttributes( &attr, &string, 0, NULL, NULL );
status = NtOpenFile( &mountmgr, GENERIC_READ | SYNCHRONIZE, &attr, &io,
FILE_SHARE_READ | FILE_SHARE_WRITE, FILE_SYNCHRONOUS_IO_NONALERT );
......@@ -2750,10 +2749,8 @@ static NTSTATUS open_hkcu_key( const char *path, HANDLE *key )
len += sprintf( buffer + len, "-%u", sid->SubAuthority[i] );
len += sprintf( buffer + len, "\\%s", path );
name.Buffer = bufferW;
name.Length = len * sizeof(WCHAR);
name.MaximumLength = name.Length + sizeof(WCHAR);
ascii_to_unicode( bufferW, buffer, len + 1 );
init_unicode_string( &name, bufferW );
InitializeObjectAttributes( &attr, &name, OBJ_CASE_INSENSITIVE, 0, NULL );
return NtCreateKey( key, KEY_ALL_ACCESS, &attr, 0, NULL, 0, NULL );
}
......@@ -2787,9 +2784,7 @@ void init_files(void)
DWORD dummy;
UNICODE_STRING nameW;
nameW.MaximumLength = sizeof(showdotfilesW);
nameW.Length = nameW.MaximumLength - sizeof(WCHAR);
nameW.Buffer = showdotfilesW;
init_unicode_string( &nameW, showdotfilesW );
if (!NtQueryValueKey( key, &nameW, KeyValuePartialInformation, tmp, sizeof(tmp), &dummy ))
{
WCHAR *str = (WCHAR *)((KEY_VALUE_PARTIAL_INFORMATION *)tmp)->Data;
......
......@@ -1618,9 +1618,7 @@ static void load_ntdll(void)
void *module;
char *name = build_path( dll_dir, "ntdll.dll.so" );
str.Buffer = path;
str.Length = sizeof(path) - sizeof(WCHAR);
str.MaximumLength = sizeof(path);
init_unicode_string( &str, path );
InitializeObjectAttributes( &attr, &str, 0, 0, NULL );
name[strlen(name) - 3] = 0; /* remove .so */
status = open_builtin_file( name, &attr, &mapping, &module, &info, &st, FALSE );
......
......@@ -1809,9 +1809,7 @@ static void find_reg_tz_info(RTL_DYNAMIC_TIME_ZONE_INFORMATION *tzi, const char*
sprintf( buffer, "%u", year );
ascii_to_unicode( yearW, buffer, strlen(buffer) + 1 );
nameW.Buffer = (WCHAR *)Time_ZonesW;
nameW.Length = sizeof(Time_ZonesW) - sizeof(WCHAR);
init_unicode_string( &nameW, Time_ZonesW );
InitializeObjectAttributes( &attr, &nameW, 0, 0, NULL );
if (NtOpenKey( &key, KEY_READ, &attr )) return;
......
......@@ -482,4 +482,11 @@ static inline int ntdll_wcsnicmp( const WCHAR *str1, const WCHAR *str2, int n )
#define towupper(c) ntdll_towupper(c)
#define towlower(c) ntdll_towlower(c)
static inline void init_unicode_string( UNICODE_STRING *str, const WCHAR *data )
{
str->Length = wcslen(data) * sizeof(WCHAR);
str->MaximumLength = str->Length + sizeof(WCHAR);
str->Buffer = (WCHAR *)data;
}
#endif /* __NTDLL_UNIX_PRIVATE_H */
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment