2007-11-08 21:06:20 +00:00
|
|
|
#include <ndk/umtypes.h>
|
|
|
|
#include <ndk/rtlfuncs.h>
|
|
|
|
|
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
|
|
|
int wctomb (char *mbchar, wchar_t wchar)
|
|
|
|
{
|
|
|
|
NTSTATUS Status;
|
|
|
|
ULONG Size;
|
|
|
|
|
|
|
|
if (mbchar == NULL)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
Status = RtlUnicodeToMultiByteN (mbchar,
|
|
|
|
1,
|
|
|
|
&Size,
|
|
|
|
&wchar,
|
|
|
|
sizeof(WCHAR));
|
|
|
|
if (!NT_SUCCESS(Status))
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
return (int)Size;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
|
|
|
size_t wcstombs (char *mbstr, const wchar_t *wcstr, size_t count)
|
|
|
|
{
|
|
|
|
NTSTATUS Status;
|
|
|
|
ULONG Size;
|
|
|
|
ULONG Length;
|
|
|
|
|
2011-09-15 17:11:53 +00:00
|
|
|
Length = (ULONG)wcslen (wcstr);
|
2007-11-08 21:06:20 +00:00
|
|
|
|
|
|
|
if (mbstr == NULL)
|
|
|
|
{
|
|
|
|
RtlUnicodeToMultiByteSize (&Size,
|
|
|
|
(wchar_t*)((size_t)wcstr),
|
|
|
|
Length * sizeof(WCHAR));
|
|
|
|
|
2015-10-25 09:28:57 +00:00
|
|
|
return (size_t)(Size / sizeof(char));
|
2007-11-08 21:06:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Status = RtlUnicodeToMultiByteN (mbstr,
|
2011-09-15 17:11:53 +00:00
|
|
|
(ULONG)count,
|
2007-11-08 21:06:20 +00:00
|
|
|
&Size,
|
|
|
|
(wchar_t*)((size_t)wcstr),
|
|
|
|
Length * sizeof(WCHAR));
|
|
|
|
if (!NT_SUCCESS(Status))
|
|
|
|
return -1;
|
|
|
|
|
2015-10-25 09:28:57 +00:00
|
|
|
return (size_t)(Size / sizeof(char));
|
2007-11-08 21:06:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* EOF */
|