ReactOS 0.4.15-dev-7906-g1b85a5f
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)
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
11static BOOL (WINAPI *pWow64DisableWow64FsRedirection)(PVOID *);
12static BOOL (WINAPI *pWow64RevertWow64FsRedirection)(PVOID);
14
16{
17 char filename[MAX_PATH], sysdir[MAX_PATH];
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}
#define ok(value,...)
Definition: atltest.h:57
#define malloc
Definition: debug_ros.c:4
#define NULL
Definition: types.h:112
#define CloseHandle
Definition: compat.h:739
#define OPEN_EXISTING
Definition: compat.h:775
#define ReadFile(a, b, c, d, e)
Definition: compat.h:742
#define GetProcAddress(x, y)
Definition: compat.h:753
#define INVALID_HANDLE_VALUE
Definition: compat.h:731
#define GENERIC_READ
Definition: compat.h:135
#define MAX_PATH
Definition: compat.h:34
#define FILE_SHARE_READ
Definition: compat.h:136
DWORD WINAPI GetFileSize(HANDLE hFile, LPDWORD lpFileSizeHigh)
Definition: fileinfo.c:331
HMODULE WINAPI DECLSPEC_HOTPATCH GetModuleHandleA(LPCSTR lpModuleName)
Definition: loader.c:812
UINT WINAPI GetSystemDirectoryA(OUT LPSTR lpBuffer, IN UINT uSize)
Definition: path.c:2283
unsigned long DWORD
Definition: ntddk_ex.h:95
const char * filename
Definition: ioapi.h:137
void SetupLocale(_In_ ULONG AnsiCode, _In_ ULONG OemCode, _In_ ULONG Unicode)
Definition: locale.c:58
static PVOID LoadCodePageData(_In_ ULONG Code)
Definition: locale.c:15
HANDLE hKernel32
Definition: locale.c:13
DWORD dwFileSize
Definition: more.c:40
#define _In_
Definition: ms_sal.h:308
_In_ HANDLE hFile
Definition: mswsock.h:90
unsigned int UINT
Definition: ndis.h:50
NTSYSAPI VOID NTAPI RtlInitNlsTables(_In_ PUSHORT AnsiTableBase, _In_ PUSHORT OemTableBase, _In_ PUSHORT CaseTableBase, _Out_ PNLSTABLEINFO NlsTable)
NTSYSAPI VOID NTAPI RtlResetRtlTranslations(_In_ PNLSTABLEINFO NlsTable)
#define BOOL
Definition: nt_native.h:43
STRSAFEAPI StringCbPrintfA(STRSAFE_LPSTR pszDest, size_t cbDest, STRSAFE_LPCSTR pszFormat,...)
Definition: strsafe.h:547
void * PVOID
Definition: typedefs.h:50
uint32_t ULONG
Definition: typedefs.h:59
_In_ UCHAR _In_ UCHAR _In_ ULONG Code
Definition: wdfdevice.h:1701
DWORD WINAPI GetLastError(void)
Definition: except.c:1042
#define CreateFile
Definition: winbase.h:3749
#define WINAPI
Definition: msvc.h:6