mirror of
https://github.com/reactos/reactos.git
synced 2025-08-06 15:43:19 +00:00
This really needs to go in a branch. It needs heavy testing and can't coincide with the current shell32 due to PSDK interface changes
svn path=/branches/shell32_new-bringup/; revision=51893
This commit is contained in:
parent
4596e5e59b
commit
4019caae75
23116 changed files with 0 additions and 1109022 deletions
69
lib/sdk/crt/string/mbstowcs_nt.c
Normal file
69
lib/sdk/crt/string/mbstowcs_nt.c
Normal file
|
@ -0,0 +1,69 @@
|
|||
#define WIN32_NO_STATUS
|
||||
#include <windows.h>
|
||||
#include <ndk/umtypes.h>
|
||||
#include <ndk/rtlfuncs.h>
|
||||
#include <string.h>
|
||||
|
||||
WCHAR NTAPI RtlAnsiCharToUnicodeChar(IN OUT PUCHAR *AnsiChar);
|
||||
#undef MB_CUR_MAX
|
||||
#define MB_CUR_MAX 2
|
||||
|
||||
/*
|
||||
* @implemented
|
||||
*/
|
||||
int mbtowc (wchar_t *wchar, const char *mbchar, size_t count)
|
||||
{
|
||||
UCHAR mbarr[MB_CUR_MAX] = { 0 };
|
||||
PUCHAR mbs = mbarr;
|
||||
WCHAR wc;
|
||||
|
||||
if (mbchar == NULL)
|
||||
return 0;
|
||||
|
||||
if (wchar == NULL)
|
||||
return 0;
|
||||
|
||||
memcpy(mbarr, mbchar, min(count, sizeof mbarr));
|
||||
|
||||
wc = RtlAnsiCharToUnicodeChar(&mbs);
|
||||
|
||||
if (wc == L' ' && mbarr[0] != ' ')
|
||||
return -1;
|
||||
|
||||
*wchar = wc;
|
||||
|
||||
return mbs - mbarr;
|
||||
}
|
||||
|
||||
/*
|
||||
* @implemented
|
||||
*/
|
||||
size_t mbstowcs (wchar_t *wcstr, const char *mbstr, size_t count)
|
||||
{
|
||||
NTSTATUS Status;
|
||||
ULONG Size;
|
||||
ULONG Length;
|
||||
|
||||
Length = strlen (mbstr);
|
||||
|
||||
if (wcstr == NULL)
|
||||
{
|
||||
RtlMultiByteToUnicodeSize (&Size,
|
||||
mbstr,
|
||||
Length);
|
||||
|
||||
return (size_t)Size;
|
||||
}
|
||||
|
||||
Status = RtlMultiByteToUnicodeN (wcstr,
|
||||
count * sizeof(WCHAR),
|
||||
&Size,
|
||||
mbstr,
|
||||
Length);
|
||||
if (!NT_SUCCESS(Status))
|
||||
return -1;
|
||||
|
||||
return (size_t)Size;
|
||||
}
|
||||
|
||||
/* EOF */
|
Loading…
Add table
Add a link
Reference in a new issue