From 18a91a1b5e8299d47d50d0301025bb9bc8b3a25a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=91=D1=80=D0=B0=D0=BD=D0=B8=D0=BC=D0=B8=D1=80=20=D0=9A?= =?UTF-8?q?=D0=B0=D1=80=D0=B0=D1=9F=D0=B8=D1=9B?= Date: Sat, 20 Apr 2019 19:04:15 -0700 Subject: [PATCH] Added printf and vprintf. --- include/bx/string.h | 6 ++++++ src/string.cpp | 28 +++++++++++++++++++++++++--- 2 files changed, 31 insertions(+), 3 deletions(-) diff --git a/include/bx/string.h b/include/bx/string.h index 3fdce89..43798a4 100644 --- a/include/bx/string.h +++ b/include/bx/string.h @@ -281,6 +281,12 @@ namespace bx /// enough space had been available. int32_t snprintf(char* _out, int32_t _max, const char* _format, ...); + /// + int32_t vprintf(const char* _format, va_list _argList); + + /// + int32_t printf(const char* _format, ...); + /// Templatized snprintf. template void stringPrintfVargs(Ty& _out, const char* _format, va_list _argList); diff --git a/src/string.cpp b/src/string.cpp index 104e8c8..f511a95 100644 --- a/src/string.cpp +++ b/src/string.cpp @@ -5,8 +5,8 @@ #include "bx_p.h" #include +#include #include -#include #include namespace bx @@ -1153,10 +1153,10 @@ namespace bx SizerWriter sizer; va_list argListCopy; va_copy(argListCopy, _argList); - int32_t size = write(&sizer, _format, argListCopy, &err); + int32_t total = write(&sizer, _format, argListCopy, &err); va_end(argListCopy); - return size; + return total; } int32_t snprintf(char* _out, int32_t _max, const char* _format, ...) @@ -1165,6 +1165,28 @@ namespace bx va_start(argList, _format); int32_t total = vsnprintf(_out, _max, _format, argList); va_end(argList); + + return total; + } + + int32_t vprintf(const char* _format, va_list _argList) + { + Error err; + va_list argListCopy; + va_copy(argListCopy, _argList); + int32_t total = write(getStdOut(), _format, argListCopy, &err); + va_end(argListCopy); + + return total; + } + + int32_t printf(const char* _format, ...) + { + va_list argList; + va_start(argList, _format); + int32_t total = vprintf(_format, argList); + va_end(argList); + return total; }