diff options
-rw-r--r-- | screenbuffer.cpp | 25 | ||||
-rw-r--r-- | screenbuffer.h | 1 |
2 files changed, 12 insertions, 14 deletions
diff --git a/screenbuffer.cpp b/screenbuffer.cpp index a382e82..d224181 100644 --- a/screenbuffer.cpp +++ b/screenbuffer.cpp @@ -74,35 +74,32 @@ void ScreenBuffer::printstr(const char *buf){ } } -__attribute__((format (printf, 2, 3))) -int ScreenBuffer::printf(const char *format,...){ - va_list ap; - va_start(ap,format); +int ScreenBuffer::printf_varargs(const char *format,va_list ap){ char *buf; int ret=vasprintf(&buf,format,ap); - va_end(ap); assert(buf); - printstr(buf); - free(buf); return ret; } +__attribute__((format (printf, 2, 3))) +int ScreenBuffer::printf(const char *format,...){ + va_list ap; + va_start(ap,format); + int ret=printf_varargs(format,ap); + va_end(ap); + return ret; +} + __attribute__((format (printf, 4, 5))) int ScreenBuffer::mvprintf(int x,int y,const char *format,...){ moveto(x,y); va_list ap; va_start(ap,format); - char *buf; - int ret=vasprintf(&buf,format,ap); + int ret=printf_varargs(format,ap); va_end(ap); - assert(buf); - - printstr(buf); - - free(buf); return ret; } diff --git a/screenbuffer.h b/screenbuffer.h index 49cc5c5..6e3d429 100644 --- a/screenbuffer.h +++ b/screenbuffer.h @@ -9,6 +9,7 @@ class ScreenBuffer{ int curx=0,cury=0; void printstr(const char *buf); + int printf_varargs(const char *format,va_list ap); public: ScreenBuffer(int W,int H); |