[CRT]
[reactos.git] / reactos / lib / sdk / crt / printf / _sxprintf.c
1 /*
2 * COPYRIGHT: GNU GPL, see COPYING in the top level directory
3 * PROJECT: ReactOS crt library
4 * FILE: lib/sdk/crt/printf/swprintf.c
5 * PURPOSE: Implementation of swprintf
6 * PROGRAMMER: Timo Kreuzer
7 */
8
9 #include <stdio.h>
10 #include <stdarg.h>
11 #include <limits.h>
12 #include <tchar.h>
13
14 #ifdef _UNICODE
15 #define _tstreamout wstreamout
16 #else
17 #define _tstreamout streamout
18 #endif
19
20 int _cdecl _tstreamout(FILE *stream, const TCHAR *format, va_list argptr);
21
22 int
23 #if defined(USER32_WSPRINTF) && defined(_M_IX86)
24 _stdcall
25 #else
26 _cdecl
27 #endif
28 _sxprintf(
29 TCHAR *buffer,
30 #if USE_COUNT
31 size_t count,
32 #endif
33 const TCHAR *format,
34 #if USE_VARARGS
35 va_list argptr)
36 #else
37 ...)
38 #endif
39 {
40 #if !USE_VARARGS
41 va_list argptr;
42 #endif
43 int result;
44 FILE stream;
45
46 stream._base = (char*)buffer;
47 stream._ptr = stream._base;
48 stream._charbuf = 0;
49 #if USE_COUNT
50 stream._cnt = count * sizeof(TCHAR);
51 #else
52 stream._cnt = INT_MAX;
53 #endif
54 stream._bufsiz = 0;
55 stream._flag = _IOSTRG | _IOWRT;
56 stream._tmpfname = 0;
57
58 #if !USE_VARARGS
59 va_start(argptr, format);
60 #endif
61 result = _tstreamout(&stream, format, argptr);
62 #if !USE_VARARGS
63 va_end(argptr);
64 #endif
65
66 /* Only zero terminate if there is enough space left */
67 if (stream._cnt >= sizeof(TCHAR)) *(TCHAR*)stream._ptr = _T('\0');
68
69 return result;
70 }
71
72