770a71d1e9a0988f1c97b9df2b745edbba2d5cb5
[reactos.git] / reactos / lib / ntdll / stdlib / wcstombs.c
1 /* $Id: wcstombs.c,v 1.1 1999/12/30 14:38:54 ekohl Exp $
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 size_t wcstombs (char *mbstr, const wchar_t *wcstr, size_t count)
14 {
15 NTSTATUS Status;
16 ULONG Size;
17 ULONG Length;
18
19 Length = wcslen (wcstr);
20
21 if (mbstr == NULL)
22 {
23 RtlUnicodeToMultiByteSize (&Size,
24 (wchar_t *)wcstr,
25 Length * sizeof(WCHAR));
26
27 return (size_t)Size;
28 }
29
30 Status = RtlUnicodeToMultiByteN (mbstr,
31 count,
32 &Size,
33 (wchar_t *)wcstr,
34 Length * sizeof(WCHAR));
35 if (!NT_SUCCESS(Status))
36 return -1;
37
38 return (size_t)Size;
39 }
40
41 /* EOF */