2007-11-08 21:06:20 +00:00
|
|
|
#include <ndk/umtypes.h>
|
|
|
|
#include <ndk/rtlfuncs.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
2011-03-09 15:29:13 +00:00
|
|
|
#undef MB_CUR_MAX
|
|
|
|
#define MB_CUR_MAX 2
|
|
|
|
|
2007-11-08 21:06:20 +00:00
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
|
|
|
int mbtowc (wchar_t *wchar, const char *mbchar, size_t count)
|
|
|
|
{
|
2011-03-09 15:29:13 +00:00
|
|
|
UCHAR mbarr[MB_CUR_MAX] = { 0 };
|
|
|
|
PUCHAR mbs = mbarr;
|
|
|
|
WCHAR wc;
|
|
|
|
|
|
|
|
if (mbchar == NULL)
|
|
|
|
return 0;
|
2007-11-08 21:06:20 +00:00
|
|
|
|
|
|
|
if (wchar == NULL)
|
|
|
|
return 0;
|
|
|
|
|
2011-03-09 15:29:13 +00:00
|
|
|
memcpy(mbarr, mbchar, min(count, sizeof mbarr));
|
|
|
|
|
|
|
|
wc = RtlAnsiCharToUnicodeChar(&mbs);
|
|
|
|
|
|
|
|
if (wc == L' ' && mbarr[0] != ' ')
|
2007-11-08 21:06:20 +00:00
|
|
|
return -1;
|
|
|
|
|
2011-03-09 15:29:13 +00:00
|
|
|
*wchar = wc;
|
|
|
|
|
2011-09-15 17:11:53 +00:00
|
|
|
return (int)(mbs - mbarr);
|
2007-11-08 21:06:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
|
|
|
size_t mbstowcs (wchar_t *wcstr, const char *mbstr, size_t count)
|
|
|
|
{
|
|
|
|
NTSTATUS Status;
|
|
|
|
ULONG Size;
|
|
|
|
ULONG Length;
|
|
|
|
|
2011-09-15 17:11:53 +00:00
|
|
|
Length = (ULONG)strlen (mbstr);
|
2007-11-08 21:06:20 +00:00
|
|
|
|
|
|
|
if (wcstr == NULL)
|
|
|
|
{
|
|
|
|
RtlMultiByteToUnicodeSize (&Size,
|
|
|
|
mbstr,
|
|
|
|
Length);
|
|
|
|
|
2015-10-25 09:28:57 +00:00
|
|
|
return (size_t)(Size / sizeof(wchar_t));
|
2007-11-08 21:06:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Status = RtlMultiByteToUnicodeN (wcstr,
|
2011-09-15 17:11:53 +00:00
|
|
|
(ULONG)count * sizeof(WCHAR),
|
2007-11-08 21:06:20 +00:00
|
|
|
&Size,
|
|
|
|
mbstr,
|
|
|
|
Length);
|
|
|
|
if (!NT_SUCCESS(Status))
|
|
|
|
return -1;
|
|
|
|
|
2015-10-25 11:11:34 +00:00
|
|
|
return (size_t)(Size / sizeof(wchar_t));
|
2007-11-08 21:06:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* EOF */
|