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