Merge from branch ReactX to Trunk,
[reactos.git] / reactos / lib / sdk / crt / string / mbstowcs_nt.c
1 #define WIN32_NO_STATUS
2 #include <windows.h>
3 #include <ndk/umtypes.h>
4 #include <ndk/rtlfuncs.h>
5 #include <string.h>
6
7 /*
8 * @implemented
9 */
10 int mbtowc (wchar_t *wchar, const char *mbchar, size_t count)
11 {
12 NTSTATUS Status;
13 ULONG Size;
14
15 if (wchar == NULL)
16 return 0;
17
18 Status = RtlMultiByteToUnicodeN (wchar,
19 sizeof(WCHAR),
20 &Size,
21 mbchar,
22 count);
23 if (!NT_SUCCESS(Status))
24 return -1;
25
26 return (int)Size;
27 }
28
29 /*
30 * @implemented
31 */
32 size_t mbstowcs (wchar_t *wcstr, const char *mbstr, size_t count)
33 {
34 NTSTATUS Status;
35 ULONG Size;
36 ULONG Length;
37
38 Length = strlen (mbstr);
39
40 if (wcstr == NULL)
41 {
42 RtlMultiByteToUnicodeSize (&Size,
43 mbstr,
44 Length);
45
46 return (size_t)Size;
47 }
48
49 Status = RtlMultiByteToUnicodeN (wcstr,
50 count,
51 &Size,
52 mbstr,
53 Length);
54 if (!NT_SUCCESS(Status))
55 return -1;
56
57 return (size_t)Size;
58 }
59
60 /* EOF */