1 #define _SNPRINTF_DLLIMPORT __declspec( dllexport )
7 #include <systools/win32/snprintf.h>
9 #if defined(_MSC_VER) && (_MSC_VER >= 1400)
10 #pragma warning(disable:4273) // inconsistent dll linkage
15 /* The non-debug versions of _vscprintf/_scprintf are just calls
16 to _vsprintf/_sprintf with string buffer pointer set to NULL,
17 requires MSVCRT version 7.0 */
19 static int __cdecl
_vsctprintf( const TCHAR
*format
, va_list ap
)
21 static int __cdecl
_vsctprintf( const _TXCHAR
*format
, va_list ap
)
24 FILE *fp
= _tfopen( _T("NUL"), _T("wb") );
28 int retval
= _vftprintf( fp
, format
, ap
);
38 /* This function retrieves the pointer to the last character of a buffer.
39 That is the pointer to the last character of the buffer that fits
40 completly into that buffer or the position of the terminating zero.
42 buffer Pointer to a _TXCHAR buffer to be examined
43 count size of the buffer to be examined
45 return The pointer to the last character that fits into the buffer or
46 NULL if count is zero or count is one and the first byte was a
47 leading DBCS character
50 static _TCHAR
*GetLastBufferChar( _TCHAR
*buffer
, size_t count
)
55 while ( (size_t)(cur
- buffer
) < count
)
68 /* Implementation of snprintf following the ISO/IEC 9899:1999 (ISO C99) standard */
70 _SNPRINTF_DLLIMPORT
int __cdecl
vsntprintf( _TCHAR
*buffer
, size_t count
, const _TCHAR
*format
, va_list list
)
74 /* First of all call the existing non POSIX standard function assuming
75 the buffer size will be large enough */
77 retval
= _vsntprintf( buffer
, count
, format
, list
);
81 /* If the buffer wasn't large enough ensure that the buffer will be
84 _TCHAR
*last
= GetLastBufferChar( buffer
, count
);
88 /* Retrieve the count of characters that would have been written
89 if the buffer were large enough */
91 retval
= _vsctprintf( format
, list
);
93 else if ( (size_t)retval
== count
&& count
)
95 /* If the buffer was large enough but not large enough for the trailing
96 zero make the buffer zero terminated */
98 _TCHAR
*last
= GetLastBufferChar( buffer
, count
);
106 /* Implementation of snprintf following the ISO/IEC 9899:1999 (ISO C99) standard */
108 _SNPRINTF_DLLIMPORT
int __cdecl
sntprintf( _TCHAR
*buffer
, size_t count
, const _TCHAR
*format
, ... )
113 va_start( list
, format
);
114 retval
= vsntprintf( buffer
, count
, format
, list
);