diff options
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; +} |