ReactOS  0.4.15-dev-3440-g915569a
locale.c
Go to the documentation of this file.
1 /*
2  * PROJECT: ReactOS API tests
3  * LICENSE: GPL-2.0-or-later (https://spdx.org/licenses/GPL-2.0-or-later.html)
4  * PURPOSE: RTL locale support
5  * COPYRIGHT: Copyright 2016 Mark Jansen <mark.jansen@reactos.org>
6  * Copyright 2021 Jérôme Gardou <jerome.gardou@reactos.org>
7  */
8 
9 #include "precomp.h"
10 
11 static BOOL (WINAPI *pWow64DisableWow64FsRedirection)(PVOID *);
12 static BOOL (WINAPI *pWow64RevertWow64FsRedirection)(PVOID);
14 
16 {
17  char filename[MAX_PATH], sysdir[MAX_PATH];
18  HANDLE hFile;
19  PVOID Data = NULL;
20  PVOID FsRedir;
21 
22  if (!hKernel32)
23  {
24  hKernel32 = GetModuleHandleA("kernel32.dll");
25 
26  pWow64DisableWow64FsRedirection = (void*)GetProcAddress(hKernel32, "Wow64DisableWow64FsRedirection");
27  pWow64RevertWow64FsRedirection = (void*)GetProcAddress(hKernel32, "Wow64RevertWow64FsRedirection");
28  }
29 
30  if (pWow64DisableWow64FsRedirection)
31  pWow64DisableWow64FsRedirection(&FsRedir);
32 
34 
35  if (Code != -1)
36  StringCbPrintfA(filename, sizeof(filename), "%s\\c_%lu.nls", sysdir, Code);
37  else
38  StringCbPrintfA(filename, sizeof(filename), "%s\\l_intl.nls", sysdir);
39 
41  ok(hFile != INVALID_HANDLE_VALUE, "Failed to open %s, error %u\n", filename, (UINT)GetLastError());
43  {
44  DWORD dwRead;
47  ReadFile(hFile, Data, dwFileSize, &dwRead, NULL);
49  }
50 
51  if (pWow64RevertWow64FsRedirection)
52  pWow64RevertWow64FsRedirection(FsRedir);
53 
54  return Data;
55 }
56 
57 /* https://www.microsoft.com/resources/msdn/goglobal/default.mspx */
59  _In_ ULONG AnsiCode,
60  _In_ ULONG OemCode,
61  _In_ ULONG Unicode)
62 {
63  NLSTABLEINFO NlsTable;
64  PVOID AnsiCodePageData;
65  PVOID OemCodePageData;
66  PVOID UnicodeCaseTableData;
67 
68  AnsiCodePageData = LoadCodePageData(AnsiCode);
69  OemCodePageData = LoadCodePageData(OemCode);
70  UnicodeCaseTableData = LoadCodePageData(Unicode);
71 
72  RtlInitNlsTables(AnsiCodePageData, OemCodePageData, UnicodeCaseTableData, &NlsTable);
73  RtlResetRtlTranslations(&NlsTable);
74  /*
75  * Do NOT free the buffers here, they are directly used!
76  * Yes, we leak the old buffers, but this is a test anyway...
77  */
78 }
NTSYSAPI VOID NTAPI RtlResetRtlTranslations(_In_ PNLSTABLEINFO NlsTable)
#define CloseHandle
Definition: compat.h:598
_Must_inspect_result_ _In_ WDFDEVICE _In_ PWDF_DEVICE_PROPERTY_DATA _In_ DEVPROPTYPE _In_ ULONG _In_opt_ PVOID Data
Definition: wdfdevice.h:4527
DWORD dwFileSize
Definition: more.c:40
UINT WINAPI GetSystemDirectoryA(OUT LPSTR lpBuffer, IN UINT uSize)
Definition: path.c:2282
#define INVALID_HANDLE_VALUE
Definition: compat.h:590
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1040
const char * filename
Definition: ioapi.h:135
#define FILE_SHARE_READ
Definition: compat.h:136
HANDLE hKernel32
Definition: locale.c:13
#define _In_
Definition: ms_sal.h:308
static PVOID LoadCodePageData(_In_ ULONG Code)
Definition: locale.c:15
void * PVOID
Definition: retypes.h:9
#define OPEN_EXISTING
Definition: compat.h:634
NTSYSAPI VOID NTAPI RtlInitNlsTables(_In_ PUSHORT AnsiTableBase, _In_ PUSHORT OemTableBase, _In_ PUSHORT CaseTableBase, _Out_ PNLSTABLEINFO NlsTable)
STRSAFEAPI StringCbPrintfA(STRSAFE_LPSTR pszDest, size_t cbDest, STRSAFE_LPCSTR pszFormat,...)
Definition: strsafe.h:547
#define MAX_PATH
Definition: compat.h:34
#define WINAPI
Definition: msvc.h:6
unsigned long DWORD
Definition: ntddk_ex.h:95
DWORD WINAPI GetFileSize(HANDLE hFile, LPDWORD lpFileSizeHigh)
Definition: fileinfo.c:331
_In_ UCHAR _In_ UCHAR _In_ ULONG Code
Definition: wdfdevice.h:1697
HMODULE WINAPI DECLSPEC_HOTPATCH GetModuleHandleA(LPCSTR lpModuleName)
Definition: loader.c:812
#define GENERIC_READ
Definition: compat.h:135
_In_ HANDLE hFile
Definition: mswsock.h:90
IN OUT PVCB OUT PDIRENT OUT PBCB IN BOOLEAN CreateFile
Definition: fatprocs.h:913
#define ok(value,...)
Definition: atltest.h:57
#define ReadFile(a, b, c, d, e)
Definition: compat.h:601
unsigned int UINT
Definition: ndis.h:50
#define NULL
Definition: types.h:112
void SetupLocale(_In_ ULONG AnsiCode, _In_ ULONG OemCode, _In_ ULONG Unicode)
Definition: locale.c:58
unsigned int ULONG
Definition: retypes.h:1
#define GetProcAddress(x, y)
Definition: compat.h:612
#define malloc
Definition: debug_ros.c:4
static const WCHAR BOOL
Definition: locale.c:95