mirror of
https://github.com/bkaradzic/bx.git
synced 2026-02-17 20:52:37 +01:00
Added swnprintf.
This commit is contained in:
@@ -12,6 +12,7 @@
|
||||
#include <stdio.h> // vsnprintf
|
||||
#include <string.h>
|
||||
#include <string>
|
||||
#include <wchar.h> // 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__
|
||||
|
||||
Reference in New Issue
Block a user