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