[CDMAKE][CTR] Fix strtok_s for empty strings. Part of Wine commit 4fa616c by Bernhard...
[reactos.git] / reactos / sdk / lib / crt / string / wcstombs_nt.c
1 #include <ndk/umtypes.h>
2 #include <ndk/rtlfuncs.h>
3
4 /*
5 * @implemented
6 */
7 int wctomb (char *mbchar, wchar_t wchar)
8 {
9 NTSTATUS Status;
10 ULONG Size;
11
12 if (mbchar == NULL)
13 return 0;
14
15 Status = RtlUnicodeToMultiByteN (mbchar,
16 1,
17 &Size,
18 &wchar,
19 sizeof(WCHAR));
20 if (!NT_SUCCESS(Status))
21 return -1;
22
23 return (int)Size;
24 }
25
26 /*
27 * @implemented
28 */
29 size_t wcstombs (char *mbstr, const wchar_t *wcstr, size_t count)
30 {
31 NTSTATUS Status;
32 ULONG Size;
33 ULONG Length;
34
35 Length = (ULONG)wcslen (wcstr);
36
37 if (mbstr == NULL)
38 {
39 RtlUnicodeToMultiByteSize (&Size,
40 (wchar_t*)((size_t)wcstr),
41 Length * sizeof(WCHAR));
42
43 return (size_t)(Size / sizeof(char));
44 }
45
46 Status = RtlUnicodeToMultiByteN (mbstr,
47 (ULONG)count,
48 &Size,
49 (wchar_t*)((size_t)wcstr),
50 Length * sizeof(WCHAR));
51 if (!NT_SUCCESS(Status))
52 return -1;
53
54 return (size_t)(Size / sizeof(char));
55 }
56
57 /* EOF */