diff options
author | Luca Barbieri <[email protected]> | 2010-08-20 11:31:24 +0200 |
---|---|---|
committer | Luca Barbieri <[email protected]> | 2010-08-20 18:18:28 +0200 |
commit | b1fa352db8a69883f97dd579d892291f414a67f5 (patch) | |
tree | 1ed8c14cb941a867ace2912f9c780c488de2d54d /src/gallium/auxiliary/os/os_stream.c | |
parent | 40eef4c20cc0b4500a0d8c8538872ed4b473d737 (diff) |
os_stream: add printf facility
Diffstat (limited to 'src/gallium/auxiliary/os/os_stream.c')
-rw-r--r-- | src/gallium/auxiliary/os/os_stream.c | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/src/gallium/auxiliary/os/os_stream.c b/src/gallium/auxiliary/os/os_stream.c new file mode 100644 index 00000000000..2d4e1852ba4 --- /dev/null +++ b/src/gallium/auxiliary/os/os_stream.c @@ -0,0 +1,40 @@ +#include "pipe/p_config.h" + +#include "os_stream.h" +#include "util/u_memory.h" +#include "util/u_string.h" + +int +os_default_stream_vprintf (struct os_stream* stream, const char *format, va_list ap) +{ + char buf[1024]; + int retval; + + retval = util_vsnprintf(buf, sizeof(buf), format, ap); + if(retval <= 0) + {} + else if(retval < sizeof(buf)) + stream->write(stream, buf, retval); + else + { + int alloc = sizeof(buf); + char* str = NULL; + for(;;) + { + alloc += alloc; + if(str) + FREE(str); + str = MALLOC(alloc); + if(!str) + return -1; + + retval = util_vsnprintf(str, alloc, format, ap); + } while(retval >= alloc); + + if(retval > 0) + stream->write(stream, str, retval); + FREE(str); + } + + return retval; +} |