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