2 * ntdll printf functions
4 * Copyright 1999, 2009 Alexandre Julliard
5 * Copyright 2000 Jon Griffiths
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
31 #include "ntdll_misc.h"
32 #include "wine/debug.h"
34 WINE_DEFAULT_DEBUG_CHANNEL(ntdll
);
36 static const SIZE_T size_max
= ~(SIZE_T
)0 >> 1;
38 typedef struct pf_flags_t
40 enum { LEN_DEFAULT
, LEN_SHORT
, LEN_LONG
} IntegerLength
;
41 BOOLEAN IntegerDouble
, IntegerNative
, LeftAlign
, Alternate
, PadZero
, WideString
;
42 int FieldLength
, Precision
;
52 /*********************************************************************
53 * _vsnprintf (NTDLL.@)
55 int CDECL
_vsnprintf( char *str
, size_t len
, const char *format
, __ms_va_list args
)
57 pf_output_a out
= { str
, len
};
58 int r
= pf_vsnprintf_a( &out
, format
, args
);
60 if (out
.used
< len
) str
[out
.used
] = 0;
65 /***********************************************************************
66 * _vsnwprintf (NTDLL.@)
68 int CDECL
_vsnwprintf( WCHAR
*str
, size_t len
, const WCHAR
*format
, __ms_va_list args
)
70 pf_output_w out
= { str
, len
};
71 int r
= pf_vsnprintf_w( &out
, format
, args
);
73 if (out
.used
< len
) str
[out
.used
] = 0;
78 /*********************************************************************
81 int WINAPIV
NTDLL__snprintf( char *str
, size_t len
, const char *format
, ... )
86 __ms_va_start( valist
, format
);
87 ret
= _vsnprintf( str
, len
, format
, valist
);
88 __ms_va_end( valist
);
93 /***********************************************************************
94 * _snwprintf (NTDLL.@)
96 int WINAPIV
_snwprintf( WCHAR
*str
, size_t len
, const WCHAR
*format
, ... )
101 __ms_va_start(valist
, format
);
102 ret
= _vsnwprintf( str
, len
, format
, valist
);
108 /*********************************************************************
109 * _vsnprintf_s (NTDLL.@)
111 int CDECL
_vsnprintf_s( char *str
, size_t size
, size_t len
, const char *format
, __ms_va_list args
)
113 pf_output_a out
= { str
, min( size
, len
) };
114 int r
= pf_vsnprintf_a( &out
, format
, args
);
116 if (out
.used
< size
) str
[out
.used
] = 0;
118 if (r
== size
) r
= -1;
123 /***********************************************************************
124 * _vsnwprintf_s (NTDLL.@)
126 int CDECL
_vsnwprintf_s( WCHAR
*str
, size_t size
, size_t len
, const WCHAR
*format
, __ms_va_list args
)
128 pf_output_w out
= { str
, min( size
, len
) };
129 int r
= pf_vsnprintf_w( &out
, format
, args
);
131 if (out
.used
< size
) str
[out
.used
] = 0;
133 if (r
== size
) r
= -1;
138 /*********************************************************************
139 * _snprintf_s (NTDLL.@)
141 int WINAPIV
_snprintf_s( char *str
, size_t size
, size_t len
, const char *format
, ... )
146 __ms_va_start( valist
, format
);
147 ret
= _vsnprintf_s( str
, size
, len
, format
, valist
);
148 __ms_va_end( valist
);
153 /*********************************************************************
154 * _snwprintf_s (NTDLL.@)
156 int WINAPIV
_snwprintf_s( WCHAR
*str
, size_t size
, size_t len
, const WCHAR
*format
, ... )
161 __ms_va_start( valist
, format
);
162 ret
= _vsnwprintf_s( str
, size
, len
, format
, valist
);
163 __ms_va_end( valist
);
168 /*********************************************************************
171 int CDECL
vsprintf( char *str
, const char *format
, __ms_va_list args
)
173 return _vsnprintf( str
, size_max
, format
, args
);
177 /*********************************************************************
178 * vsprintf_s (NTDLL.@)
180 int CDECL
vsprintf_s( char *str
, size_t size
, const char *format
, __ms_va_list args
)
182 return _vsnprintf_s( str
, size
, size
, format
, args
);
186 /*********************************************************************
187 * _vswprintf (NTDLL.@)
189 int CDECL
_vswprintf( WCHAR
*str
, const WCHAR
*format
, __ms_va_list args
)
191 return _vsnwprintf( str
, size_max
, format
, args
);
195 /*********************************************************************
196 * vswprintf_s (NTDLL.@)
198 int CDECL
vswprintf_s( WCHAR
*str
, size_t size
, const WCHAR
*format
, __ms_va_list args
)
200 return _vsnwprintf_s( str
, size
, size
, format
, args
);
204 /*********************************************************************
207 int WINAPIV
NTDLL_sprintf( char *str
, const char *format
, ... )
212 __ms_va_start( valist
, format
);
213 ret
= _vsnprintf( str
, size_max
, format
, valist
);
214 __ms_va_end( valist
);
219 /*********************************************************************
220 * sprintf_s (NTDLL.@)
222 int WINAPIV
sprintf_s( char *str
, size_t size
, const char *format
, ... )
227 __ms_va_start( valist
, format
);
228 ret
= vsprintf_s( str
, size
, format
, valist
);
229 __ms_va_end( valist
);
234 /***********************************************************************
237 int WINAPIV
NTDLL_swprintf( WCHAR
*str
, const WCHAR
*format
, ... )
242 __ms_va_start(valist
, format
);
243 ret
= _vsnwprintf( str
, size_max
, format
, valist
);
249 /***********************************************************************
250 * swprintf_s (NTDLL.@)
252 int WINAPIV
swprintf_s( WCHAR
*str
, size_t size
, const WCHAR
*format
, ... )
257 __ms_va_start(valist
, format
);
258 ret
= vswprintf_s( str
, size
, format
, valist
);