From 01f6e30ac7cfc8f9b304d3993394e9bae4efc846 Mon Sep 17 00:00:00 2001 From: bkaradzic Date: Fri, 17 May 2013 22:14:16 -0700 Subject: [PATCH] Added swnprintf. --- include/bx/string.h | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/include/bx/string.h b/include/bx/string.h index a2e0c79..a90beae 100644 --- a/include/bx/string.h +++ b/include/bx/string.h @@ -12,6 +12,7 @@ #include // vsnprintf #include #include +#include // wchar_t namespace bx { @@ -172,21 +173,34 @@ namespace bx /// Cross platform implementation of vsnprintf that returns number of /// characters which would have been written to the final string if /// enough space had been available. - inline int32_t vsnprintf(char* _str, size_t _size, const char* _format, va_list _argList) + inline int32_t vsnprintf(char* _str, size_t _count, const char* _format, va_list _argList) { #if BX_COMPILER_MSVC - int32_t len = ::vsnprintf(_str, _size, _format, _argList); + int32_t len = ::vsnprintf(_str, _count, _format, _argList); return -1 == len ? ::_vscprintf(_format, _argList) : len; #else - return ::vsnprintf(_str, _size, _format, _argList); + return ::vsnprintf(_str, _count, _format, _argList); #endif // BX_COMPILER_MSVC } - inline int32_t snprintf(char* _str, size_t _size, const char* _format, ...) // BX_PRINTF_ARGS(3, 4) + inline int32_t snprintf(char* _str, size_t _count, const char* _format, ...) // BX_PRINTF_ARGS(3, 4) { va_list argList; va_start(argList, _format); - int32_t len = vsnprintf(_str, _size, _format, argList); + int32_t len = vsnprintf(_str, _count, _format, argList); + va_end(argList); + return len; + } + + inline int32_t swnprintf(wchar_t* _out, size_t _count, const wchar_t* _format, ...) + { + va_list argList; + va_start(argList, _format); +#if defined(__MINGW32__) + int32_t len = swprintf(_out, _format, argList); +#else + int32_t len = swprintf(_out, _count, _format, argList); +#endif // defined(__MINGW__) va_end(argList); return len; } @@ -213,6 +227,7 @@ namespace bx stringPrintfVargs(_out, _format, argList); va_end(argList); } + } // namespace bx #endif // __BX_PRINTF_H__