Commit | Line | Data |
---|---|---|
d0ef6382 MM |
1 | #include "StreamOutput.h" |
2 | ||
3 | NullStreamOutput StreamOutput::NullStream; | |
fc7b9a7b JM |
4 | |
5 | int StreamOutput::printf(const char *format, ...) | |
6 | { | |
7 | char b[64]; | |
8 | char *buffer; | |
9 | // Make the message | |
10 | va_list args; | |
11 | va_start(args, format); | |
12 | ||
13 | int size = vsnprintf(b, 64, format, args) + 1; // we add one to take into account space for the terminating \0 | |
14 | ||
15 | if (size < 64) { | |
16 | buffer = b; | |
17 | } else { | |
18 | buffer = new char[size]; | |
19 | vsnprintf(buffer, size, format, args); | |
20 | } | |
21 | va_end(args); | |
22 | ||
23 | puts(buffer); | |
24 | ||
25 | if (buffer != b) | |
26 | delete[] buffer; | |
27 | ||
28 | return size - 1; | |
29 | } |