- NDK fix: don't undef a million status codes, instead, have apps define WIN32_NO_STATUS.
[reactos.git] / reactos / lib / string / wcstombs.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
8 /*
9 * @implemented
10 */
11 int wctomb (char *mbchar, wchar_t wchar)
12 {
13 NTSTATUS Status;
14 ULONG Size;
15
16 if (mbchar == NULL)
17 return 0;
18
19 Status = RtlUnicodeToMultiByteN (mbchar,
20 1,
21 &Size,
22 &wchar,
23 sizeof(WCHAR));
24 if (!NT_SUCCESS(Status))
25 return -1;
26
27 return (int)Size;
28 }
29
30 /*
31 * @implemented
32 */
33 size_t wcstombs (char *mbstr, const wchar_t *wcstr, size_t count)
34 {
35 NTSTATUS Status;
36 ULONG Size;
37 ULONG Length;
38
39 Length = wcslen (wcstr);
40
41 if (mbstr == NULL)
42 {
43 RtlUnicodeToMultiByteSize (&Size,
44 (wchar_t *)wcstr,
45 Length * sizeof(WCHAR));
46
47 return (size_t)Size;
48 }
49
50 Status = RtlUnicodeToMultiByteN (mbstr,
51 count,
52 &Size,
53 (wchar_t *)wcstr,
54 Length * sizeof(WCHAR));
55 if (!NT_SUCCESS(Status))
56 return -1;
57
58 return (size_t)Size;
59 }
60
61 /* EOF */