update for HEAD-2003091401
[reactos.git] / lib / ntdll / stdlib / wcstombs.c
1 /* $Id$
2  *
3  * COPYRIGHT:       See COPYING in the top level directory
4  * PROJECT:         ReactOS kernel
5  * FILE:            lib/ntdll/stdlib/wcstombs.c
6  * PURPOSE:         converts a unicode string to a multi byte string
7  */
8
9 #include <ddk/ntddk.h>
10 #include <stdlib.h>
11 #include <string.h>
12
13 /*
14  * @implemented
15  */
16 size_t wcstombs (char *mbstr, const wchar_t *wcstr, size_t count)
17 {
18         NTSTATUS Status;
19         ULONG Size;
20         ULONG Length;
21
22         Length = wcslen (wcstr);
23
24         if (mbstr == NULL)
25         {
26                 RtlUnicodeToMultiByteSize (&Size,
27                                            (wchar_t *)wcstr,
28                                            Length * sizeof(WCHAR));
29
30                 return (size_t)Size;
31         }
32
33         Status = RtlUnicodeToMultiByteN (mbstr,
34                                          count,
35                                          &Size,
36                                          (wchar_t *)wcstr,
37                                          Length * sizeof(WCHAR));
38         if (!NT_SUCCESS(Status))
39                 return -1;
40
41         return (size_t)Size;
42 }
43
44 /* EOF */