Skip to content

Commit 18a91a1

Browse files
committed
Added printf and vprintf.
1 parent 702b676 commit 18a91a1

File tree

2 files changed

+31
-3
lines changed

2 files changed

+31
-3
lines changed

include/bx/string.h

+6
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,12 @@ namespace bx
281281
/// enough space had been available.
282282
int32_t snprintf(char* _out, int32_t _max, const char* _format, ...);
283283

284+
///
285+
int32_t vprintf(const char* _format, va_list _argList);
286+
287+
///
288+
int32_t printf(const char* _format, ...);
289+
284290
/// Templatized snprintf.
285291
template <typename Ty>
286292
void stringPrintfVargs(Ty& _out, const char* _format, va_list _argList);

src/string.cpp

+25-3
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55

66
#include "bx_p.h"
77
#include <bx/allocator.h>
8+
#include <bx/file.h>
89
#include <bx/hash.h>
9-
#include <bx/readerwriter.h>
1010
#include <bx/string.h>
1111

1212
namespace bx
@@ -1153,10 +1153,10 @@ namespace bx
11531153
SizerWriter sizer;
11541154
va_list argListCopy;
11551155
va_copy(argListCopy, _argList);
1156-
int32_t size = write(&sizer, _format, argListCopy, &err);
1156+
int32_t total = write(&sizer, _format, argListCopy, &err);
11571157
va_end(argListCopy);
11581158

1159-
return size;
1159+
return total;
11601160
}
11611161

11621162
int32_t snprintf(char* _out, int32_t _max, const char* _format, ...)
@@ -1165,6 +1165,28 @@ namespace bx
11651165
va_start(argList, _format);
11661166
int32_t total = vsnprintf(_out, _max, _format, argList);
11671167
va_end(argList);
1168+
1169+
return total;
1170+
}
1171+
1172+
int32_t vprintf(const char* _format, va_list _argList)
1173+
{
1174+
Error err;
1175+
va_list argListCopy;
1176+
va_copy(argListCopy, _argList);
1177+
int32_t total = write(getStdOut(), _format, argListCopy, &err);
1178+
va_end(argListCopy);
1179+
1180+
return total;
1181+
}
1182+
1183+
int32_t printf(const char* _format, ...)
1184+
{
1185+
va_list argList;
1186+
va_start(argList, _format);
1187+
int32_t total = vprintf(_format, argList);
1188+
va_end(argList);
1189+
11681190
return total;
11691191
}
11701192

0 commit comments

Comments
 (0)