ReactOS  0.4.15-dev-3163-gf17c2c0
mbstowcs_nt.c
Go to the documentation of this file.
1 #include <ndk/umtypes.h>
2 #include <ndk/rtlfuncs.h>
3 #include <string.h>
4 
5 #undef MB_CUR_MAX
6 #define MB_CUR_MAX 2
7 
8 /*
9  * @implemented
10  */
11 int mbtowc (wchar_t *wchar, const char *mbchar, size_t count)
12 {
13  UCHAR mbarr[MB_CUR_MAX] = { 0 };
14  PUCHAR mbs = mbarr;
15  WCHAR wc;
16 
17  if (mbchar == NULL)
18  return 0;
19 
20  if (wchar == NULL)
21  return 0;
22 
23  memcpy(mbarr, mbchar, min(count, sizeof mbarr));
24 
26 
27  if (wc == L' ' && mbarr[0] != ' ')
28  return -1;
29 
30  *wchar = wc;
31 
32  return (int)(mbs - mbarr);
33 }
34 
35 /*
36  * @implemented
37  */
38 size_t mbstowcs (wchar_t *wcstr, const char *mbstr, size_t count)
39 {
41  ULONG Size;
42  ULONG Length;
43 
44  Length = (ULONG)strlen (mbstr);
45 
46  if (wcstr == NULL)
47  {
49  mbstr,
50  Length);
51 
52  return (size_t)(Size / sizeof(wchar_t));
53  }
54 
56  (ULONG)count * sizeof(WCHAR),
57  &Size,
58  mbstr,
59  Length);
60  if (!NT_SUCCESS(Status))
61  return -1;
62 
63  return (size_t)(Size / sizeof(wchar_t));
64 }
65 
66 /* EOF */
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
int mbtowc(wchar_t *wchar, const char *mbchar, size_t count)
Definition: mbstowcs_nt.c:11
GLuint GLuint GLsizei count
Definition: gl.h:1545
unsigned char * PUCHAR
Definition: retypes.h:3
LONG NTSTATUS
Definition: precomp.h:26
NTSYSAPI WCHAR WINAPI RtlAnsiCharToUnicodeChar(LPSTR *)
NTSYSAPI NTSTATUS WINAPI RtlMultiByteToUnicodeSize(DWORD *, LPCSTR, UINT)
IN PVOID IN PVOID IN USHORT IN USHORT Size
Definition: pci.h:361
size_t mbstowcs(wchar_t *wcstr, const char *mbstr, size_t count)
Definition: mbstowcs_nt.c:38
Status
Definition: gdiplustypes.h:24
NTSYSAPI NTSTATUS WINAPI RtlMultiByteToUnicodeN(LPWSTR, DWORD, LPDWORD, LPCSTR, DWORD)
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
unsigned char UCHAR
Definition: xmlstorage.h:181
static const WCHAR L[]
Definition: oid.c:1250
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
#define min(a, b)
Definition: monoChain.cc:55
#define MB_CUR_MAX
Definition: mbstowcs_nt.c:6
#define NULL
Definition: types.h:112
unsigned int ULONG
Definition: retypes.h:1
#define wchar_t
Definition: wchar.h:102
char mbs[5]