Added printf and vprintf.

This commit is contained in:
Бранимир Караџић
2019-04-20 19:04:15 -07:00
parent 702b676ec2
commit 18a91a1b5e
2 changed files with 31 additions and 3 deletions

View File

@@ -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 <typename Ty>
void stringPrintfVargs(Ty& _out, const char* _format, va_list _argList);

View File

@@ -5,8 +5,8 @@
#include "bx_p.h"
#include <bx/allocator.h>
#include <bx/file.h>
#include <bx/hash.h>
#include <bx/readerwriter.h>
#include <bx/string.h>
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;
}