ReactOS  0.4.15-dev-5109-g2469ce2
nls.c File Reference
#include <k32.h>
#include <debug.h>
Include dependency graph for nls.c:

Go to the source code of this file.

Macros

#define NDEBUG
 

Functions

GetNlsSectionName

Construct a name of NLS section.

Parameters
CodePageCode page number.
BaseInteger base used for converting to string. Usually set to 10.
UnknownAs the name suggests the meaning of this parameter is unknown. The native version of Kernel32 passes it as the third parameter to NlsConvertIntegerToString function, which is used for the actual conversion of the code page number.
BaseNameBase name of the section. (ex. "\\Nls\\NlsSectionCP")
ResultBuffer that will hold the constructed name.
ResultSizeSize of the buffer for the result.
Returns
TRUE if the buffer was large enough and was filled with the requested information, FALSE otherwise.

@implemented

BOOL WINAPI GetNlsSectionName (UINT CodePage, UINT Base, ULONG Unknown, LPSTR BaseName, LPSTR Result, ULONG ResultSize)
 
GetCPFileNameFromRegistry

Get file name of code page definition file.

Parameters
CodePageCode page number to get file name of.
FileNameBuffer that is filled with file name of successful return. Can be set to NULL.
FileNameSizeSize of the buffer to hold file name in WCHARs.
Returns
TRUE if the file name was retrieved, FALSE otherwise.

@implemented

BOOL WINAPI GetCPFileNameFromRegistry (UINT CodePage, LPWSTR FileName, ULONG FileNameSize)
 
IsDBCSLeadByteEx

Determine if passed byte is lead byte in current ANSI code page.

@implemented

NTSTATUS CreateNlsDirectorySecurity (_Out_ PSECURITY_DESCRIPTOR *NlsSecurityDescriptor)
 Creates a security descriptor for the NLS object directory name. More...
 
NTSTATUS WINAPI CreateNlsSecurityDescriptor (_Out_ PSECURITY_DESCRIPTOR *SecurityDescriptor, _In_ SIZE_T DescriptorSize, _In_ ULONG AccessMask)
 Creates a security descriptor for each NLS section name. More...
 
BOOL WINAPI IsDBCSLeadByteEx (UINT CodePage, BYTE TestByte)
 
BOOL WINAPI IsDBCSLeadByte (BYTE TestByte)
 
BOOL WINAPI IsValidUILanguage (LANGID langid)
 
VOID WINAPI NlsConvertIntegerToString (ULONG Value, ULONG Base, ULONG strsize, LPWSTR str, ULONG strsize2)
 
UINT WINAPI SetCPGlobal (UINT CodePage)
 
BOOL WINAPI ValidateLCType (int a1, unsigned int a2, int a3, int a4)
 
BOOL WINAPI NlsResetProcessLocale (VOID)
 
VOID WINAPI GetDefaultSortkeySize (LPVOID lpUnknown)
 
VOID WINAPI GetLinguistLangSize (LPVOID lpUnknown)
 
BOOL WINAPI ValidateLocale (IN ULONG LocaleId)
 
ULONG WINAPI NlsGetCacheUpdateCount (VOID)
 
BOOL WINAPI IsNLSDefinedString (IN NLS_FUNCTION Function, IN DWORD dwFlags, IN LPNLSVERSIONINFO lpVersionInformation, IN LPCWSTR lpString, IN INT cchStr)
 
BOOL WINAPI GetNLSVersion (IN NLS_FUNCTION Function, IN LCID Locale, IN OUT LPNLSVERSIONINFO lpVersionInformation)
 
BOOL WINAPI GetNLSVersionEx (IN NLS_FUNCTION function, IN LPCWSTR lpLocaleName, IN OUT LPNLSVERSIONINFOEX lpVersionInformation)
 
NlsInit

Internal NLS related stuff initialization.

BOOL FASTCALL NlsInit (VOID)
 
NlsUninit

Internal NLS related stuff uninitialization.

VOID FASTCALL NlsUninit (VOID)
 
IntGetLoadedCodePageEntry

Internal function to get structure containing a code page information of code page that is already loaded.

Parameters
CodePageNumber of the code page. Special values like CP_OEMCP, CP_ACP or CP_UTF8 aren't allowed.
Returns
Code page entry or NULL if the specified code page hasn't been loaded yet.
PCODEPAGE_ENTRY FASTCALL IntGetLoadedCodePageEntry (UINT CodePage)
 
IntGetCodePageEntry

Internal function to get structure containing a code page information.

Parameters
CodePageNumber of the code page. Special values like CP_OEMCP, CP_ACP or CP_THREAD_ACP are allowed, but CP_UTF[7/8] isn't.
Returns
Code page entry.
PCODEPAGE_ENTRY FASTCALL IntGetCodePageEntry (UINT CodePage)
 
IntMultiByteToWideCharUTF8

Internal version of MultiByteToWideChar for UTF8.

Note
We use Win10's behaviour due to security reason.
See also
MultiByteToWideChar
static INT WINAPI IntMultiByteToWideCharUTF8 (DWORD Flags, LPCSTR MultiByteString, INT MultiByteCount, LPWSTR WideCharString, INT WideCharCount)
 
IntMultiByteToWideCharCP

Internal version of MultiByteToWideChar for code page tables.

See also
MultiByteToWideChar
Todo:
Handle MB_PRECOMPOSED, MB_COMPOSITE, MB_USEGLYPHCHARS and DBCS codepages.
static INT WINAPI IntMultiByteToWideCharCP (UINT CodePage, DWORD Flags, LPCSTR MultiByteString, INT MultiByteCount, LPWSTR WideCharString, INT WideCharCount)
 
IntMultiByteToWideCharSYMBOL

Internal version of MultiByteToWideChar for SYMBOL.

See also
MultiByteToWideChar
static INT WINAPI IntMultiByteToWideCharSYMBOL (DWORD Flags, LPCSTR MultiByteString, INT MultiByteCount, LPWSTR WideCharString, INT WideCharCount)
 
IntWideCharToMultiByteSYMBOL

Internal version of WideCharToMultiByte for SYMBOL.

See also
WideCharToMultiByte
static INT WINAPI IntWideCharToMultiByteSYMBOL (DWORD Flags, LPCWSTR WideCharString, INT WideCharCount, LPSTR MultiByteString, INT MultiByteCount)
 
IntWideCharToMultiByteUTF8

Internal version of WideCharToMultiByte for UTF8.

See also
WideCharToMultiByte
static INT WINAPI IntWideCharToMultiByteUTF8 (UINT CodePage, DWORD Flags, LPCWSTR WideCharString, INT WideCharCount, LPSTR MultiByteString, INT MultiByteCount, LPCSTR DefaultChar, LPBOOL UsedDefaultChar)
 
IsValidSBCSMapping

Checks if ch (single-byte character) is a valid mapping for wch

See also
IntWideCharToMultiByteCP
static BOOL IntIsValidSBCSMapping (PCPTABLEINFO CodePageTable, DWORD Flags, WCHAR wch, UCHAR ch)
 
IsValidDBCSMapping

Checks if ch (double-byte character) is a valid mapping for wch

See also
IntWideCharToMultiByteCP
static BOOL IntIsValidDBCSMapping (PCPTABLEINFO CodePageTable, DWORD Flags, WCHAR wch, USHORT ch)
 
IntWideCharToMultiByteCP

Internal version of WideCharToMultiByte for code page tables.

See also
WideCharToMultiByte
Todo:
Handle WC_COMPOSITECHECK
static INT WINAPI IntWideCharToMultiByteCP (UINT CodePage, DWORD Flags, LPCWSTR WideCharString, INT WideCharCount, LPSTR MultiByteString, INT MultiByteCount, LPCSTR DefaultChar, LPBOOL UsedDefaultChar)
 
IntIsLeadByte

Internal function to detect if byte is lead byte in specific character table.

static BOOL WINAPI IntIsLeadByte (PCPTABLEINFO TableInfo, BYTE Byte)
 
IsValidCodePage

Detect if specified code page is valid and present in the system.

Parameters
CodePageCode page number to query.
Returns
TRUE if code page is present.
BOOL WINAPI IsValidCodePage (UINT CodePage)
 
static BOOL utf7_write_w (WCHAR *dst, int dstlen, int *index, WCHAR character)
 
static INT Utf7ToWideChar (const char *src, int srclen, WCHAR *dst, int dstlen)
 
MultiByteToWideChar

Convert a multi-byte string to wide-charater equivalent.

Parameters
CodePageCode page to be used to perform the conversion. It can be also one of the special values (CP_ACP for ANSI code page, CP_MACCP for Macintosh code page, CP_OEMCP for OEM code page, CP_THREAD_ACP for thread active code page, CP_UTF7 or CP_UTF8).
FlagsAdditional conversion flags (MB_PRECOMPOSED, MB_COMPOSITE, MB_ERR_INVALID_CHARS, MB_USEGLYPHCHARS).
MultiByteStringInput buffer.
MultiByteCountSize of MultiByteString, or -1 if MultiByteString is NULL terminated.
WideCharStringOutput buffer.
WideCharCountSize in WCHARs of WideCharString, or 0 if the caller just wants to know how large WideCharString should be for a successful conversion.
Returns
Zero on error, otherwise the number of WCHARs written in the WideCharString buffer.

@implemented

INT WINAPI MultiByteToWideChar (UINT CodePage, DWORD Flags, LPCSTR MultiByteString, INT MultiByteCount, LPWSTR WideCharString, INT WideCharCount)
 
static BOOL utf7_can_directly_encode (WCHAR codepoint)
 
static BOOL utf7_write_c (char *dst, int dstlen, int *index, char character)
 
static INT WideCharToUtf7 (const WCHAR *src, int srclen, char *dst, int dstlen)
 
UINT GetLocalisedText (IN UINT uID, IN LPWSTR lpszDest, IN UINT cchDest, IN LANGID lang)
 
BOOL WINAPI GetCPInfo (UINT CodePage, LPCPINFO CodePageInfo)
 
BOOL WINAPI GetCPInfoExW (UINT CodePage, DWORD dwFlags, LPCPINFOEXW lpCPInfoEx)
 
BOOL WINAPI GetCPInfoExA (UINT CodePage, DWORD dwFlags, LPCPINFOEXA lpCPInfoEx)
 
WideCharToMultiByte

Convert a wide-charater string to closest multi-byte equivalent.

Parameters
CodePageCode page to be used to perform the conversion. It can be also one of the special values (CP_ACP for ANSI code page, CP_MACCP for Macintosh code page, CP_OEMCP for OEM code page, CP_THREAD_ACP for thread active code page, CP_UTF7 or CP_UTF8).
FlagsAdditional conversion flags (WC_NO_BEST_FIT_CHARS, WC_COMPOSITECHECK, WC_DISCARDNS, WC_SEPCHARS, WC_DEFAULTCHAR).
WideCharStringPoints to the wide-character string to be converted.
WideCharCountSize in WCHARs of WideCharStr, or 0 if the caller just wants to know how large WideCharString should be for a successful conversion.
MultiByteStringPoints to the buffer to receive the translated string.
MultiByteCountSpecifies the size in bytes of the buffer pointed to by the MultiByteString parameter. If this value is zero, the function returns the number of bytes required for the buffer.
DefaultCharPoints to the character used if a wide character cannot be represented in the specified code page. If this parameter is NULL, a system default value is used.
UsedDefaultCharPoints to a flag that indicates whether a default character was used. This parameter can be NULL.
Returns
Zero on error, otherwise the number of bytes written in the MultiByteString buffer. Or the number of bytes needed for the MultiByteString buffer if MultiByteCount is zero.

@implemented

INT WINAPI WideCharToMultiByte (UINT CodePage, DWORD Flags, LPCWSTR WideCharString, INT WideCharCount, LPSTR MultiByteString, INT MultiByteCount, LPCSTR DefaultChar, LPBOOL UsedDefaultChar)
 
GetACP

Get active ANSI code page number.

@implemented

UINT WINAPI GetACP (VOID)
 
GetOEMCP

Get active OEM code page number.

@implemented

UINT WINAPI GetOEMCP (VOID)
 

Variables

static const char UTF8Length [128]
 
static const unsigned char UTF8Mask [6] = {0x7f, 0x1f, 0x0f, 0x07, 0x03, 0x01}
 
static const unsigned long UTF8LBound []
 
static LIST_ENTRY CodePageListHead
 
static CODEPAGE_ENTRY AnsiCodePage
 
static CODEPAGE_ENTRY OemCodePage
 
static RTL_CRITICAL_SECTION CodePageListLock
 

Macro Definition Documentation

◆ NDEBUG

#define NDEBUG

Definition at line 19 of file nls.c.

Function Documentation

◆ CreateNlsDirectorySecurity()

NTSTATUS CreateNlsDirectorySecurity ( _Out_ PSECURITY_DESCRIPTOR NlsSecurityDescriptor)

Creates a security descriptor for the NLS object directory name.

Parameters
[out]SecurityDescriptorA pointer to an allocated and created security descriptor that is given to the caller.
Returns
STATUS_SUCCESS is returned if the function has successfully created a security descriptor for a NLS section name. Otherwise a NTSTATUS failure code is returned.
Remarks
Everyone (aka World SID) is given read access to the NLS directory whereas admins are given full power.

Definition at line 2294 of file nls.c.

2295 {
2296  NTSTATUS Status;
2297  PACL Dacl;
2298  PSID WorldSid = NULL, AdminsSid = NULL;
2299  ULONG DaclSize, RelSdSize = 0;
2300  PSECURITY_DESCRIPTOR RelativeSd = NULL;
2301  SECURITY_DESCRIPTOR AbsoluteSd;
2304 
2305  /* Create the World SID */
2307  1,
2309  0, 0, 0, 0, 0, 0, 0,
2310  &WorldSid);
2311  if (!NT_SUCCESS(Status))
2312  {
2313  DPRINT1("CreateNlsDirectorySecurity(): Failed to create world SID (Status 0x%08x)\n", Status);
2314  return Status;
2315  }
2316 
2317  /* Create the admins SID */
2319  2,
2322  0, 0, 0, 0, 0, 0,
2323  &AdminsSid);
2324  if (!NT_SUCCESS(Status))
2325  {
2326  DPRINT1("CreateNlsDirectorySecurity(): Failed to create admins SID (Status 0x%08x)\n", Status);
2327  goto Quit;
2328  }
2329 
2330  /* Build up the size of our DACL, including the World and admins SIDs */
2331  DaclSize = sizeof(ACL) +
2333  sizeof(ACCESS_ALLOWED_ACE) + RtlLengthSid(AdminsSid);
2334 
2335  /* Allocate memory for our DACL */
2336  Dacl = RtlAllocateHeap(RtlGetProcessHeap(), HEAP_ZERO_MEMORY, DaclSize);
2337  if (Dacl == NULL)
2338  {
2339  DPRINT1("CreateNlsDirectorySecurity(): Could not allocate memory for DACL, not enough memory!\n");
2341  goto Quit;
2342  }
2343 
2344  /* Create the DACL */
2346  if (!NT_SUCCESS(Status))
2347  {
2348  DPRINT1("CreateNlsDirectorySecurity(): Failed to create the DACL (Status 0x%08x)\n", Status);
2349  goto Quit;
2350  }
2351 
2352  /* Give everyone basic directory access */
2354  ACL_REVISION,
2356  WorldSid);
2357  if (!NT_SUCCESS(Status))
2358  {
2359  DPRINT1("CreateNlsDirectorySecurity(): Failed to insert allowed access ACE to DACL for World SID (Status 0x%08x)\n", Status);
2360  goto Quit;
2361  }
2362 
2363  /* Give admins full power */
2365  ACL_REVISION,
2367  AdminsSid);
2368  if (!NT_SUCCESS(Status))
2369  {
2370  DPRINT1("CreateNlsDirectorySecurity(): Failed to insert allowed access ACE to DACL for admins SID (Status 0x%08x)\n", Status);
2371  goto Quit;
2372  }
2373 
2374  /* Initialize the security descriptor */
2375  Status = RtlCreateSecurityDescriptor(&AbsoluteSd,
2377  if (!NT_SUCCESS(Status))
2378  {
2379  DPRINT1("CreateNlsDirectorySecurity(): Failed to initialize the security descriptor (Status 0x%08x)\n", Status);
2380  goto Quit;
2381  }
2382 
2383  /* Set the DACL to descriptor */
2384  Status = RtlSetDaclSecurityDescriptor(&AbsoluteSd,
2385  TRUE,
2386  Dacl,
2387  FALSE);
2388  if (!NT_SUCCESS(Status))
2389  {
2390  DPRINT1("CreateNlsDirectorySecurity(): Failed to insert DACL into the descriptor (Status 0x%08x)\n", Status);
2391  goto Quit;
2392  }
2393 
2394  /* Determine how much size is needed to convert the absolute SD into self-relative one */
2395  Status = RtlAbsoluteToSelfRelativeSD(&AbsoluteSd,
2396  NULL,
2397  &RelSdSize);
2399  {
2400  DPRINT1("CreateNlsDirectorySecurity(): Unexpected status code, must be STATUS_BUFFER_TOO_SMALL (Status 0x%08x)\n", Status);
2401  goto Quit;
2402  }
2403 
2404  /* Allocate buffer for relative SD */
2405  RelativeSd = RtlAllocateHeap(RtlGetProcessHeap(), HEAP_ZERO_MEMORY, RelSdSize);
2406  if (RelativeSd == NULL)
2407  {
2408  DPRINT1("CreateNlsDirectorySecurity(): Could not allocate memory for relative SD, not enough memory!\n");
2410  goto Quit;
2411  }
2412 
2413  /* Convert it now */
2414  Status = RtlAbsoluteToSelfRelativeSD(&AbsoluteSd,
2415  RelativeSd,
2416  &RelSdSize);
2417  if (!NT_SUCCESS(Status))
2418  {
2419  DPRINT1("CreateNlsDirectorySecurity(): Failed to convert absolute SD to self-relative format (Status 0x%08x)\n", Status);
2420  goto Quit;
2421  }
2422 
2423  /* Give the security descriptor to the caller */
2424  *NlsSecurityDescriptor = RelativeSd;
2425 
2426 Quit:
2427  if (WorldSid != NULL)
2428  {
2429  RtlFreeHeap(RtlGetProcessHeap(), 0, WorldSid);
2430  }
2431 
2432  if (AdminsSid != NULL)
2433  {
2434  RtlFreeHeap(RtlGetProcessHeap(), 0, AdminsSid);
2435  }
2436 
2437  if (Dacl != NULL)
2438  {
2439  RtlFreeHeap(RtlGetProcessHeap(), 0, Dacl);
2440  }
2441 
2442  if (!NT_SUCCESS(Status))
2443  {
2444  if (RelativeSd != NULL)
2445  {
2446  RtlFreeHeap(RtlGetProcessHeap(), 0, RelativeSd);
2447  }
2448  }
2449 
2450  return Status;
2451 }
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
#define TRUE
Definition: types.h:120
#define DIRECTORY_CREATE_OBJECT
Definition: nt_native.h:1256
LONG NTSTATUS
Definition: precomp.h:26
static SID_IDENTIFIER_AUTHORITY WorldAuthority
Definition: security.c:14
BOOLEAN NTAPI RtlFreeHeap(IN PVOID HeapHandle, IN ULONG Flags, IN PVOID HeapBase)
Definition: heap.c:606
struct _ACCESS_ALLOWED_ACE ACCESS_ALLOWED_ACE
NTSYSAPI NTSTATUS NTAPI RtlCreateSecurityDescriptor(_Out_ PSECURITY_DESCRIPTOR SecurityDescriptor, _In_ ULONG Revision)
NTSYSAPI NTSTATUS WINAPI RtlAddAccessAllowedAce(PACL, DWORD, DWORD, PSID)
NTSYSAPI NTSTATUS WINAPI RtlSetDaclSecurityDescriptor(PSECURITY_DESCRIPTOR, BOOLEAN, PACL, BOOLEAN)
NTSYSAPI NTSTATUS NTAPI RtlAllocateAndInitializeSid(IN PSID_IDENTIFIER_AUTHORITY IdentifierAuthority, IN UCHAR SubAuthorityCount, IN ULONG SubAuthority0, IN ULONG SubAuthority1, IN ULONG SubAuthority2, IN ULONG SubAuthority3, IN ULONG SubAuthority4, IN ULONG SubAuthority5, IN ULONG SubAuthority6, IN ULONG SubAuthority7, OUT PSID *Sid)
Definition: sid.c:290
#define STATUS_BUFFER_TOO_SMALL
Definition: shellext.h:69
NTSYSAPI NTSTATUS NTAPI RtlCreateAcl(PACL Acl, ULONG AclSize, ULONG AclRevision)
#define SECURITY_DESCRIPTOR_REVISION
Definition: setypes.h:58
#define FALSE
Definition: types.h:117
NTSYSAPI NTSTATUS NTAPI RtlAbsoluteToSelfRelativeSD(IN PSECURITY_DESCRIPTOR AbsoluteSecurityDescriptor, IN OUT PSECURITY_DESCRIPTOR SelfRelativeSecurityDescriptor, IN PULONG BufferLength)
Definition: sd.c:626
struct _ACL ACL
NTSYSAPI ULONG NTAPI RtlLengthSid(IN PSID Sid)
Definition: sid.c:150
#define SECURITY_NT_AUTHORITY
Definition: setypes.h:554
PVOID NTAPI RtlAllocateHeap(IN PVOID HeapHandle, IN ULONG Flags, IN SIZE_T Size)
Definition: heap.c:588
#define DIRECTORY_TRAVERSE
Definition: nt_native.h:1255
Status
Definition: gdiplustypes.h:24
#define SECURITY_BUILTIN_DOMAIN_RID
Definition: setypes.h:581
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define SECURITY_WORLD_SID_AUTHORITY
Definition: setypes.h:527
#define SECURITY_WORLD_RID
Definition: setypes.h:541
_Out_writes_bytes_to_opt_ AbsoluteSecurityDescriptorSize PSECURITY_DESCRIPTOR _Inout_ PULONG _Out_writes_bytes_to_opt_ DaclSize PACL Dacl
Definition: rtlfuncs.h:1579
static SID_IDENTIFIER_AUTHORITY NtAuthority
Definition: security.c:40
PSID WorldSid
Definition: globals.c:15
#define DIRECTORY_ALL_ACCESS
Definition: nt_native.h:1259
#define NULL
Definition: types.h:112
#define HEAP_ZERO_MEMORY
Definition: compat.h:134
#define DPRINT1
Definition: precomp.h:8
_Out_writes_bytes_to_opt_ AbsoluteSecurityDescriptorSize PSECURITY_DESCRIPTOR _Inout_ PULONG _Out_writes_bytes_to_opt_ DaclSize PACL _Inout_ PULONG DaclSize
Definition: rtlfuncs.h:1579
#define ACL_REVISION
Definition: setypes.h:39
unsigned int ULONG
Definition: retypes.h:1
#define DOMAIN_ALIAS_RID_ADMINS
Definition: setypes.h:652

Referenced by NlsInit().

◆ CreateNlsSecurityDescriptor()

NTSTATUS WINAPI CreateNlsSecurityDescriptor ( _Out_ PSECURITY_DESCRIPTOR SecurityDescriptor,
_In_ SIZE_T  DescriptorSize,
_In_ ULONG  AccessMask 
)

Creates a security descriptor for each NLS section name.

Parameters
[in]AccessMaskAn access mask bit to supply to the function. This access mask grants everyone access specific to that bit mask.
[out]SecurityDescriptorA pointer to an allocated and created security descriptor that is given to the caller.
Returns
STATUS_SUCCESS is returned if the function has successfully created a security descriptor for a NLS section name. Otherwise a NTSTATUS failure code is returned.
Remarks
The implementation of CreateNlsSecurityDescriptor on Windows Server 2003 is slightly different compared to ours. The second parameter takes the size of a security descriptor, in bytes. This is implied that on Windows the caller is responsible to submit the exact size of the descriptor. On ReactOS we're going to do it different, let the function be responsible for security descriptor creation and its size. DescriptorSize will act like a dummy parameter for us in this case. Everyone (aka World SID) is given read access to each NLS section name.

Definition at line 2483 of file nls.c.

2484 {
2485  NTSTATUS Status;
2486  PACL Dacl;
2487  PSID WorldSid = NULL;
2488  ULONG DaclSize, RelSdSize = 0;
2489  PSECURITY_DESCRIPTOR RelativeSd = NULL;
2490  SECURITY_DESCRIPTOR AbsoluteSd;
2492 
2493  /* DescriptorSize is just a dummy parameter */
2494  UNREFERENCED_PARAMETER(DescriptorSize);
2495 
2496  /* Create the World SID */
2498  1,
2500  0, 0, 0, 0, 0, 0, 0,
2501  &WorldSid);
2502  if (!NT_SUCCESS(Status))
2503  {
2504  DPRINT1("CreateNlsSecurityDescriptor(): Failed to create world SID (Status 0x%08x)\n", Status);
2505  return Status;
2506  }
2507 
2508  /* Build up the size of our DACL, including the World SID */
2509  DaclSize = sizeof(ACL) +
2511 
2512  /* Allocate memory for our DACL */
2513  Dacl = RtlAllocateHeap(RtlGetProcessHeap(), HEAP_ZERO_MEMORY, DaclSize);
2514  if (Dacl == NULL)
2515  {
2516  DPRINT1("CreateNlsSecurityDescriptor(): Could not allocate memory for DACL, not enough memory!\n");
2518  goto Quit;
2519  }
2520 
2521  /* Create the DACL */
2523  if (!NT_SUCCESS(Status))
2524  {
2525  DPRINT1("CreateNlsSecurityDescriptor(): Failed to create the DACL (Status 0x%08x)\n", Status);
2526  goto Quit;
2527  }
2528 
2529  /* Add a ACE with allow access to the World SID */
2531  ACL_REVISION,
2532  AccessMask,
2533  WorldSid);
2534  if (!NT_SUCCESS(Status))
2535  {
2536  DPRINT1("CreateNlsSecurityDescriptor(): Failed to insert allowed access ACE to DACL for World SID (Status 0x%08x)\n", Status);
2537  goto Quit;
2538  }
2539 
2540  /* Initialize the security descriptor */
2541  Status = RtlCreateSecurityDescriptor(&AbsoluteSd,
2543  if (!NT_SUCCESS(Status))
2544  {
2545  DPRINT1("CreateNlsSecurityDescriptor(): Failed to insert allowed access ACE to DACL for World SID (Status 0x%08x)\n", Status);
2546  goto Quit;
2547  }
2548 
2549  /* Set the DACL to descriptor */
2550  Status = RtlSetDaclSecurityDescriptor(&AbsoluteSd,
2551  TRUE,
2552  Dacl,
2553  FALSE);
2554  if (!NT_SUCCESS(Status))
2555  {
2556  DPRINT1("CreateNlsSecurityDescriptor(): Failed to insert DACL into the descriptor (Status 0x%08x)\n", Status);
2557  goto Quit;
2558  }
2559 
2560  /* Determine how much size is needed to convert the absolute SD into self-relative one */
2561  Status = RtlAbsoluteToSelfRelativeSD(&AbsoluteSd,
2562  NULL,
2563  &RelSdSize);
2565  {
2566  DPRINT1("CreateNlsSecurityDescriptor(): Unexpected status code, must be STATUS_BUFFER_TOO_SMALL (Status 0x%08x)\n", Status);
2567  goto Quit;
2568  }
2569 
2570  /* Allocate buffer for relative SD */
2571  RelativeSd = RtlAllocateHeap(RtlGetProcessHeap(), HEAP_ZERO_MEMORY, RelSdSize);
2572  if (RelativeSd == NULL)
2573  {
2574  DPRINT1("CreateNlsSecurityDescriptor(): Could not allocate memory for relative SD, not enough memory!\n");
2576  goto Quit;
2577  }
2578 
2579  /* Convert it now */
2580  Status = RtlAbsoluteToSelfRelativeSD(&AbsoluteSd,
2581  RelativeSd,
2582  &RelSdSize);
2583  if (!NT_SUCCESS(Status))
2584  {
2585  DPRINT1("CreateNlsSecurityDescriptor(): Failed to convert absolute SD to self-relative format (Status 0x%08x)\n", Status);
2586  goto Quit;
2587  }
2588 
2589  /* Give the security descriptor to the caller */
2590  *SecurityDescriptor = RelativeSd;
2591 
2592 Quit:
2593  if (WorldSid != NULL)
2594  {
2595  RtlFreeHeap(RtlGetProcessHeap(), 0, WorldSid);
2596  }
2597 
2598  if (Dacl != NULL)
2599  {
2600  RtlFreeHeap(RtlGetProcessHeap(), 0, Dacl);
2601  }
2602 
2603  if (!NT_SUCCESS(Status))
2604  {
2605  if (RelativeSd != NULL)
2606  {
2607  RtlFreeHeap(RtlGetProcessHeap(), 0, RelativeSd);
2608  }
2609  }
2610 
2611  return Status;
2612 }
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
#define TRUE
Definition: types.h:120
#define UNREFERENCED_PARAMETER(P)
Definition: ntbasedef.h:317
_In_ USHORT _In_ ULONG _In_ PSOCKADDR _In_ PSOCKADDR _Reserved_ ULONG _In_opt_ PVOID _In_opt_ const WSK_CLIENT_CONNECTION_DISPATCH _In_opt_ PEPROCESS _In_opt_ PETHREAD _In_opt_ PSECURITY_DESCRIPTOR SecurityDescriptor
Definition: wsk.h:182
LONG NTSTATUS
Definition: precomp.h:26
static SID_IDENTIFIER_AUTHORITY WorldAuthority
Definition: security.c:14
BOOLEAN NTAPI RtlFreeHeap(IN PVOID HeapHandle, IN ULONG Flags, IN PVOID HeapBase)
Definition: heap.c:606
NTSYSAPI NTSTATUS NTAPI RtlCreateSecurityDescriptor(_Out_ PSECURITY_DESCRIPTOR SecurityDescriptor, _In_ ULONG Revision)
NTSYSAPI NTSTATUS WINAPI RtlAddAccessAllowedAce(PACL, DWORD, DWORD, PSID)
NTSYSAPI NTSTATUS WINAPI RtlSetDaclSecurityDescriptor(PSECURITY_DESCRIPTOR, BOOLEAN, PACL, BOOLEAN)
NTSYSAPI NTSTATUS NTAPI RtlAllocateAndInitializeSid(IN PSID_IDENTIFIER_AUTHORITY IdentifierAuthority, IN UCHAR SubAuthorityCount, IN ULONG SubAuthority0, IN ULONG SubAuthority1, IN ULONG SubAuthority2, IN ULONG SubAuthority3, IN ULONG SubAuthority4, IN ULONG SubAuthority5, IN ULONG SubAuthority6, IN ULONG SubAuthority7, OUT PSID *Sid)
Definition: sid.c:290
#define STATUS_BUFFER_TOO_SMALL
Definition: shellext.h:69
NTSYSAPI NTSTATUS NTAPI RtlCreateAcl(PACL Acl, ULONG AclSize, ULONG AclRevision)
#define SECURITY_DESCRIPTOR_REVISION
Definition: setypes.h:58
#define FALSE
Definition: types.h:117
NTSYSAPI NTSTATUS NTAPI RtlAbsoluteToSelfRelativeSD(IN PSECURITY_DESCRIPTOR AbsoluteSecurityDescriptor, IN OUT PSECURITY_DESCRIPTOR SelfRelativeSecurityDescriptor, IN PULONG BufferLength)
Definition: sd.c:626
struct _ACL ACL
NTSYSAPI ULONG NTAPI RtlLengthSid(IN PSID Sid)
Definition: sid.c:150
PVOID NTAPI RtlAllocateHeap(IN PVOID HeapHandle, IN ULONG Flags, IN SIZE_T Size)
Definition: heap.c:588
Status
Definition: gdiplustypes.h:24
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define SECURITY_WORLD_SID_AUTHORITY
Definition: setypes.h:527
_In_ ACCESS_MASK AccessMask
Definition: exfuncs.h:186
#define SECURITY_WORLD_RID
Definition: setypes.h:541
_Out_writes_bytes_to_opt_ AbsoluteSecurityDescriptorSize PSECURITY_DESCRIPTOR _Inout_ PULONG _Out_writes_bytes_to_opt_ DaclSize PACL Dacl
Definition: rtlfuncs.h:1579
PSID WorldSid
Definition: globals.c:15
#define NULL
Definition: types.h:112
#define HEAP_ZERO_MEMORY
Definition: compat.h:134
#define DPRINT1
Definition: precomp.h:8
_Out_writes_bytes_to_opt_ AbsoluteSecurityDescriptorSize PSECURITY_DESCRIPTOR _Inout_ PULONG _Out_writes_bytes_to_opt_ DaclSize PACL _Inout_ PULONG DaclSize
Definition: rtlfuncs.h:1579
#define ACL_REVISION
Definition: setypes.h:39
unsigned int ULONG
Definition: retypes.h:1

Referenced by IntGetCodePageEntry().

◆ GetACP()

◆ GetCPFileNameFromRegistry()

BOOL WINAPI GetCPFileNameFromRegistry ( UINT  CodePage,
LPWSTR  FileName,
ULONG  FileNameSize 
)

Definition at line 1439 of file nls.c.

1440 {
1441  WCHAR ValueNameBuffer[11];
1444  NTSTATUS Status;
1445  HANDLE KeyHandle;
1447  DWORD KvpiSize;
1448  BOOL bRetValue;
1449 
1450  bRetValue = FALSE;
1451 
1452  /* Convert the codepage number to string. */
1453  ValueName.Buffer = ValueNameBuffer;
1454  ValueName.MaximumLength = sizeof(ValueNameBuffer);
1455 
1456  if (!NT_SUCCESS(RtlIntegerToUnicodeString(CodePage, 10, &ValueName)))
1457  return bRetValue;
1458 
1459  /* Open the registry key containing file name mappings. */
1460  RtlInitUnicodeString(&KeyName, L"\\Registry\\Machine\\System\\"
1461  L"CurrentControlSet\\Control\\Nls\\CodePage");
1463  NULL, NULL);
1465  if (!NT_SUCCESS(Status))
1466  {
1467  return bRetValue;
1468  }
1469 
1470  /* Allocate buffer that will be used to query the value data. */
1471  KvpiSize = sizeof(KEY_VALUE_PARTIAL_INFORMATION) + (MAX_PATH * sizeof(WCHAR));
1472  Kvpi = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, KvpiSize);
1473  if (Kvpi == NULL)
1474  {
1475  NtClose(KeyHandle);
1476  return bRetValue;
1477  }
1478 
1479  /* Query the file name for our code page. */
1481  Kvpi, KvpiSize, &KvpiSize);
1482 
1483  NtClose(KeyHandle);
1484 
1485  /* Check if we succeded and the value is non-empty string. */
1486  if (NT_SUCCESS(Status) && Kvpi->Type == REG_SZ &&
1487  Kvpi->DataLength > sizeof(WCHAR))
1488  {
1489  bRetValue = TRUE;
1490  if (FileName != NULL)
1491  {
1492  lstrcpynW(FileName, (WCHAR*)Kvpi->Data,
1493  min(Kvpi->DataLength / sizeof(WCHAR), FileNameSize));
1494  }
1495  }
1496 
1497  /* free temporary buffer */
1498  HeapFree(GetProcessHeap(),0,Kvpi);
1499  return bRetValue;
1500 }
IN PUNICODE_STRING IN POBJECT_ATTRIBUTES ObjectAttributes
Definition: conport.c:35
#define OBJ_CASE_INSENSITIVE
Definition: winternl.h:228
_Must_inspect_result_ _Out_ PNDIS_STATUS _In_ NDIS_HANDLE _In_ ULONG _Out_ PNDIS_STRING _Out_ PNDIS_HANDLE KeyHandle
Definition: ndis.h:4711
#define KEY_READ
Definition: nt_native.h:1023
#define TRUE
Definition: types.h:120
LONG NTSTATUS
Definition: precomp.h:26
#define lstrcpynW
Definition: compat.h:597
#define L(x)
Definition: ntvdm.h:50
#define FALSE
Definition: types.h:117
unsigned int BOOL
Definition: ntddk_ex.h:94
_Must_inspect_result_ _In_ WDFDEVICE _In_ PCUNICODE_STRING KeyName
Definition: wdfdevice.h:2697
Status
Definition: gdiplustypes.h:24
NTSYSAPI NTSTATUS NTAPI RtlIntegerToUnicodeString(ULONG Value, ULONG Base, PUNICODE_STRING String)
NTSYSAPI NTSTATUS NTAPI NtQueryValueKey(IN HANDLE KeyHandle, IN PUNICODE_STRING ValueName, IN KEY_VALUE_INFORMATION_CLASS KeyValueInformationClass, IN PVOID KeyValueInformation, IN ULONG Length, IN PULONG ResultLength)
#define GetProcessHeap()
Definition: compat.h:595
PVOID WINAPI HeapAlloc(HANDLE, DWORD, SIZE_T)
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define MAX_PATH
Definition: compat.h:34
unsigned long DWORD
Definition: ntddk_ex.h:95
NTSTATUS NTAPI NtClose(IN HANDLE Handle)
Definition: obhandle.c:3402
_Must_inspect_result_ _In_ WDFKEY _In_ PCUNICODE_STRING ValueName
Definition: wdfregistry.h:240
struct _KEY_VALUE_PARTIAL_INFORMATION KEY_VALUE_PARTIAL_INFORMATION
#define min(a, b)
Definition: monoChain.cc:55
#define NULL
Definition: types.h:112
#define HEAP_ZERO_MEMORY
Definition: compat.h:134
NTSYSAPI NTSTATUS NTAPI NtOpenKey(OUT PHANDLE KeyHandle, IN ACCESS_MASK DesiredAccess, IN POBJECT_ATTRIBUTES ObjectAttributes)
Definition: ntapi.c:336
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
#define InitializeObjectAttributes(p, n, a, r, s)
Definition: reg.c:106
#define HeapFree(x, y, z)
Definition: compat.h:594
#define REG_SZ
Definition: layer.c:22

Referenced by IntGetCodePageEntry(), and IsValidCodePage().

◆ GetCPInfo()

BOOL WINAPI GetCPInfo ( UINT  CodePage,
LPCPINFO  CodePageInfo 
)

Definition at line 1950 of file nls.c.

1952 {
1953  PCODEPAGE_ENTRY CodePageEntry;
1954 
1955  if (!CodePageInfo)
1956  {
1958  return FALSE;
1959  }
1960 
1961  CodePageEntry = IntGetCodePageEntry(CodePage);
1962  if (CodePageEntry == NULL)
1963  {
1964  switch(CodePage)
1965  {
1966  case CP_UTF7:
1967  case CP_UTF8:
1968  CodePageInfo->DefaultChar[0] = 0x3f;
1969  CodePageInfo->DefaultChar[1] = 0;
1970  CodePageInfo->LeadByte[0] = CodePageInfo->LeadByte[1] = 0;
1971  CodePageInfo->MaxCharSize = (CodePage == CP_UTF7) ? 5 : 4;
1972  return TRUE;
1973  }
1974 
1975  DPRINT1("Invalid CP!: %lx\n", CodePage);
1977  return FALSE;
1978  }
1979 
1980  if (CodePageEntry->CodePageTable.DefaultChar & 0xff00)
1981  {
1982  CodePageInfo->DefaultChar[0] = (CodePageEntry->CodePageTable.DefaultChar & 0xff00) >> 8;
1983  CodePageInfo->DefaultChar[1] = CodePageEntry->CodePageTable.DefaultChar & 0x00ff;
1984  }
1985  else
1986  {
1987  CodePageInfo->DefaultChar[0] = CodePageEntry->CodePageTable.DefaultChar & 0xff;
1988  CodePageInfo->DefaultChar[1] = 0;
1989  }
1990 
1991  if ((CodePageInfo->MaxCharSize = CodePageEntry->CodePageTable.MaximumCharacterSize) == 2)
1992  memcpy(CodePageInfo->LeadByte, CodePageEntry->CodePageTable.LeadByte, sizeof(CodePageInfo->LeadByte));
1993  else
1994  CodePageInfo->LeadByte[0] = CodePageInfo->LeadByte[1] = 0;
1995 
1996  return TRUE;
1997 }
#define ERROR_INVALID_PARAMETER
Definition: compat.h:101
#define CP_UTF7
Definition: winnls.h:235
#define TRUE
Definition: types.h:120
UINT MaxCharSize
Definition: winnls.h:581
#define CP_UTF8
Definition: nls.h:20
#define FALSE
Definition: types.h:117
UCHAR LeadByte[MAXIMUM_LEADBYTES]
Definition: precomp.h:39
BYTE LeadByte[MAX_LEADBYTES]
Definition: winnls.h:583
USHORT MaximumCharacterSize
Definition: precomp.h:33
PCODEPAGE_ENTRY FASTCALL IntGetCodePageEntry(UINT CodePage)
Definition: nls.c:213
#define SetLastError(x)
Definition: compat.h:611
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
USHORT DefaultChar
Definition: precomp.h:34
Definition: kernel32.h:62
BYTE DefaultChar[MAX_DEFAULTCHAR]
Definition: winnls.h:582
#define NULL
Definition: types.h:112
#define DPRINT1
Definition: precomp.h:8
CPTABLEINFO CodePageTable
Definition: kernel32.h:68

Referenced by _Locale_codecvt_create(), _Locale_ctype_create(), _setmbcp_l(), GetCPInfoExW(), GetKerningPairsA(), Global_Chr(), make_csconv(), ME_GetTextLengthEx(), MSVCRT__create_locale(), test_GetCPInfo(), and test_mbcp().

◆ GetCPInfoExA()

BOOL WINAPI GetCPInfoExA ( UINT  CodePage,
DWORD  dwFlags,
LPCPINFOEXA  lpCPInfoEx 
)

Definition at line 2063 of file nls.c.

2066 {
2067  CPINFOEXW CPInfo;
2068 
2069  if (!GetCPInfoExW(CodePage, dwFlags, &CPInfo))
2070  return FALSE;
2071 
2072  /* the layout is the same except for CodePageName */
2073  memcpy(lpCPInfoEx, &CPInfo, sizeof(CPINFOEXA));
2074 
2076  0,
2077  CPInfo.CodePageName,
2078  -1,
2079  lpCPInfoEx->CodePageName,
2080  sizeof(lpCPInfoEx->CodePageName),
2081  NULL,
2082  NULL);
2083  return TRUE;
2084 }
#define TRUE
Definition: types.h:120
WCHAR CodePageName[MAX_PATH]
Definition: winnls.h:599
#define CP_ACP
Definition: compat.h:109
INT WINAPI WideCharToMultiByte(UINT CodePage, DWORD Flags, LPCWSTR WideCharString, INT WideCharCount, LPSTR MultiByteString, INT MultiByteCount, LPCSTR DefaultChar, LPBOOL UsedDefaultChar)
Definition: nls.c:2127
#define FALSE
Definition: types.h:117
CHAR CodePageName[MAX_PATH]
Definition: winnls.h:591
_In_ PCCERT_CONTEXT _In_ DWORD dwFlags
Definition: wincrypt.h:1175
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
#define NULL
Definition: types.h:112
BOOL WINAPI GetCPInfoExW(UINT CodePage, DWORD dwFlags, LPCPINFOEXW lpCPInfoEx)
Definition: nls.c:2004

Referenced by init_procs(), and test_threadcp().

◆ GetCPInfoExW()

BOOL WINAPI GetCPInfoExW ( UINT  CodePage,
DWORD  dwFlags,
LPCPINFOEXW  lpCPInfoEx 
)

Definition at line 2004 of file nls.c.

2007 {
2008  if (!GetCPInfo(CodePage, (LPCPINFO)lpCPInfoEx))
2009  return FALSE;
2010 
2011  switch(CodePage)
2012  {
2013  case CP_UTF7:
2014  {
2015  lpCPInfoEx->CodePage = CP_UTF7;
2016  lpCPInfoEx->UnicodeDefaultChar = 0x3f;
2017  return GetLocalisedText(lpCPInfoEx->CodePage,
2018  lpCPInfoEx->CodePageName,
2019  ARRAYSIZE(lpCPInfoEx->CodePageName),
2020  GetThreadLocale()) != 0;
2021  }
2022  break;
2023 
2024  case CP_UTF8:
2025  {
2026  lpCPInfoEx->CodePage = CP_UTF8;
2027  lpCPInfoEx->UnicodeDefaultChar = 0x3f;
2028  return GetLocalisedText(lpCPInfoEx->CodePage,
2029  lpCPInfoEx->CodePageName,
2030  ARRAYSIZE(lpCPInfoEx->CodePageName),
2031  GetThreadLocale()) != 0;
2032  }
2033 
2034  default:
2035  {
2036  PCODEPAGE_ENTRY CodePageEntry;
2037 
2038  CodePageEntry = IntGetCodePageEntry(CodePage);
2039  if (CodePageEntry == NULL)
2040  {
2041  DPRINT1("Could not get CodePage Entry! CodePageEntry = NULL\n");
2043  return FALSE;
2044  }
2045 
2046  lpCPInfoEx->CodePage = CodePageEntry->CodePageTable.CodePage;
2047  lpCPInfoEx->UnicodeDefaultChar = CodePageEntry->CodePageTable.UniDefaultChar;
2048  return GetLocalisedText(lpCPInfoEx->CodePage,
2049  lpCPInfoEx->CodePageName,
2050  ARRAYSIZE(lpCPInfoEx->CodePageName),
2051  GetThreadLocale()) != 0;
2052  }
2053  break;
2054  }
2055 }
#define ERROR_INVALID_PARAMETER
Definition: compat.h:101
BOOL WINAPI GetCPInfo(UINT CodePage, LPCPINFO CodePageInfo)
Definition: nls.c:1950
USHORT UniDefaultChar
Definition: precomp.h:35
#define CP_UTF7
Definition: winnls.h:235
#define ARRAYSIZE(array)
Definition: filtermapper.c:47
#define CP_UTF8
Definition: nls.h:20
#define FALSE
Definition: types.h:117
PCODEPAGE_ENTRY FASTCALL IntGetCodePageEntry(UINT CodePage)
Definition: nls.c:213
#define SetLastError(x)
Definition: compat.h:611
USHORT CodePage
Definition: precomp.h:32
Definition: kernel32.h:62
#define NULL
Definition: types.h:112
#define DPRINT1
Definition: precomp.h:8
UINT GetLocalisedText(IN UINT uID, IN LPWSTR lpszDest, IN UINT cchDest, IN LANGID lang)
Definition: nls.c:1863
CPTABLEINFO CodePageTable
Definition: kernel32.h:68
LCID WINAPI GetThreadLocale(void)
Definition: lang.c:1453

Referenced by AddCodePage(), FillCharacterSetComboList(), GetCPInfoExA(), GetSupportedCP(), and ME_StreamOutRTFHeader().

◆ GetDefaultSortkeySize()

VOID WINAPI GetDefaultSortkeySize ( LPVOID  lpUnknown)

Definition at line 2667 of file nls.c.

2668 {
2669  STUB;
2670  lpUnknown = NULL;
2671 }
#define STUB
Definition: kernel32.h:27
#define NULL
Definition: types.h:112

◆ GetLinguistLangSize()

VOID WINAPI GetLinguistLangSize ( LPVOID  lpUnknown)

Definition at line 2678 of file nls.c.

2679 {
2680  STUB;
2681  lpUnknown = NULL;
2682 }
#define STUB
Definition: kernel32.h:27
#define NULL
Definition: types.h:112

◆ GetLocalisedText()

UINT GetLocalisedText ( IN UINT  uID,
IN LPWSTR  lpszDest,
IN UINT  cchDest,
IN LANGID  lang 
)

Definition at line 1863 of file nls.c.

1868 {
1869  HRSRC hrsrc;
1870  HGLOBAL hmem;
1871  LCID lcid;
1872  LANGID langId;
1873  const WCHAR *p;
1874  UINT i;
1875 
1876  /* See HACK in winnls/lang/xx-XX.rc files */
1877  if (uID == 37)
1878  uID = uID * 100;
1879 
1881 
1882  langId = LANGIDFROMLCID(lcid);
1883 
1884  if (PRIMARYLANGID(langId) == LANG_NEUTRAL)
1886 
1888  (LPWSTR)RT_STRING,
1889  MAKEINTRESOURCEW((uID >> 4) + 1),
1890  langId);
1891 
1892  /* English fallback */
1893  if (!hrsrc)
1894  {
1896  (LPWSTR)RT_STRING,
1897  MAKEINTRESOURCEW((uID >> 4) + 1),
1899  }
1900 
1901  if (!hrsrc)
1902  goto NotFound;
1903 
1904  hmem = LoadResource(hCurrentModule, hrsrc);
1905  if (!hmem)
1906  goto NotFound;
1907 
1908  p = LockResource(hmem);
1909 
1910  for (i = 0; i < (uID & 0x0F); i++)
1911  p += *p + 1;
1912 
1913  /* Needed for GetGeoInfo(): return the needed string size including the NULL terminator */
1914  if (cchDest == 0)
1915  return *p + 1;
1916  /* Needed for GetGeoInfo(): bail out if the user buffer is not large enough */
1917  if (*p + 1 > cchDest)
1918  {
1920  return 0;
1921  }
1922 
1923  i = *p;
1924  if (i > 0)
1925  {
1926  memcpy(lpszDest, p + 1, i * sizeof(WCHAR));
1927  lpszDest[i] = L'\0';
1928  return i;
1929  }
1930 #if 0
1931  else
1932  {
1933  if (cchDest >= 1)
1934  lpszDest[0] = L'\0';
1935  /* Fall-back */
1936  }
1937 #endif
1938 
1939 NotFound:
1940  DPRINT1("Resource not found: uID = %lu\n", uID);
1942  return 0;
1943 }
#define ERROR_INVALID_PARAMETER
Definition: compat.h:101
#define LANG_NEUTRAL
Definition: nls.h:22
LPVOID WINAPI LockResource(HGLOBAL handle)
Definition: res.c:550
DWORD LCID
Definition: nls.h:13
WORD LANGID
Definition: typedefs.h:81
#define SUBLANG_ENGLISH_US
Definition: nls.h:222
#define L(x)
Definition: ntvdm.h:50
LCID WINAPI ConvertDefaultLocale(LCID lcid)
Definition: lang.c:1506
HGLOBAL WINAPI LoadResource(HINSTANCE hModule, HRSRC hRsrc)
Definition: res.c:532
WCHAR lpszDest[260]
HMODULE hCurrentModule
Definition: dllmain.c:25
static const WCHAR lang[]
Definition: wbemdisp.c:287
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define SetLastError(x)
Definition: compat.h:611
#define LANG_ENGLISH
Definition: nls.h:52
HRSRC WINAPI FindResourceExW(HMODULE hModule, LPCWSTR type, LPCWSTR name, WORD lang)
Definition: res.c:164
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
#define LANGIDFROMLCID(l)
Definition: nls.h:18
#define RT_STRING
Definition: pedump.c:368
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
unsigned int UINT
Definition: ndis.h:50
#define DPRINT1
Definition: precomp.h:8
#define MAKELANGID(p, s)
Definition: nls.h:15
#define MAKEINTRESOURCEW(i)
Definition: winuser.h:582
GLfloat GLfloat p
Definition: glext.h:8902
WCHAR * LPWSTR
Definition: xmlstorage.h:184
#define PRIMARYLANGID(l)
Definition: nls.h:16
#define ERROR_INSUFFICIENT_BUFFER
Definition: dderror.h:10

Referenced by GetCPInfoExW().

◆ GetNlsSectionName()

BOOL WINAPI GetNlsSectionName ( UINT  CodePage,
UINT  Base,
ULONG  Unknown,
LPSTR  BaseName,
LPSTR  Result,
ULONG  ResultSize 
)

Definition at line 1394 of file nls.c.

1400 {
1401  CHAR Integer[11];
1402 
1403  if (!NT_SUCCESS(RtlIntegerToChar(CodePage, Base, sizeof(Integer), Integer)))
1404  return FALSE;
1405 
1406  /*
1407  * If the name including the terminating NULL character doesn't
1408  * fit in the output buffer then fail.
1409  */
1410  if (strlen(Integer) + strlen(BaseName) >= ResultSize)
1411  return FALSE;
1412 
1413  lstrcpyA(Result, BaseName);
1414  lstrcatA(Result, Integer);
1415 
1416  return TRUE;
1417 }
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
#define TRUE
Definition: types.h:120
char CHAR
Definition: xmlstorage.h:175
_In_opt_ ULONG Base
Definition: rtlfuncs.h:2413
NTSYSAPI NTSTATUS NTAPI RtlIntegerToChar(_In_ ULONG Value, _In_ ULONG Base, _In_ ULONG Length, _Out_ PCHAR String)
#define FALSE
Definition: types.h:117
_At_(*)(_In_ PWSK_CLIENT Client, _In_opt_ PUNICODE_STRING NodeName, _In_opt_ PUNICODE_STRING ServiceName, _In_opt_ ULONG NameSpace, _In_opt_ GUID *Provider, _In_opt_ PADDRINFOEXW Hints, _Outptr_ PADDRINFOEXW *Result, _In_opt_ PEPROCESS OwningProcess, _In_opt_ PETHREAD OwningThread, _Inout_ PIRP Irp Result)(Mem)) NTSTATUS(WSKAPI *PFN_WSK_GET_ADDRESS_INFO
Definition: wsk.h:426
LPSTR WINAPI lstrcatA(LPSTR lpString1, LPCSTR lpString2)
Definition: lstring.c:123
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
LPSTR WINAPI lstrcpyA(LPSTR lpString1, LPCSTR lpString2)
Definition: lstring.c:100

Referenced by IntGetCodePageEntry().

◆ GetNLSVersion()

BOOL WINAPI GetNLSVersion ( IN NLS_FUNCTION  Function,
IN LCID  Locale,
IN OUT LPNLSVERSIONINFO  lpVersionInformation 
)

Definition at line 2726 of file nls.c.

2729 {
2730  STUB;
2731  return TRUE;
2732 }
#define TRUE
Definition: types.h:120
#define STUB
Definition: kernel32.h:27

◆ GetNLSVersionEx()

BOOL WINAPI GetNLSVersionEx ( IN NLS_FUNCTION  function,
IN LPCWSTR  lpLocaleName,
IN OUT LPNLSVERSIONINFOEX  lpVersionInformation 
)

Definition at line 2739 of file nls.c.

2742 {
2743  STUB;
2744  return TRUE;
2745 }
#define TRUE
Definition: types.h:120
#define STUB
Definition: kernel32.h:27

◆ GetOEMCP()

◆ IntGetCodePageEntry()

PCODEPAGE_ENTRY FASTCALL IntGetCodePageEntry ( UINT  CodePage)

Definition at line 213 of file nls.c.

214 {
215  CHAR SectionName[40];
217  HANDLE SectionHandle = INVALID_HANDLE_VALUE, FileHandle;
218  PBYTE SectionMapping;
220  ANSI_STRING AnsiName;
222  WCHAR FileName[MAX_PATH + 1];
223  UINT FileNamePos;
224  PCODEPAGE_ENTRY CodePageEntry;
225  PSECURITY_DESCRIPTOR NlsSd;
226  if (CodePage == CP_ACP)
227  {
228  return &AnsiCodePage;
229  }
230  else if (CodePage == CP_OEMCP)
231  {
232  return &OemCodePage;
233  }
234  else if (CodePage == CP_THREAD_ACP)
235  {
237  LOCALE_IDEFAULTANSICODEPAGE | LOCALE_RETURN_NUMBER,
238  (WCHAR *)&CodePage,
239  sizeof(CodePage) / sizeof(WCHAR)))
240  {
241  /* Last error is set by GetLocaleInfoW. */
242  return NULL;
243  }
244  if (CodePage == 0)
245  return &AnsiCodePage;
246  }
247  else if (CodePage == CP_MACCP)
248  {
250  LOCALE_IDEFAULTMACCODEPAGE | LOCALE_RETURN_NUMBER,
251  (WCHAR *)&CodePage,
252  sizeof(CodePage) / sizeof(WCHAR)))
253  {
254  /* Last error is set by GetLocaleInfoW. */
255  return NULL;
256  }
257  }
258 
259  /* Try searching for loaded page first. */
260  CodePageEntry = IntGetLoadedCodePageEntry(CodePage);
261  if (CodePageEntry != NULL)
262  {
263  return CodePageEntry;
264  }
265 
266  /*
267  * Yes, we really want to lock here. Otherwise it can happen that
268  * two parallel requests will try to get the entry for the same
269  * code page and we would load it twice.
270  */
272 
273  /* Generate the section name. */
274  if (!GetNlsSectionName(CodePage,
275  10,
276  0,
277  "\\Nls\\NlsSectionCP",
278  SectionName,
279  sizeof(SectionName)))
280  {
282  return NULL;
283  }
284 
285  RtlInitAnsiString(&AnsiName, SectionName);
287 
288  /*
289  * FIXME: IntGetCodePageEntry should not create any security
290  * descriptor here but instead this responsibility should be
291  * assigned to Base Server API (aka basesrv.dll). That is,
292  * kernel32 must instruct basesrv.dll on creating NLS section
293  * names that do not exist through API message communication.
294  * However since we do not do that, let the kernel32 do the job
295  * by assigning security to NLS section names for the time being...
296  */
298  if (!NT_SUCCESS(Status))
299  {
301  return NULL;
302  }
303 
305 
306  /* Try to open the section first */
308 
309  /* If the section doesn't exist, try to create it. */
310  if (Status == STATUS_UNSUCCESSFUL ||
313  {
314  FileNamePos = GetSystemDirectoryW(FileName, MAX_PATH);
315  if (GetCPFileNameFromRegistry(CodePage,
316  FileName + FileNamePos + 1,
317  MAX_PATH - FileNamePos - 1))
318  {
319  FileName[FileNamePos] = L'\\';
320  FileName[MAX_PATH] = 0;
324  NULL,
326  0,
327  NULL);
328 
329  Status = NtCreateSection(&SectionHandle,
332  NULL,
334  SEC_COMMIT,
335  FileHandle);
336 
337  /* HACK: Check if another process was faster
338  * and already created this section. See bug 3626 for details */
340  {
341  /* Close the file then */
343 
344  /* And open the section */
345  Status = NtOpenSection(&SectionHandle,
348  }
349  }
350  }
352  HeapFree(GetProcessHeap(), 0, NlsSd);
353 
354  if (!NT_SUCCESS(Status))
355  {
357  return NULL;
358  }
359 
360  SectionMapping = MapViewOfFile(SectionHandle, FILE_MAP_READ, 0, 0, 0);
361  if (SectionMapping == NULL)
362  {
363  NtClose(SectionHandle);
365  return NULL;
366  }
367 
368  CodePageEntry = HeapAlloc(GetProcessHeap(), 0, sizeof(CODEPAGE_ENTRY));
369  if (CodePageEntry == NULL)
370  {
371  NtClose(SectionHandle);
373  return NULL;
374  }
375 
376  CodePageEntry->CodePage = CodePage;
377  CodePageEntry->SectionHandle = SectionHandle;
378  CodePageEntry->SectionMapping = SectionMapping;
379 
380  RtlInitCodePageTable((PUSHORT)SectionMapping, &CodePageEntry->CodePageTable);
381 
382  /* Insert the new entry to list and unlock. Uff. */
383  InsertTailList(&CodePageListHead, &CodePageEntry->Entry);
385 
386  return CodePageEntry;
387 }
#define STATUS_OBJECT_NAME_COLLISION
Definition: udferr_usr.h:150
#define FILE_GENERIC_READ
Definition: nt_native.h:653
IN PUNICODE_STRING IN POBJECT_ATTRIBUTES ObjectAttributes
Definition: conport.c:35
#define LOCALE_IDEFAULTANSICODEPAGE
Definition: winnls.h:38
static CODEPAGE_ENTRY AnsiCodePage
Definition: nls.c:46
#define MapViewOfFile
Definition: compat.h:604
NTSTATUS NTAPI NtCreateSection(OUT PHANDLE SectionHandle, IN ACCESS_MASK DesiredAccess, IN POBJECT_ATTRIBUTES ObjectAttributes OPTIONAL, IN PLARGE_INTEGER MaximumSize OPTIONAL, IN ULONG SectionPageProtection OPTIONAL, IN ULONG AllocationAttributes, IN HANDLE FileHandle OPTIONAL)
Definition: section.c:3454
#define TRUE
Definition: types.h:120
static LIST_ENTRY CodePageListHead
Definition: nls.c:45
#define CP_ACP
Definition: compat.h:109
char CHAR
Definition: xmlstorage.h:175
LONG NTSTATUS
Definition: precomp.h:26
IN PDCB IN POEM_STRING IN PUNICODE_STRING UnicodeName
Definition: fatprocs.h:1303
#define LOCALE_IDEFAULTMACCODEPAGE
Definition: winnls.h:39
NTSYSAPI NTSTATUS NTAPI RtlEnterCriticalSection(_In_ PRTL_CRITICAL_SECTION CriticalSection)
#define INVALID_HANDLE_VALUE
Definition: compat.h:590
#define InsertTailList(ListHead, Entry)
PCODEPAGE_ENTRY FASTCALL IntGetLoadedCodePageEntry(UINT CodePage)
Definition: nls.c:177
#define FILE_SHARE_READ
Definition: compat.h:136
NTSYSAPI VOID NTAPI RtlInitAnsiString(PANSI_STRING DestinationString, PCSZ SourceString)
INT WINAPI GetLocaleInfoW(LCID lcid, LCTYPE lctype, LPWSTR buffer, INT len)
Definition: lang.c:1102
#define L(x)
Definition: ntvdm.h:50
#define SEC_COMMIT
Definition: mmtypes.h:99
NTSYSAPI NTSTATUS NTAPI RtlLeaveCriticalSection(_In_ PRTL_CRITICAL_SECTION CriticalSection)
UINT CodePage
Definition: kernel32.h:65
NTSTATUS NTAPI NtOpenSection(OUT PHANDLE SectionHandle, IN ACCESS_MASK DesiredAccess, IN POBJECT_ATTRIBUTES ObjectAttributes)
Definition: section.c:3582
#define FILE_MAP_READ
Definition: compat.h:635
#define OPEN_EXISTING
Definition: compat.h:634
Status
Definition: gdiplustypes.h:24
#define GetProcessHeap()
Definition: compat.h:595
PVOID WINAPI HeapAlloc(HANDLE, DWORD, SIZE_T)
__wchar_t WCHAR
Definition: xmlstorage.h:180
LIST_ENTRY Entry
Definition: kernel32.h:64
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define MAX_PATH
Definition: compat.h:34
#define LOCALE_SYSTEM_DEFAULT
#define STATUS_OBJECT_PATH_NOT_FOUND
Definition: udferr_usr.h:151
NTSYSAPI VOID NTAPI RtlFreeUnicodeString(PUNICODE_STRING UnicodeString)
NTSTATUS NTAPI NtClose(IN HANDLE Handle)
Definition: obhandle.c:3402
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
static CODEPAGE_ENTRY OemCodePage
Definition: nls.c:47
static RTL_CRITICAL_SECTION CodePageListLock
Definition: nls.c:48
#define SECTION_MAP_READ
Definition: compat.h:139
VOID NTAPI RtlInitCodePageTable(IN PUSHORT TableBase, OUT PCPTABLEINFO CodePageTable)
Definition: nls.c:155
BOOL WINAPI GetCPFileNameFromRegistry(UINT CodePage, LPWSTR FileName, ULONG FileNameSize)
Definition: nls.c:1439
BOOL WINAPI GetNlsSectionName(UINT CodePage, UINT Base, ULONG Unknown, LPSTR BaseName, LPSTR Result, ULONG ResultSize)
Definition: nls.c:1394
NTSTATUS WINAPI CreateNlsSecurityDescriptor(_Out_ PSECURITY_DESCRIPTOR *SecurityDescriptor, _In_ SIZE_T DescriptorSize, _In_ ULONG AccessMask)
Creates a security descriptor for each NLS section name.
Definition: nls.c:2483
_Must_inspect_result_ _In_opt_ PFLT_INSTANCE _Out_ PHANDLE FileHandle
Definition: fltkernel.h:1230
#define STATUS_OBJECT_NAME_NOT_FOUND
Definition: udferr_usr.h:149
Definition: kernel32.h:62
NTSYSAPI NTSTATUS NTAPI RtlAnsiStringToUnicodeString(PUNICODE_STRING DestinationString, PANSI_STRING SourceString, BOOLEAN AllocateDestinationString)
UINT WINAPI GetSystemDirectoryW(OUT LPWSTR lpBuffer, IN UINT uSize)
Definition: path.c:2313
unsigned int UINT
Definition: ndis.h:50
#define NULL
Definition: types.h:112
#define PAGE_READONLY
Definition: compat.h:138
PBYTE SectionMapping
Definition: kernel32.h:67
#define CreateFileW
Definition: compat.h:600
#define InitializeObjectAttributes(p, n, a, r, s)
Definition: reg.c:106
HANDLE SectionHandle
Definition: kernel32.h:66
#define CP_THREAD_ACP
Definition: winnls.h:233
BYTE * PBYTE
Definition: pedump.c:66
#define CP_OEMCP
Definition: winnls.h:231
#define HeapFree(x, y, z)
Definition: compat.h:594
unsigned short * PUSHORT
Definition: retypes.h:2
CPTABLEINFO CodePageTable
Definition: kernel32.h:68
LCID WINAPI GetThreadLocale(void)
Definition: lang.c:1453
#define CP_MACCP
Definition: winnls.h:232

Referenced by GetCPInfo(), GetCPInfoExW(), IntMultiByteToWideCharCP(), IntWideCharToMultiByteCP(), and IsDBCSLeadByteEx().

◆ IntGetLoadedCodePageEntry()

PCODEPAGE_ENTRY FASTCALL IntGetLoadedCodePageEntry ( UINT  CodePage)

Definition at line 177 of file nls.c.

178 {
179  LIST_ENTRY *CurrentEntry;
180  PCODEPAGE_ENTRY Current;
181 
183  for (CurrentEntry = CodePageListHead.Flink;
184  CurrentEntry != &CodePageListHead;
185  CurrentEntry = CurrentEntry->Flink)
186  {
187  Current = CONTAINING_RECORD(CurrentEntry, CODEPAGE_ENTRY, Entry);
188  if (Current->CodePage == CodePage)
189  {
191  return Current;
192  }
193  }
195 
196  return NULL;
197 }
static LIST_ENTRY CodePageListHead
Definition: nls.c:45
NTSYSAPI NTSTATUS NTAPI RtlEnterCriticalSection(_In_ PRTL_CRITICAL_SECTION CriticalSection)
NTSYSAPI NTSTATUS NTAPI RtlLeaveCriticalSection(_In_ PRTL_CRITICAL_SECTION CriticalSection)
UINT CodePage
Definition: kernel32.h:65
PFLT_MESSAGE_WAITER_QUEUE CONTAINING_RECORD(Csq, DEVICE_EXTENSION, IrpQueue)) -> WaiterQ.mLock) _IRQL_raises_(DISPATCH_LEVEL) VOID NTAPI FltpAcquireMessageWaiterLock(_In_ PIO_CSQ Csq, _Out_ PKIRQL Irql)
Definition: Messaging.c:560
struct _LIST_ENTRY * Flink
Definition: typedefs.h:121
static RTL_CRITICAL_SECTION CodePageListLock
Definition: nls.c:48
Definition: typedefs.h:119
Definition: kernel32.h:62
#define NULL
Definition: types.h:112
base of all file and directory entries
Definition: entries.h:82

Referenced by IntGetCodePageEntry(), and IsValidCodePage().

◆ IntIsLeadByte()

static BOOL WINAPI IntIsLeadByte ( PCPTABLEINFO  TableInfo,
BYTE  Byte 
)
static

Definition at line 1347 of file nls.c.

1348 {
1349  UINT i;
1350 
1351  if (TableInfo->MaximumCharacterSize == 2)
1352  {
1353  for (i = 0; i < MAXIMUM_LEADBYTES && TableInfo->LeadByte[i]; i += 2)
1354  {
1355  if (Byte >= TableInfo->LeadByte[i] && Byte <= TableInfo->LeadByte[i+1])
1356  return TRUE;
1357  }
1358  }
1359 
1360  return FALSE;
1361 }
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
UCHAR LeadByte[MAXIMUM_LEADBYTES]
Definition: precomp.h:39
USHORT MaximumCharacterSize
Definition: precomp.h:33
#define MAXIMUM_LEADBYTES
Definition: precomp.h:16
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
unsigned int UINT
Definition: ndis.h:50
unsigned char Byte
Definition: zlib.h:37

Referenced by IsDBCSLeadByte(), and IsDBCSLeadByteEx().

◆ IntIsValidDBCSMapping()

static BOOL IntIsValidDBCSMapping ( PCPTABLEINFO  CodePageTable,
DWORD  Flags,
WCHAR  wch,
USHORT  ch 
)
inlinestatic

Definition at line 1036 of file nls.c.

1037 {
1038  /* If ch is the default character, but the wch is not, it can't be a valid mapping */
1040  return FALSE;
1041 
1042  /* If the WC_NO_BEST_FIT_CHARS flag has been specified, the characters need to match exactly. */
1044  {
1045  if(ch & 0xff00)
1046  {
1047  USHORT uOffset = CodePageTable->DBCSOffsets[ch >> 8];
1048  /* if (!uOffset) return (CodePageTable->MultiByteTable[ch] == wch); */
1049  return (CodePageTable->DBCSOffsets[uOffset + (ch & 0xff)] == wch);
1050  }
1051 
1052  return (CodePageTable->MultiByteTable[ch] == wch);
1053  }
1054 
1055  /* If we're still here, we have a valid mapping */
1056  return TRUE;
1057 }
PUSHORT DBCSOffsets
Definition: precomp.h:43
PUSHORT MultiByteTable
Definition: precomp.h:40
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
USHORT TransDefaultChar
Definition: precomp.h:36
_Must_inspect_result_ _In_ ULONG Flags
Definition: wsk.h:170
USHORT TransUniDefaultChar
Definition: precomp.h:37
#define WC_NO_BEST_FIT_CHARS
Definition: unicode.h:46
unsigned short USHORT
Definition: pedump.c:61
_Out_ PCPTABLEINFO CodePageTable
Definition: rtlfuncs.h:4291

Referenced by IntWideCharToMultiByteCP().

◆ IntIsValidSBCSMapping()

static BOOL IntIsValidSBCSMapping ( PCPTABLEINFO  CodePageTable,
DWORD  Flags,
WCHAR  wch,
UCHAR  ch 
)
inlinestatic

Definition at line 1013 of file nls.c.

1014 {
1015  /* If the WC_NO_BEST_FIT_CHARS flag has been specified, the characters need to match exactly. */
1017  return (CodePageTable->MultiByteTable[ch] == wch);
1018 
1019  /* By default, all characters except TransDefaultChar apply as a valid mapping
1020  for ch (so also "nearest" characters) */
1021  if (ch != CodePageTable->TransDefaultChar)
1022  return TRUE;
1023 
1024  /* The only possible left valid mapping is the default character itself */
1025  return (wch == CodePageTable->TransUniDefaultChar);
1026 }
PUSHORT MultiByteTable
Definition: precomp.h:40
#define TRUE
Definition: types.h:120
USHORT TransDefaultChar
Definition: precomp.h:36
_Must_inspect_result_ _In_ ULONG Flags
Definition: wsk.h:170
USHORT TransUniDefaultChar
Definition: precomp.h:37
#define WC_NO_BEST_FIT_CHARS
Definition: unicode.h:46
_Out_ PCPTABLEINFO CodePageTable
Definition: rtlfuncs.h:4291

Referenced by IntWideCharToMultiByteCP().

◆ IntMultiByteToWideCharCP()

static INT WINAPI IntMultiByteToWideCharCP ( UINT  CodePage,
DWORD  Flags,
LPCSTR  MultiByteString,
INT  MultiByteCount,
LPWSTR  WideCharString,
INT  WideCharCount 
)
static

Definition at line 573 of file nls.c.

579 {
580  PCODEPAGE_ENTRY CodePageEntry;
582  PUSHORT MultiByteTable;
583  LPCSTR TempString;
584  INT TempLength;
585  USHORT WideChar;
586 
587  /* Get code page table. */
588  CodePageEntry = IntGetCodePageEntry(CodePage);
589  if (CodePageEntry == NULL)
590  {
592  return 0;
593  }
594 
595  CodePageTable = &CodePageEntry->CodePageTable;
596 
597  /* If MB_USEGLYPHCHARS flag present and glyph table present */
599  {
600  /* Use glyph table */
601  MultiByteTable = CodePageTable->MultiByteTable + 256 + 1;
602  }
603  else
604  {
605  MultiByteTable = CodePageTable->MultiByteTable;
606  }
607 
608  /* Different handling for DBCS code pages. */
610  {
611  UCHAR Char;
612  USHORT DBCSOffset;
613  LPCSTR MbsEnd = MultiByteString + MultiByteCount;
614  INT Count;
615 
617  {
618  TempString = MultiByteString;
619 
620  while (TempString < MbsEnd)
621  {
622  DBCSOffset = CodePageTable->DBCSOffsets[(UCHAR)*TempString];
623 
624  if (DBCSOffset)
625  {
626  /* If lead byte is presented, but behind it there is no symbol */
627  if (((TempString + 1) == MbsEnd) || (*(TempString + 1) == 0))
628  {
630  return 0;
631  }
632 
633  WideChar = CodePageTable->DBCSOffsets[DBCSOffset + *(TempString + 1)];
634 
635  if (WideChar == CodePageTable->UniDefaultChar &&
636  MAKEWORD(*(TempString + 1), *TempString) != CodePageTable->TransUniDefaultChar)
637  {
639  return 0;
640  }
641 
642  TempString++;
643  }
644  else
645  {
646  WideChar = MultiByteTable[(UCHAR)*TempString];
647 
648  if ((WideChar == CodePageTable->UniDefaultChar &&
649  *TempString != CodePageTable->TransUniDefaultChar) ||
650  /* "Private Use" characters */
651  (WideChar >= 0xE000 && WideChar <= 0xF8FF))
652  {
654  return 0;
655  }
656  }
657 
658  TempString++;
659  }
660  }
661 
662  /* Does caller query for output buffer size? */
663  if (WideCharCount == 0)
664  {
665  for (; MultiByteString < MbsEnd; WideCharCount++)
666  {
667  Char = *MultiByteString++;
668 
669  DBCSOffset = CodePageTable->DBCSOffsets[Char];
670 
671  if (!DBCSOffset)
672  continue;
673 
674  if (MultiByteString < MbsEnd)
675  MultiByteString++;
676  }
677 
678  return WideCharCount;
679  }
680 
681  for (Count = 0; Count < WideCharCount && MultiByteString < MbsEnd; Count++)
682  {
683  Char = *MultiByteString++;
684 
685  DBCSOffset = CodePageTable->DBCSOffsets[Char];
686 
687  if (!DBCSOffset)
688  {
689  *WideCharString++ = MultiByteTable[Char];
690  continue;
691  }
692 
693  if (MultiByteString == MbsEnd || *MultiByteString == 0)
694  {
695  *WideCharString++ = CodePageTable->UniDefaultChar;
696  }
697  else
698  {
699  *WideCharString++ = CodePageTable->DBCSOffsets[DBCSOffset + (UCHAR)*MultiByteString++];
700  }
701  }
702 
703  if (MultiByteString < MbsEnd)
704  {
706  return 0;
707  }
708 
709  return Count;
710  }
711  else /* SBCS code page */
712  {
713  /* Check for invalid characters. */
715  {
716  for (TempString = MultiByteString, TempLength = MultiByteCount;
717  TempLength > 0;
718  TempString++, TempLength--)
719  {
720  WideChar = MultiByteTable[(UCHAR)*TempString];
721 
722  if ((WideChar == CodePageTable->UniDefaultChar &&
723  *TempString != CodePageTable->TransUniDefaultChar) ||
724  /* "Private Use" characters */
725  (WideChar >= 0xE000 && WideChar <= 0xF8FF))
726  {
728  return 0;
729  }
730  }
731  }
732 
733  /* Does caller query for output buffer size? */
734  if (WideCharCount == 0)
735  return MultiByteCount;
736 
737  /* Fill the WideCharString buffer with what will fit: Verified on WinXP */
738  for (TempLength = (WideCharCount < MultiByteCount) ? WideCharCount : MultiByteCount;
739  TempLength > 0;
740  MultiByteString++, TempLength--)
741  {
742  *WideCharString++ = MultiByteTable[(UCHAR)*MultiByteString];
743  }
744 
745  /* Adjust buffer size. Wine trick ;-) */
746  if (WideCharCount < MultiByteCount)
747  {
748  MultiByteCount = WideCharCount;
750  return 0;
751  }
752  return MultiByteCount;
753  }
754 }
#define ERROR_INVALID_PARAMETER
Definition: compat.h:101
#define MB_ERR_INVALID_CHARS
Definition: unicode.h:41
USHORT UniDefaultChar
Definition: precomp.h:35
PUSHORT DBCSOffsets
Definition: precomp.h:43
#define MB_USEGLYPHCHARS
Definition: unicode.h:42
PUSHORT MultiByteTable
Definition: precomp.h:40
#define MAKEWORD(a, b)
Definition: typedefs.h:248
int32_t INT
Definition: typedefs.h:58
const char * LPCSTR
Definition: xmlstorage.h:183
USHORT DBCSCodePage
Definition: precomp.h:38
int Count
Definition: noreturn.cpp:7
_Must_inspect_result_ _In_ ULONG Flags
Definition: wsk.h:170
USHORT TransUniDefaultChar
Definition: precomp.h:37
PCODEPAGE_ENTRY FASTCALL IntGetCodePageEntry(UINT CodePage)
Definition: nls.c:213
#define SetLastError(x)
Definition: compat.h:611
#define ERROR_NO_UNICODE_TRANSLATION
Definition: winerror.h:649
unsigned char UCHAR
Definition: xmlstorage.h:181
Definition: kernel32.h:62
unsigned short USHORT
Definition: pedump.c:61
#define NULL
Definition: types.h:112
*BytesInMultiByteString PCHAR MultiByteString
Definition: rtlfuncs.h:1527
_Out_ PCPTABLEINFO CodePageTable
Definition: rtlfuncs.h:4291
unsigned short * PUSHORT
Definition: retypes.h:2
CPTABLEINFO CodePageTable
Definition: kernel32.h:68
#define ERROR_INSUFFICIENT_BUFFER
Definition: dderror.h:10

Referenced by MultiByteToWideChar().

◆ IntMultiByteToWideCharSYMBOL()

static INT WINAPI IntMultiByteToWideCharSYMBOL ( DWORD  Flags,
LPCSTR  MultiByteString,
INT  MultiByteCount,
LPWSTR  WideCharString,
INT  WideCharCount 
)
static

Definition at line 767 of file nls.c.

772 {
773  LONG Count;
774  UCHAR Char;
775  INT WideCharMaxLen;
776 
777 
778  if (Flags != 0)
779  {
781  return 0;
782  }
783 
784  if (WideCharCount == 0)
785  {
786  return MultiByteCount;
787  }
788 
789  WideCharMaxLen = WideCharCount > MultiByteCount ? MultiByteCount : WideCharCount;
790 
791  for (Count = 0; Count < WideCharMaxLen; Count++)
792  {
793  Char = MultiByteString[Count];
794  if ( Char < 0x20 )
795  {
796  WideCharString[Count] = Char;
797  }
798  else
799  {
800  WideCharString[Count] = Char + 0xf000;
801  }
802  }
803  if (MultiByteCount > WideCharMaxLen)
804  {
806  return 0;
807  }
808 
809  return WideCharMaxLen;
810 }
int32_t INT
Definition: typedefs.h:58
long LONG
Definition: pedump.c:60
int Count
Definition: noreturn.cpp:7
_Must_inspect_result_ _In_ ULONG Flags
Definition: wsk.h:170
#define SetLastError(x)
Definition: compat.h:611
unsigned char UCHAR
Definition: xmlstorage.h:181
*BytesInMultiByteString PCHAR MultiByteString
Definition: rtlfuncs.h:1527
#define ERROR_INVALID_FLAGS
Definition: winerror.h:583
#define ERROR_INSUFFICIENT_BUFFER
Definition: dderror.h:10

Referenced by MultiByteToWideChar().

◆ IntMultiByteToWideCharUTF8()

static INT WINAPI IntMultiByteToWideCharUTF8 ( DWORD  Flags,
LPCSTR  MultiByteString,
INT  MultiByteCount,
LPWSTR  WideCharString,
INT  WideCharCount 
)
static

Definition at line 401 of file nls.c.

406 {
407  LPCSTR MbsEnd, MbsPtrSave;
408  UCHAR Char, TrailLength;
409  WCHAR WideChar;
410  LONG Count;
411  BOOL CharIsValid, StringIsValid = TRUE;
412  const WCHAR InvalidChar = 0xFFFD;
413 
414  if (Flags != 0 && Flags != MB_ERR_INVALID_CHARS)
415  {
417  return 0;
418  }
419 
420  /* Does caller query for output buffer size? */
421  if (WideCharCount == 0)
422  {
423  /* validate and count the wide characters */
424  MbsEnd = MultiByteString + MultiByteCount;
425  for (; MultiByteString < MbsEnd; WideCharCount++)
426  {
427  Char = *MultiByteString++;
428  if (Char < 0x80)
429  {
430  TrailLength = 0;
431  continue;
432  }
433  if ((Char & 0xC0) == 0x80)
434  {
435  TrailLength = 0;
436  StringIsValid = FALSE;
437  continue;
438  }
439 
440  TrailLength = UTF8Length[Char - 0x80];
441  if (TrailLength == 0)
442  {
443  StringIsValid = FALSE;
444  continue;
445  }
446 
447  CharIsValid = TRUE;
448  MbsPtrSave = MultiByteString;
449  WideChar = Char & UTF8Mask[TrailLength];
450 
451  while (TrailLength && MultiByteString < MbsEnd)
452  {
453  if ((*MultiByteString & 0xC0) != 0x80)
454  {
455  CharIsValid = StringIsValid = FALSE;
456  break;
457  }
458 
459  WideChar = (WideChar << 6) | (*MultiByteString++ & 0x7f);
460  TrailLength--;
461  }
462 
463  if (!CharIsValid || WideChar < UTF8LBound[UTF8Length[Char - 0x80]])
464  {
465  MultiByteString = MbsPtrSave;
466  }
467  }
468 
469  if (TrailLength)
470  {
471  WideCharCount++;
472  StringIsValid = FALSE;
473  }
474 
475  if (Flags == MB_ERR_INVALID_CHARS && !StringIsValid)
476  {
478  return 0;
479  }
480 
481  return WideCharCount;
482  }
483 
484  /* convert */
485  MbsEnd = MultiByteString + MultiByteCount;
486  for (Count = 0; Count < WideCharCount && MultiByteString < MbsEnd; Count++)
487  {
488  Char = *MultiByteString++;
489  if (Char < 0x80)
490  {
491  *WideCharString++ = Char;
492  TrailLength = 0;
493  continue;
494  }
495  if ((Char & 0xC0) == 0x80)
496  {
497  *WideCharString++ = InvalidChar;
498  TrailLength = 0;
499  StringIsValid = FALSE;
500  continue;
501  }
502 
503  TrailLength = UTF8Length[Char - 0x80];
504  if (TrailLength == 0)
505  {
506  *WideCharString++ = InvalidChar;
507  StringIsValid = FALSE;
508  continue;
509  }
510 
511  CharIsValid = TRUE;
512  MbsPtrSave = MultiByteString;
513  WideChar = Char & UTF8Mask[TrailLength];
514 
515  while (TrailLength && MultiByteString < MbsEnd)
516  {
517  if ((*MultiByteString & 0xC0) != 0x80)
518  {
519  CharIsValid = StringIsValid = FALSE;
520  break;
521  }
522 
523  WideChar = (WideChar << 6) | (*MultiByteString++ & 0x7f);
524  TrailLength--;
525  }
526 
527  if (CharIsValid && UTF8LBound[UTF8Length[Char - 0x80]] <= WideChar)
528  {
529  *WideCharString++ = WideChar;
530  }
531  else
532  {
533  *WideCharString++ = InvalidChar;
534  MultiByteString = MbsPtrSave;
535  StringIsValid = FALSE;
536  }
537  }
538 
539  if (TrailLength && Count < WideCharCount && MultiByteString < MbsEnd)
540  {
541  *WideCharString = InvalidChar;
542  WideCharCount++;
543  }
544 
545  if (MultiByteString < MbsEnd)
546  {
548  return 0;
549  }
550 
551  if (Flags == MB_ERR_INVALID_CHARS && (!StringIsValid || TrailLength))
552  {
554  return 0;
555  }
556 
557  return Count;
558 }
#define MB_ERR_INVALID_CHARS
Definition: unicode.h:41
#define TRUE
Definition: types.h:120
static const char UTF8Length[128]
Definition: nls.c:25
static const unsigned long UTF8LBound[]
Definition: nls.c:41
#define FALSE
Definition: types.h:117
unsigned int BOOL
Definition: ntddk_ex.h:94
long LONG
Definition: pedump.c:60
const char * LPCSTR
Definition: xmlstorage.h:183
int Count
Definition: noreturn.cpp:7
_Must_inspect_result_ _In_ ULONG Flags
Definition: wsk.h:170
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define SetLastError(x)
Definition: compat.h:611
#define ERROR_NO_UNICODE_TRANSLATION
Definition: winerror.h:649
unsigned char UCHAR
Definition: xmlstorage.h:181
static const unsigned char UTF8Mask[6]
Definition: nls.c:38
*BytesInMultiByteString PCHAR MultiByteString
Definition: rtlfuncs.h:1527
#define ERROR_INVALID_FLAGS
Definition: winerror.h:583
#define ERROR_INSUFFICIENT_BUFFER
Definition: dderror.h:10

Referenced by MultiByteToWideChar().

◆ IntWideCharToMultiByteCP()

static INT WINAPI IntWideCharToMultiByteCP ( UINT  CodePage,
DWORD  Flags,
LPCWSTR  WideCharString,
INT  WideCharCount,
LPSTR  MultiByteString,
INT  MultiByteCount,
LPCSTR  DefaultChar,
LPBOOL  UsedDefaultChar 
)
static

Definition at line 1070 of file nls.c.

1078 {
1079  PCODEPAGE_ENTRY CodePageEntry;
1081  INT TempLength;
1082 
1083  /* Get code page table. */
1084  CodePageEntry = IntGetCodePageEntry(CodePage);
1085  if (CodePageEntry == NULL)
1086  {
1088  return 0;
1089  }
1090 
1091  CodePageTable = &CodePageEntry->CodePageTable;
1092 
1093 
1094  /* Different handling for DBCS code pages. */
1096  {
1097  /* If Flags, DefaultChar or UsedDefaultChar were given, we have to do some more work */
1098  if (Flags || DefaultChar || UsedDefaultChar)
1099  {
1100  BOOL TempUsedDefaultChar;
1101  USHORT DefChar;
1102 
1103  /* If UsedDefaultChar is not set, set it to a temporary value, so we don't have
1104  to check on every character */
1105  if (!UsedDefaultChar)
1106  UsedDefaultChar = &TempUsedDefaultChar;
1107 
1108  *UsedDefaultChar = FALSE;
1109 
1110  /* Use the CodePage's TransDefaultChar if none was given. Don't modify the DefaultChar pointer here. */
1111  if (DefaultChar)
1112  DefChar = DefaultChar[1] ? ((DefaultChar[0] << 8) | DefaultChar[1]) : DefaultChar[0];
1113  else
1114  DefChar = CodePageTable->TransDefaultChar;
1115 
1116  /* Does caller query for output buffer size? */
1117  if (!MultiByteCount)
1118  {
1119  for (TempLength = 0; WideCharCount; WideCharCount--, WideCharString++, TempLength++)
1120  {
1121  USHORT uChar;
1122 
1123  if ((Flags & WC_COMPOSITECHECK) && WideCharCount > 1)
1124  {
1125  /* FIXME: Handle WC_COMPOSITECHECK */
1126  DPRINT("WC_COMPOSITECHECK flag UNIMPLEMENTED\n");
1127  }
1128 
1129  uChar = ((PUSHORT) CodePageTable->WideCharTable)[*WideCharString];
1130 
1131  /* Verify if the mapping is valid for handling DefaultChar and UsedDefaultChar */
1132  if (!IntIsValidDBCSMapping(CodePageTable, Flags, *WideCharString, uChar))
1133  {
1134  uChar = DefChar;
1135  *UsedDefaultChar = TRUE;
1136  }
1137 
1138  /* Increment TempLength again if this is a double-byte character */
1139  if (uChar & 0xff00)
1140  TempLength++;
1141  }
1142 
1143  return TempLength;
1144  }
1145 
1146  /* Convert the WideCharString to the MultiByteString and verify if the mapping is valid */
1147  for (TempLength = MultiByteCount;
1148  WideCharCount && TempLength;
1149  TempLength--, WideCharString++, WideCharCount--)
1150  {
1151  USHORT uChar;
1152 
1153  if ((Flags & WC_COMPOSITECHECK) && WideCharCount > 1)
1154  {
1155  /* FIXME: Handle WC_COMPOSITECHECK */
1156  DPRINT("WC_COMPOSITECHECK flag UNIMPLEMENTED\n");
1157  }
1158 
1159  uChar = ((PUSHORT)CodePageTable->WideCharTable)[*WideCharString];
1160 
1161  /* Verify if the mapping is valid for handling DefaultChar and UsedDefaultChar */
1162  if (!IntIsValidDBCSMapping(CodePageTable, Flags, *WideCharString, uChar))
1163  {
1164  uChar = DefChar;
1165  *UsedDefaultChar = TRUE;
1166  }
1167 
1168  /* Handle double-byte characters */
1169  if (uChar & 0xff00)
1170  {
1171  /* Don't output a partial character */
1172  if (TempLength == 1)
1173  break;
1174 
1175  TempLength--;
1176  *MultiByteString++ = uChar >> 8;
1177  }
1178 
1179  *MultiByteString++ = (char)uChar;
1180  }
1181 
1182  /* WideCharCount should be 0 if all characters were converted */
1183  if (WideCharCount)
1184  {
1186  return 0;
1187  }
1188 
1189  return MultiByteCount - TempLength;
1190  }
1191 
1192  /* Does caller query for output buffer size? */
1193  if (!MultiByteCount)
1194  {
1195  for (TempLength = 0; WideCharCount; WideCharCount--, WideCharString++, TempLength++)
1196  {
1197  /* Increment TempLength again if this is a double-byte character */
1198  if (((PWCHAR)CodePageTable->WideCharTable)[*WideCharString] & 0xff00)
1199  TempLength++;
1200  }
1201 
1202  return TempLength;
1203  }
1204 
1205  /* Convert the WideCharString to the MultiByteString */
1206  for (TempLength = MultiByteCount;
1207  WideCharCount && TempLength;
1208  TempLength--, WideCharString++, WideCharCount--)
1209  {
1210  USHORT uChar = ((PUSHORT) CodePageTable->WideCharTable)[*WideCharString];
1211 
1212  /* Is this a double-byte character? */
1213  if (uChar & 0xff00)
1214  {
1215  /* Don't output a partial character */
1216  if (TempLength == 1)
1217  break;
1218 
1219  TempLength--;
1220  *MultiByteString++ = uChar >> 8;
1221  }
1222 
1223  *MultiByteString++ = (char)uChar;
1224  }
1225 
1226  /* WideCharCount should be 0 if all characters were converted */
1227  if (WideCharCount)
1228  {
1230  return 0;
1231  }
1232 
1233  return MultiByteCount - TempLength;
1234  }
1235  else /* SBCS code page */
1236  {
1237  INT nReturn;
1238 
1239  /* If Flags, DefaultChar or UsedDefaultChar were given, we have to do some more work */
1240  if (Flags || DefaultChar || UsedDefaultChar)
1241  {
1242  BOOL TempUsedDefaultChar;
1243  CHAR DefChar;
1244 
1245  /* If UsedDefaultChar is not set, set it to a temporary value, so we don't have
1246  to check on every character */
1247  if (!UsedDefaultChar)
1248  UsedDefaultChar = &TempUsedDefaultChar;
1249 
1250  *UsedDefaultChar = FALSE;
1251 
1252  /* Does caller query for output buffer size? */
1253  if (!MultiByteCount)
1254  {
1255  /* Loop through the whole WideCharString and check if we can get a valid mapping for each character */
1256  for (TempLength = 0; WideCharCount; TempLength++, WideCharString++, WideCharCount--)
1257  {
1258  if ((Flags & WC_COMPOSITECHECK) && WideCharCount > 1)
1259  {
1260  /* FIXME: Handle WC_COMPOSITECHECK */
1261  DPRINT("WC_COMPOSITECHECK flag UNIMPLEMENTED\n");
1262  }
1263 
1264  if (!*UsedDefaultChar)
1265  *UsedDefaultChar = !IntIsValidSBCSMapping(CodePageTable,
1266  Flags,
1267  *WideCharString,
1268  ((PCHAR)CodePageTable->WideCharTable)[*WideCharString]);
1269  }
1270 
1271  return TempLength;
1272  }
1273 
1274  /* Use the CodePage's TransDefaultChar if none was given. Don't modify the DefaultChar pointer here. */
1275  if (DefaultChar)
1276  DefChar = *DefaultChar;
1277  else
1278  DefChar = (CHAR)CodePageTable->TransDefaultChar;
1279 
1280  /* Convert the WideCharString to the MultiByteString and verify if the mapping is valid */
1281  for (TempLength = MultiByteCount;
1282  WideCharCount && TempLength;
1283  MultiByteString++, TempLength--, WideCharString++, WideCharCount--)
1284  {
1285  if ((Flags & WC_COMPOSITECHECK) && WideCharCount > 1)
1286  {
1287  /* FIXME: Handle WC_COMPOSITECHECK */
1288  DPRINT("WC_COMPOSITECHECK flag UNIMPLEMENTED\n");
1289  }
1290 
1291  *MultiByteString = ((PCHAR)CodePageTable->WideCharTable)[*WideCharString];
1292 
1293  if (!IntIsValidSBCSMapping(CodePageTable, Flags, *WideCharString, *MultiByteString))
1294  {
1295  *MultiByteString = DefChar;
1296  *UsedDefaultChar = TRUE;
1297  }
1298  }
1299 
1300  /* WideCharCount should be 0 if all characters were converted */
1301  if (WideCharCount)
1302  {
1304  return 0;
1305  }
1306 
1307  return MultiByteCount - TempLength;
1308  }
1309 
1310  /* Does caller query for output buffer size? */
1311  if (!MultiByteCount)
1312  return WideCharCount;
1313 
1314  /* Is the buffer large enough? */
1315  if (MultiByteCount < WideCharCount)
1316  {
1317  /* Convert the string up to MultiByteCount and return 0 */
1318  WideCharCount = MultiByteCount;
1320  nReturn = 0;
1321  }
1322  else
1323  {
1324  /* Otherwise WideCharCount will be the number of converted characters */
1325  nReturn = WideCharCount;
1326  }
1327 
1328  /* Convert the WideCharString to the MultiByteString */
1329  for (TempLength = WideCharCount; --TempLength >= 0; WideCharString++, MultiByteString++)
1330  {
1331  *MultiByteString = ((PCHAR)CodePageTable->WideCharTable)[*WideCharString];
1332  }
1333 
1334  return nReturn;
1335  }
1336 }
signed char * PCHAR
Definition: retypes.h:7
#define ERROR_INVALID_PARAMETER
Definition: compat.h:101
#define TRUE
Definition: types.h:120
char CHAR
Definition: xmlstorage.h:175
uint16_t * PWCHAR
Definition: typedefs.h:56
int32_t INT
Definition: typedefs.h:58
#define FALSE
Definition: types.h:117
unsigned int BOOL
Definition: ntddk_ex.h:94
PVOID WideCharTable
Definition: precomp.h:41
static BOOL IntIsValidSBCSMapping(PCPTABLEINFO CodePageTable, DWORD Flags, WCHAR wch, UCHAR ch)
Definition: nls.c:1013
unsigned char
Definition: typeof.h:29
USHORT TransDefaultChar
Definition: precomp.h:36
#define PCHAR
Definition: match.c:90
USHORT DBCSCodePage
Definition: precomp.h:38
_Must_inspect_result_ _In_ ULONG Flags
Definition: wsk.h:170
PCODEPAGE_ENTRY FASTCALL IntGetCodePageEntry(UINT CodePage)
Definition: nls.c:213
#define for
Definition: utility.h:88
#define SetLastError(x)
Definition: compat.h:611
static BOOL IntIsValidDBCSMapping(PCPTABLEINFO CodePageTable, DWORD Flags, WCHAR wch, USHORT ch)
Definition: nls.c:1036
Definition: kernel32.h:62
#define WC_COMPOSITECHECK
Definition: unicode.h:43
unsigned short USHORT
Definition: pedump.c:61
#define NULL
Definition: types.h:112
*BytesInMultiByteString PCHAR MultiByteString
Definition: rtlfuncs.h:1527
_Out_ PCPTABLEINFO CodePageTable
Definition: rtlfuncs.h:4291
#define DPRINT
Definition: sndvol32.h:71
#define CHAR(Char)
unsigned short * PUSHORT
Definition: retypes.h:2
CPTABLEINFO CodePageTable
Definition: kernel32.h:68
#define ERROR_INSUFFICIENT_BUFFER
Definition: dderror.h:10

Referenced by WideCharToMultiByte().

◆ IntWideCharToMultiByteSYMBOL()

static INT WINAPI IntWideCharToMultiByteSYMBOL ( DWORD  Flags,
LPCWSTR  WideCharString,
INT  WideCharCount,
LPSTR  MultiByteString,
INT  MultiByteCount 
)
static

Definition at line 822 of file nls.c.

827 {
828  LONG Count;
829  INT MaxLen;
830  WCHAR Char;
831 
832  if (Flags!=0)
833  {
835  return 0;
836  }
837 
838 
839  if (MultiByteCount == 0)
840  {
841  return WideCharCount;
842  }
843 
844  MaxLen = MultiByteCount > WideCharCount ? WideCharCount : MultiByteCount;
845  for (Count = 0; Count < MaxLen; Count++)
846  {
847  Char = WideCharString[Count];
848  if (Char < 0x20)
849  {
850  MultiByteString[Count] = (CHAR)Char;
851  }
852  else
853  {
854  if ((Char >= 0xf020) && (Char < 0xf100))
855  {
856  MultiByteString[Count] = Char - 0xf000;
857  }
858  else
859  {
861  return 0;
862  }
863  }
864  }
865 
866  if (WideCharCount > MaxLen)
867  {
869  return 0;
870  }
871  return MaxLen;
872 }
#define ERROR_INVALID_PARAMETER
Definition: compat.h:101
int32_t INT
Definition: typedefs.h:58
long LONG
Definition: pedump.c:60
int Count
Definition: noreturn.cpp:7
_Must_inspect_result_ _In_ ULONG Flags
Definition: wsk.h:170
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define SetLastError(x)
Definition: compat.h:611
#define ERROR_NO_UNICODE_TRANSLATION
Definition: winerror.h:649
*BytesInMultiByteString PCHAR MultiByteString
Definition: rtlfuncs.h:1527
#define CHAR(Char)
#define ERROR_INSUFFICIENT_BUFFER
Definition: dderror.h:10

Referenced by WideCharToMultiByte().

◆ IntWideCharToMultiByteUTF8()

static INT WINAPI IntWideCharToMultiByteUTF8 ( UINT  CodePage,
DWORD  Flags,
LPCWSTR  WideCharString,
INT  WideCharCount,
LPSTR  MultiByteString,
INT  MultiByteCount,
LPCSTR  DefaultChar,
LPBOOL  UsedDefaultChar 
)
static

Definition at line 884 of file nls.c.

892 {
893  INT TempLength;
894  DWORD Char;
895 
896  if (Flags)
897  {
899  return 0;
900  }
901 
902  /* Does caller query for output buffer size? */
903  if (MultiByteCount == 0)
904  {
905  for (TempLength = 0; WideCharCount;
906  WideCharCount--, WideCharString++)
907  {
908  TempLength++;
909  if (*WideCharString >= 0x80)
910  {
911  TempLength++;
912  if (*WideCharString >= 0x800)
913  {
914  TempLength++;
915  if (*WideCharString >= 0xd800 && *WideCharString < 0xdc00 &&
916  WideCharCount >= 1 &&
917  WideCharString[1] >= 0xdc00 && WideCharString[1] <= 0xe000)
918  {
919  WideCharCount--;
920  WideCharString++;
921  TempLength++;
922  }
923  }
924  }
925  }
926  return TempLength;
927  }
928 
929  for (TempLength = MultiByteCount; WideCharCount; WideCharCount--, WideCharString++)
930  {
931  Char = *WideCharString;
932  if (Char < 0x80)
933  {
934  if (!TempLength)
935  {
937  break;
938  }
939  TempLength--;
940  *MultiByteString++ = (CHAR)Char;
941  continue;
942  }
943 
944  if (Char < 0x800) /* 0x80-0x7ff: 2 bytes */
945  {
946  if (TempLength < 2)
947  {
949  break;
950  }
951  MultiByteString[1] = 0x80 | (Char & 0x3f); Char >>= 6;
952  MultiByteString[0] = 0xc0 | Char;
953  MultiByteString += 2;
954  TempLength -= 2;
955  continue;
956  }
957 
958  /* surrogate pair 0x10000-0x10ffff: 4 bytes */
959  if (Char >= 0xd800 && Char < 0xdc00 &&
960  WideCharCount >= 1 &&
961  WideCharString[1] >= 0xdc00 && WideCharString[1] < 0xe000)
962  {
963  WideCharCount--;
964  WideCharString++;
965 
966  if (TempLength < 4)
967  {
969  break;
970  }
971 
972  Char = (Char - 0xd800) << 10;
973  Char |= *WideCharString - 0xdc00;
974  ASSERT(Char <= 0xfffff);
975  Char += 0x10000;
976  ASSERT(Char <= 0x10ffff);
977 
978  MultiByteString[3] = 0x80 | (Char & 0x3f); Char >>= 6;
979  MultiByteString[2] = 0x80 | (Char & 0x3f); Char >>= 6;
980  MultiByteString[1] = 0x80 | (Char & 0x3f); Char >>= 6;
981  MultiByteString[0] = 0xf0 | Char;
982  MultiByteString += 4;
983  TempLength -= 4;
984  continue;
985  }
986 
987  /* 0x800-0xffff: 3 bytes */
988  if (TempLength < 3)
989  {
991  break;
992  }
993  MultiByteString[2] = 0x80 | (Char & 0x3f); Char >>= 6;
994  MultiByteString[1] = 0x80 | (Char & 0x3f); Char >>= 6;
995  MultiByteString[0] = 0xe0 | Char;
996  MultiByteString += 3;
997  TempLength -= 3;
998  }
999 
1000  return MultiByteCount - TempLength;
1001 }
int32_t INT
Definition: typedefs.h:58
_Must_inspect_result_ _In_ ULONG Flags
Definition: wsk.h:170
#define ASSERT(a)
Definition: mode.c:44
unsigned long DWORD
Definition: ntddk_ex.h:95
#define SetLastError(x)
Definition: compat.h:611
*BytesInMultiByteString PCHAR MultiByteString
Definition: rtlfuncs.h:1527
#define CHAR(Char)
#define ERROR_INVALID_FLAGS
Definition: winerror.h:583
#define ERROR_INSUFFICIENT_BUFFER
Definition: dderror.h:10

Referenced by WideCharToMultiByte().

◆ IsDBCSLeadByte()

BOOL WINAPI IsDBCSLeadByte ( BYTE  TestByte)

◆ IsDBCSLeadByteEx()

BOOL WINAPI IsDBCSLeadByteEx ( UINT  CodePage,
BYTE  TestByte 
)

Definition at line 2248 of file nls.c.

2249 {
2250  PCODEPAGE_ENTRY CodePageEntry;
2251 
2252  CodePageEntry = IntGetCodePageEntry(CodePage);
2253  if (CodePageEntry != NULL)
2254  return IntIsLeadByte(&CodePageEntry->CodePageTable, TestByte);
2255 
2257  return FALSE;
2258 }
#define ERROR_INVALID_PARAMETER
Definition: compat.h:101
#define FALSE
Definition: types.h:117
PCODEPAGE_ENTRY FASTCALL IntGetCodePageEntry(UINT CodePage)
Definition: nls.c:213
static BOOL WINAPI IntIsLeadByte(PCPTABLEINFO TableInfo, BYTE Byte)
Definition: nls.c:1347
#define SetLastError(x)
Definition: compat.h:611
Definition: kernel32.h:62
#define NULL
Definition: types.h:112
CPTABLEINFO CodePageTable
Definition: kernel32.h:68

Referenced by CharNextExA(), dbcs_mblen(), Global_Chr(), IchWideFromAnsi(), Imm32CompAttrAnsiToWide(), METADC_ExtTextOut(), MFDRV_ExtTextOut(), START_TEST(), test_bitmap_font_glyph_index(), test_text_metrics(), and test_threadcp().

◆ IsNLSDefinedString()

BOOL WINAPI IsNLSDefinedString ( IN NLS_FUNCTION  Function,
IN DWORD  dwFlags,
IN LPNLSVERSIONINFO  lpVersionInformation,
IN LPCWSTR  lpString,
IN INT  cchStr 
)

Definition at line 2711 of file nls.c.

2716 {
2717  STUB;
2718  return TRUE;
2719 }
#define TRUE
Definition: types.h:120
#define STUB
Definition: kernel32.h:27

◆ IsValidCodePage()

BOOL WINAPI IsValidCodePage ( UINT  CodePage)

Definition at line 1515 of file nls.c.

1516 {
1517  if (CodePage == 0) return FALSE;
1518  if (CodePage == CP_UTF8 || CodePage == CP_UTF7)
1519  return TRUE;
1520  if (IntGetLoadedCodePageEntry(CodePage))
1521  return TRUE;
1522  return GetCPFileNameFromRegistry(CodePage, NULL, 0);
1523 }
#define CP_UTF7
Definition: winnls.h:235
#define TRUE
Definition: types.h:120
PCODEPAGE_ENTRY FASTCALL IntGetLoadedCodePageEntry(UINT CodePage)
Definition: nls.c:177
#define CP_UTF8
Definition: nls.h:20
#define FALSE
Definition: types.h:117
BOOL WINAPI GetCPFileNameFromRegistry(UINT CodePage, LPWSTR FileName, ULONG FileNameSize)
Definition: nls.c:1439
#define NULL
Definition: types.h:112

Referenced by AddCodePage(), ChangeOutputCP_(), ConCfgReadUserSettings(), ConDrvInitConsole(), ConDrvSetConsoleCP(), ConSrvApplyUserSettings(), fnIMultiLanguage3_ValidateCodePageEx(), make_csconv(), match_name_table_language(), MSVCRT_locale_to_LCID(), test_CP_ThreadLang(), test_EnumCodePages(), test_IsCodePageInstallable(), test_string_conversion(), test_undefined_byte_char(), testScreenBuffer(), and validate_codepage().

◆ IsValidUILanguage()

BOOL WINAPI IsValidUILanguage ( LANGID  langid)

Definition at line 2617 of file nls.c.

2618 {
2619  STUB;
2620  return 0;
2621 }
#define STUB
Definition: kernel32.h:27

◆ MultiByteToWideChar()

INT WINAPI MultiByteToWideChar ( UINT  CodePage,
DWORD  Flags,
LPCSTR  MultiByteString,
INT  MultiByteCount,
LPWSTR  WideCharString,
INT  WideCharCount 
)

Definition at line 1674 of file nls.c.

1680 {
1681  /* Check the parameters. */
1682  if (MultiByteString == NULL ||
1683  MultiByteCount == 0 || WideCharCount < 0 ||
1684  (WideCharCount && (WideCharString == NULL ||
1685  (PVOID)MultiByteString == (PVOID)WideCharString)))
1686  {
1688  return 0;
1689  }
1690 
1691  /* Determine the input string length. */
1692  if (MultiByteCount < 0)
1693  {
1694  MultiByteCount = lstrlenA(MultiByteString) + 1;
1695  }
1696 
1697  switch (CodePage)
1698  {
1699  case CP_UTF8:
1702  MultiByteCount,
1703  WideCharString,
1704  WideCharCount);
1705 
1706  case CP_UTF7:
1707  if (Flags)
1708  {
1710  return 0;
1711  }
1712  return Utf7ToWideChar(MultiByteString, MultiByteCount,
1713  WideCharString, WideCharCount);
1714 
1715  case CP_SYMBOL:
1718  MultiByteCount,
1719  WideCharString,
1720  WideCharCount);
1721  default:
1722  return IntMultiByteToWideCharCP(CodePage,
1723  Flags,
1725  MultiByteCount,
1726  WideCharString,
1727  WideCharCount);
1728  }
1729 }
#define ERROR_INVALID_PARAMETER
Definition: compat.h:101
static INT WINAPI IntMultiByteToWideCharUTF8(DWORD Flags, LPCSTR MultiByteString, INT MultiByteCount, LPWSTR WideCharString, INT WideCharCount)
Definition: nls.c:401
static INT Utf7ToWideChar(const char *src, int srclen, WCHAR *dst, int dstlen)
Definition: nls.c:1540
#define CP_UTF7
Definition: winnls.h:235
#define CP_SYMBOL
Definition: winnls.h:234
static INT WINAPI IntMultiByteToWideCharSYMBOL(DWORD Flags, LPCSTR MultiByteString, INT MultiByteCount, LPWSTR WideCharString, INT WideCharCount)
Definition: nls.c:767
#define CP_UTF8
Definition: nls.h:20
_Must_inspect_result_ _In_ ULONG Flags
Definition: wsk.h:170
static INT WINAPI IntMultiByteToWideCharCP(UINT CodePage, DWORD Flags, LPCSTR MultiByteString, INT MultiByteCount, LPWSTR WideCharString, INT WideCharCount)
Definition: nls.c:573
#define SetLastError(x)
Definition: compat.h:611
int WINAPI lstrlenA(LPCSTR lpString)
Definition: lstring.c:145
#define NULL
Definition: types.h:112
*BytesInMultiByteString PCHAR MultiByteString
Definition: rtlfuncs.h:1527
#define ERROR_INVALID_FLAGS
Definition: winerror.h:583

◆ NlsConvertIntegerToString()

VOID WINAPI NlsConvertIntegerToString ( ULONG  Value,
ULONG  Base,
ULONG  strsize,
LPWSTR  str,
ULONG  strsize2 
)

Definition at line 2626 of file nls.c.

2627 {
2628  STUB;
2629 }
#define STUB
Definition: kernel32.h:27

◆ NlsGetCacheUpdateCount()

ULONG WINAPI NlsGetCacheUpdateCount ( VOID  )

Definition at line 2700 of file nls.c.

2701 {
2702  STUB;
2703  return 0;
2704 }
#define STUB
Definition: kernel32.h:27

◆ NlsInit()

BOOL FASTCALL NlsInit ( VOID  )

Definition at line 75 of file nls.c.

76 {
79  PSECURITY_DESCRIPTOR NlsDirSd;
80  HANDLE Handle;
82 
85 
86  /*
87  * FIXME: Eventually this should be done only for the NLS Server
88  * process, but since we don't have anything like that (yet?) we
89  * always try to create the "\Nls" directory here.
90  */
91  RtlInitUnicodeString(&DirName, L"\\Nls");
92 
93  /* Create a security descriptor for NLS directory */
95  if (!NT_SUCCESS(Status))
96  {
97  DPRINT1("Failed to create NLS directory security (Status 0x%08x)\n", Status);
98  return FALSE;
99  }
100 
102  &DirName,
104  NULL,
105  NlsDirSd);
106 
108  {
109  NtClose(Handle);
110  }
111 
112  /* Setup ANSI code page. */
114  AnsiCodePage.SectionMapping = NtCurrentTeb()->ProcessEnvironmentBlock->AnsiCodePageData;
115 
119 
121 
122  /* Setup OEM code page. */
124  OemCodePage.SectionMapping = NtCurrentTeb()->ProcessEnvironmentBlock->OemCodePageData;
125 
130 
131  RtlFreeHeap(RtlGetProcessHeap(), 0, NlsDirSd);
132  return TRUE;
133 }
IN PUNICODE_STRING IN POBJECT_ATTRIBUTES ObjectAttributes
Definition: conport.c:35
static CODEPAGE_ENTRY AnsiCodePage
Definition: nls.c:46
#define OBJ_CASE_INSENSITIVE
Definition: winternl.h:228
#define TRUE
Definition: types.h:120
static LIST_ENTRY CodePageListHead
Definition: nls.c:45
#define DIRECTORY_CREATE_OBJECT
Definition: nt_native.h:1256
LONG NTSTATUS
Definition: precomp.h:26
BOOLEAN NTAPI RtlFreeHeap(IN PVOID HeapHandle, IN ULONG Flags, IN PVOID HeapBase)
Definition: heap.c:606
#define InsertTailList(ListHead, Entry)
#define L(x)
Definition: ntvdm.h:50
#define FALSE
Definition: types.h:117
UINT CodePage
Definition: kernel32.h:65
#define DIRECTORY_TRAVERSE
Definition: nt_native.h:1255
Status
Definition: gdiplustypes.h:24
LIST_ENTRY Entry
Definition: kernel32.h:64
NTSYSAPI NTSTATUS NTAPI RtlInitializeCriticalSection(_In_ PRTL_CRITICAL_SECTION CriticalSection)
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
NTSTATUS NTAPI NtClose(IN HANDLE Handle)
Definition: obhandle.c:3402
USHORT CodePage
Definition: precomp.h:32
static CODEPAGE_ENTRY OemCodePage
Definition: nls.c:47
static RTL_CRITICAL_SECTION CodePageListLock
Definition: nls.c:48
NTSTATUS CreateNlsDirectorySecurity(_Out_ PSECURITY_DESCRIPTOR *NlsSecurityDescriptor)
Creates a security descriptor for the NLS object directory name.
Definition: nls.c:2294
#define OBJ_PERMANENT
Definition: winternl.h:226
VOID NTAPI RtlInitCodePageTable(IN PUSHORT TableBase, OUT PCPTABLEINFO CodePageTable)
Definition: nls.c:155
NTSTATUS NTAPI NtCreateDirectoryObject(OUT PHANDLE DirectoryHandle, IN ACCESS_MASK DesiredAccess, IN POBJECT_ATTRIBUTES ObjectAttributes)
Definition: obdir.c:765
FORCEINLINE struct _TEB * NtCurrentTeb(VOID)
Definition: psfuncs.h:420
#define InitializeListHead(ListHead)
Definition: env_spec_w32.h:944
#define NULL
Definition: types.h:112
PBYTE SectionMapping
Definition: kernel32.h:67
#define DPRINT1
Definition: precomp.h:8
_In_ HANDLE Handle
Definition: extypes.h:390
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
_In_ PFCB _In_ PCD_NAME DirName
Definition: cdprocs.h:736
#define InitializeObjectAttributes(p, n, a, r, s)
Definition: reg.c:106
HANDLE SectionHandle
Definition: kernel32.h:66
unsigned short * PUSHORT
Definition: retypes.h:2
CPTABLEINFO CodePageTable
Definition: kernel32.h:68

Referenced by DllMain().

◆ NlsResetProcessLocale()

BOOL WINAPI NlsResetProcessLocale ( VOID  )

Definition at line 2656 of file nls.c.

2657 {
2658  STUB;
2659  return TRUE;
2660 }
#define TRUE
Definition: types.h:120
#define STUB
Definition: kernel32.h:27

◆ NlsUninit()

VOID FASTCALL NlsUninit ( VOID  )

Definition at line 143 of file nls.c.

144 {
145  PCODEPAGE_ENTRY Current;
146 
147  /* Delete the code page list. */
148  while (!IsListEmpty(&CodePageListHead))
149  {
151  if (Current->SectionHandle != NULL)
152  {
154  NtClose(Current->SectionHandle);
155  }
157  }
159 }
static LIST_ENTRY CodePageListHead
Definition: nls.c:45
_Must_inspect_result_ FORCEINLINE BOOLEAN IsListEmpty(_In_ const LIST_ENTRY *ListHead)
Definition: rtlfuncs.h:57
FORCEINLINE PLIST_ENTRY RemoveHeadList(_Inout_ PLIST_ENTRY ListHead)
Definition: rtlfuncs.h:128
PFLT_MESSAGE_WAITER_QUEUE CONTAINING_RECORD(Csq, DEVICE_EXTENSION, IrpQueue)) -> WaiterQ.mLock) _IRQL_raises_(DISPATCH_LEVEL) VOID NTAPI FltpAcquireMessageWaiterLock(_In_ PIO_CSQ Csq, _Out_ PKIRQL Irql)
Definition: Messaging.c:560
struct _LIST_ENTRY * Flink
Definition: typedefs.h:121
NTSTATUS NTAPI NtClose(IN HANDLE Handle)
Definition: obhandle.c:3402
static RTL_CRITICAL_SECTION CodePageListLock
Definition: nls.c:48
Definition: kernel32.h:62
#define NULL
Definition: types.h:112
PBYTE SectionMapping
Definition: kernel32.h:67
HANDLE SectionHandle
Definition: kernel32.h:66
NTSYSAPI NTSTATUS NTAPI RtlDeleteCriticalSection(_In_ PRTL_CRITICAL_SECTION CriticalSection)
#define UnmapViewOfFile
Definition: compat.h:605
base of all file and directory entries
Definition: entries.h:82

Referenced by DllMain().

◆ SetCPGlobal()

UINT WINAPI SetCPGlobal ( UINT  CodePage)

Definition at line 2634 of file nls.c.

2635 {
2636  STUB;
2637  return 0;
2638 }
#define STUB
Definition: kernel32.h:27

◆ utf7_can_directly_encode()

static BOOL utf7_can_directly_encode ( WCHAR  codepoint)
inlinestatic

Definition at line 1731 of file nls.c.

1732 {
1733  static const BOOL directly_encodable_table[] =
1734  {
1735  1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 1, 0, 0, /* 0x00 - 0x0F */
1736  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x10 - 0x1F */
1737  1, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 1, 1, 1, 1, 1, /* 0x20 - 0x2F */
1738  1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1, /* 0x30 - 0x3F */
1739  0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* 0x40 - 0x4F */
1740  1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, /* 0x50 - 0x5F */
1741  0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* 0x60 - 0x6F */
1742  1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 /* 0x70 - 0x7A */
1743  };
1744 
1745  return codepoint <= 0x7A ? directly_encodable_table[codepoint] : FALSE;
1746 }
#define FALSE
Definition: types.h:117
unsigned int BOOL
Definition: ntddk_ex.h:94

Referenced by WideCharToUtf7().

◆ utf7_write_c()

static BOOL utf7_write_c ( char dst,
int  dstlen,
int index,
char  character 
)
inlinestatic

Definition at line 1748 of file nls.c.

1749 {
1750  if (dstlen > 0)
1751  {
1752  if (*index >= dstlen)
1753  return FALSE;
1754 
1755  dst[*index] = character;
1756  }
1757 
1758  (*index)++;
1759 
1760  return TRUE;
1761 }
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
GLuint index
Definition: glext.h:6031
#define index(s, c)
Definition: various.h:29
static DWORD dstlen
Definition: directory.c:51
GLenum GLenum dst
Definition: glext.h:6340

Referenced by WideCharToUtf7().

◆ utf7_write_w()

static BOOL utf7_write_w ( WCHAR dst,
int  dstlen,
int index,
WCHAR  character 
)
inlinestatic

Definition at line 1525 of file nls.c.

1526 {
1527  if (dstlen > 0)
1528  {
1529  if (*index >= dstlen)
1530  return FALSE;
1531 
1532  dst[*index] = character;
1533  }
1534 
1535  (*index)++;
1536 
1537  return TRUE;
1538 }
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
GLuint index
Definition: glext.h:6031
#define index(s, c)
Definition: various.h:29
static DWORD dstlen
Definition: directory.c:51
GLenum GLenum dst
Definition: glext.h:6340

Referenced by Utf7ToWideChar().

◆ Utf7ToWideChar()

static INT Utf7ToWideChar ( const char src,
int  srclen,
WCHAR dst,
int  dstlen 
)
static

Definition at line 1540 of file nls.c.

1541 {
1542  static const signed char base64_decoding_table[] =
1543  {
1544  -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 0x00-0x0F */
1545  -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 0x10-0x1F */
1546  -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 62, -1, -1, -1, 63, /* 0x20-0x2F */
1547  52, 53, 54, 55, 56, 57, 58, 59, 60, 61, -1, -1, -1, -1, -1, -1, /* 0x30-0x3F */
1548  -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, /* 0x40-0x4F */
1549  15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, -1, -1, -1, -1, -1, /* 0x50-0x5F */
1550  -1, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, /* 0x60-0x6F */
1551  41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, -1, -1, -1, -1, -1 /* 0x70-0x7F */
1552  };
1553 
1554  const char *source_end = src + srclen;
1555  int dest_index = 0;
1556 
1557  DWORD byte_pair = 0;
1558  short offset = 0;
1559 
1560  while (src < source_end)
1561  {
1562  if (*src == '+')
1563  {
1564  src++;
1565  if (src >= source_end)
1566  break;
1567 
1568  if (*src == '-')
1569  {
1570  /* just a plus sign escaped as +- */
1571  if (!utf7_write_w(dst, dstlen, &dest_index, '+'))
1572  {
1574  return 0;
1575  }
1576  src++;
1577  continue;
1578  }
1579 
1580  do
1581  {
1582  signed char sextet = *src;
1583  if (sextet == '-')
1584  {
1585  /* skip over the dash and end base64 decoding
1586  * the current, unfinished byte pair is discarded */
1587  src++;
1588  offset = 0;
1589  break;
1590  }
1591  if (sextet < 0)
1592  {
1593  /* the next character of src is < 0 and therefore not part of a base64 sequence
1594  * the current, unfinished byte pair is NOT discarded in this case
1595  * this is probably a bug in Windows */
1596  break;
1597  }
1598 
1599  sextet = base64_decoding_table[sextet];
1600  if (sextet == -1)
1601  {
1602  /* -1 means that the next character of src is not part of a base64 sequence
1603  * in other words, all sextets in this base64 sequence have been processed
1604  * the current, unfinished byte pair is discarded */
1605  offset = 0;
1606  break;
1607  }
1608 
1609  byte_pair = (byte_pair << 6) | sextet;
1610  offset += 6;
1611 
1612  if (offset >= 16)
1613  {
1614  /* this byte pair is done */
1615  if (!utf7_write_w(dst, dstlen, &dest_index, (byte_pair >> (offset - 16)) & 0xFFFF))
1616  {
1618  return 0;
1619  }
1620  offset -= 16;
1621  }
1622 
1623  src++;
1624  }
1625  while (src < source_end);
1626  }
1627  else
1628  {
1629  /* we have to convert to unsigned char in case *src < 0 */
1630  if (!utf7_write_w(dst, dstlen, &dest_index, (unsigned char)*src))
1631  {
1633  return 0;
1634  }
1635  src++;
1636  }
1637  }
1638 
1639  return dest_index;
1640 }
GLintptr offset
Definition: glext.h:5920
static DWORD LPDWORD LPCSTR DWORD srclen
Definition: directory.c:51
unsigned long DWORD
Definition: ntddk_ex.h:95
#define SetLastError(x)
Definition: compat.h:611
GLenum src
Definition: glext.h:6340
static DWORD dstlen
Definition: directory.c:51
GLenum GLenum dst
Definition: glext.h:6340
static BOOL utf7_write_w(WCHAR *dst, int dstlen, int *index, WCHAR character)
Definition: nls.c:1525
#define ERROR_INSUFFICIENT_BUFFER
Definition: dderror.h:10

Referenced by MultiByteToWideChar().

◆ ValidateLCType()

BOOL WINAPI ValidateLCType ( int  a1,
unsigned int  a2,
int  a3,
int  a4 
)

Definition at line 2645 of file nls.c.

2646 {
2647  STUB;
2648  return FALSE;
2649 }
#define FALSE
Definition: types.h:117
#define STUB
Definition: kernel32.h:27

◆ ValidateLocale()

BOOL WINAPI ValidateLocale ( IN ULONG  LocaleId)

Definition at line 2689 of file nls.c.

2690 {
2691  STUB;
2692  return TRUE;
2693 }
#define TRUE
Definition: types.h:120
#define STUB
Definition: kernel32.h:27

◆ WideCharToMultiByte()

INT WINAPI WideCharToMultiByte ( UINT  CodePage,
DWORD  Flags,
LPCWSTR  WideCharString,
INT  WideCharCount,
LPSTR  MultiByteString,
INT  MultiByteCount,
LPCSTR  DefaultChar,
LPBOOL  UsedDefaultChar 
)

Definition at line 2127 of file nls.c.

2135 {
2136  /* Check the parameters. */
2137  if (WideCharString == NULL ||
2138  WideCharCount == 0 ||
2139  (MultiByteString == NULL && MultiByteCount > 0) ||
2140  (PVOID)WideCharString == (PVOID)MultiByteString ||
2141  MultiByteCount < 0)
2142  {
2144  return 0;
2145  }
2146 
2147  /* Determine the input string length. */
2148  if (WideCharCount < 0)
2149  {
2150  WideCharCount = lstrlenW(WideCharString) + 1;
2151  }
2152 
2153  switch (CodePage)
2154  {
2155  case CP_UTF8:
2156  if (DefaultChar != NULL || UsedDefaultChar != NULL)
2157  {
2159  return 0;
2160  }
2161  return IntWideCharToMultiByteUTF8(CodePage,
2162  Flags,
2163  WideCharString,
2164  WideCharCount,
2166  MultiByteCount,
2167  DefaultChar,
2168  UsedDefaultChar);
2169 
2170  case CP_UTF7:
2171  if (DefaultChar != NULL || UsedDefaultChar != NULL)
2172  {
2174  return 0;
2175  }
2176  if (Flags)
2177  {
2179  return 0;
2180  }
2181  return WideCharToUtf7(WideCharString, WideCharCount,
2182  MultiByteString, MultiByteCount);
2183 
2184  case CP_SYMBOL:
2185  if ((DefaultChar!=NULL) || (UsedDefaultChar!=NULL))
2186  {
2188  return 0;
2189  }
2191  WideCharString,
2192  WideCharCount,
2194  MultiByteCount);
2195 
2196  default:
2197  return IntWideCharToMultiByteCP(CodePage,
2198  Flags,
2199  WideCharString,
2200  WideCharCount,
2202  MultiByteCount,
2203  DefaultChar,
2204  UsedDefaultChar);
2205  }
2206 }
#define ERROR_INVALID_PARAMETER
Definition: compat.h:101
static INT WideCharToUtf7(const WCHAR *src, int srclen, char *dst, int dstlen)
Definition: nls.c:1763
#define CP_UTF7
Definition: winnls.h:235
static INT WINAPI IntWideCharToMultiByteSYMBOL(DWORD Flags, LPCWSTR WideCharString, INT WideCharCount, LPSTR MultiByteString, INT MultiByteCount)
Definition: nls.c:822
#define lstrlenW
Definition: compat.h:609
#define CP_SYMBOL
Definition: winnls.h:234
static INT WINAPI IntWideCharToMultiByteUTF8(UINT CodePage, DWORD Flags, LPCWSTR WideCharString, INT WideCharCount, LPSTR MultiByteString, INT MultiByteCount, LPCSTR DefaultChar, LPBOOL UsedDefaultChar)
Definition: nls.c:884
#define CP_UTF8
Definition: nls.h:20
_Must_inspect_result_ _In_ ULONG Flags
Definition: wsk.h:170
#define SetLastError(x)
Definition: compat.h:611
static INT WINAPI IntWideCharToMultiByteCP(UINT CodePage, DWORD Flags, LPCWSTR WideCharString, INT WideCharCount, LPSTR MultiByteString, INT MultiByteCount, LPCSTR DefaultChar, LPBOOL UsedDefaultChar)
Definition: nls.c:1070
#define NULL
Definition: types.h:112
*BytesInMultiByteString PCHAR MultiByteString
Definition: rtlfuncs.h:1527
#define ERROR_INVALID_FLAGS
Definition: winerror.h:583

Referenced by GetCPInfoExA().

◆ WideCharToUtf7()

static INT WideCharToUtf7 ( const WCHAR src,
int  srclen,
char dst,
int  dstlen 
)
static

Definition at line 1763 of file nls.c.

1764 {
1765  static const char base64_encoding_table[] =
1766  "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
1767 
1768  const WCHAR *source_end = src + srclen;
1769  int dest_index = 0;
1770 
1771  while (src < source_end)
1772  {
1773  if (*src == '+')
1774  {
1775  if (!utf7_write_c(dst, dstlen, &dest_index, '+'))
1776  {
1778  return 0;
1779  }
1780  if (!utf7_write_c(dst, dstlen, &dest_index, '-'))
1781  {
1783  return 0;
1784  }
1785  src++;
1786  }
1787  else if (utf7_can_directly_encode(*src))
1788  {
1789  if (!utf7_write_c(dst, dstlen, &dest_index, *src))
1790  {
1792  return 0;
1793  }
1794  src++;
1795  }
1796  else
1797  {
1798  unsigned int offset = 0;
1799  DWORD byte_pair = 0;
1800 
1801  if (!utf7_write_c(dst, dstlen, &dest_index, '+'))
1802  {
1804  return 0;
1805  }
1806 
1807  while (src < source_end && !utf7_can_directly_encode(*src))
1808  {
1809  byte_pair = (byte_pair << 16) | *src;
1810  offset += 16;
1811  while (offset >= 6)
1812  {
1813  if (!utf7_write_c(dst, dstlen, &dest_index, base64_encoding_table[(byte_pair >> (offset - 6)) & 0x3F]))
1814  {
1816  return 0;
1817  }
1818  offset -= 6;
1819  }
1820  src++;
1821  }
1822 
1823  if (offset)
1824  {
1825  /* Windows won't create a padded base64 character if there's no room for the - sign
1826  * as well ; this is probably a bug in Windows */
1827  if (dstlen > 0 && dest_index + 1 >= dstlen)
1828  {
1830  return 0;
1831  }
1832 
1833  byte_pair <<= (6 - offset);
1834  if (!utf7_write_c(dst, dstlen, &dest_index, base64_encoding_table[byte_pair & 0x3F]))
1835  {
1837  return 0;
1838  }
1839  }
1840 
1841  /* Windows always explicitly terminates the base64 sequence
1842  even though RFC 2152 (page 3, rule 2) does not require this */
1843  if (!utf7_write_c(dst, dstlen, &dest_index, '-'))
1844  {
1846  return 0;
1847  }
1848  }
1849  }
1850 
1851  return dest_index;
1852 }
static BOOL utf7_write_c(char *dst, int dstlen, int *index, char character)
Definition: nls.c:1748
__wchar_t WCHAR
Definition: xmlstorage.h:180
GLintptr offset
Definition: glext.h:5920
static DWORD LPDWORD LPCSTR DWORD srclen
Definition: directory.c:51
unsigned long DWORD
Definition: ntddk_ex.h:95
#define SetLastError(x)
Definition: compat.h:611
GLenum src
Definition: glext.h:6340
static DWORD dstlen
Definition: directory.c:51
GLenum GLenum dst
Definition: glext.h:6340
static BOOL utf7_can_directly_encode(WCHAR codepoint)
Definition: nls.c:1731
#define ERROR_INSUFFICIENT_BUFFER
Definition: dderror.h:10

Referenced by WideCharToMultiByte().

Variable Documentation

◆ AnsiCodePage

CODEPAGE_ENTRY AnsiCodePage
static

◆ CodePageListHead

LIST_ENTRY CodePageListHead
static

Definition at line 45 of file nls.c.

Referenced by IntGetCodePageEntry(), IntGetLoadedCodePageEntry(), NlsInit(), and NlsUninit().

◆ CodePageListLock

RTL_CRITICAL_SECTION CodePageListLock
static

Definition at line 48 of file nls.c.

Referenced by IntGetCodePageEntry(), IntGetLoadedCodePageEntry(), NlsInit(), and NlsUninit().

◆ OemCodePage

◆ UTF8LBound

const unsigned long UTF8LBound[]
static
Initial value:
=
{0, 0x80, 0x800, 0x10000, 0x200000, 0x2000000, 0xFFFFFFFF}

Definition at line 41 of file nls.c.

Referenced by IntMultiByteToWideCharUTF8().

◆ UTF8Length

const char UTF8Length[128]
static
Initial value:
=
{
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
3, 3, 3, 3, 3, 3, 3, 3, 0, 0, 0, 0, 0, 0, 0, 0
}

Definition at line 25 of file nls.c.

Referenced by IntMultiByteToWideCharUTF8().

◆ UTF8Mask

const unsigned char UTF8Mask[6] = {0x7f, 0x1f, 0x0f, 0x07, 0x03, 0x01}
static

Definition at line 38 of file nls.c.

Referenced by IntMultiByteToWideCharUTF8().