[CMAKE]
[reactos.git] / lib / sdk / crt / printf / _snwprintf.c
1 /*
2 * COPYRIGHT: GNU GPL, see COPYING in the top level directory
3 * PROJECT: ReactOS crt library
4 * FILE: lib/sdk/crt/printf/_snwprintf.c
5 * PURPOSE: Implementation of _snwprintf
6 * PROGRAMMER: Timo Kreuzer
7 */
8
9 #include <stdio.h>
10 #include <stdarg.h>
11
12 int _cdecl wstreamout(FILE *stream, const wchar_t *format, va_list argptr);
13
14 int
15 __cdecl
16 _snwprintf(
17 wchar_t *buffer,
18 size_t count,
19 const wchar_t *format,
20 ...)
21 {
22 va_list argptr;
23 int result;
24 FILE stream;
25
26 stream._base = (char*)buffer;
27 stream._ptr = stream._base;
28 stream._bufsiz = count * sizeof(wchar_t);
29 stream._cnt = stream._bufsiz;
30 stream._flag = _IOSTRG | _IOWRT;
31 stream._tmpfname = 0;
32 stream._charbuf = 0;
33
34 va_start(argptr, format);
35 result = wstreamout(&stream, format, argptr);
36 va_end(argptr);
37
38 /* Only zero terminate if there is enough space left */
39 if (stream._cnt >= sizeof(wchar_t)) *(wchar_t*)stream._ptr = L'\0';
40
41 return result;
42 }