21 # error Not enough var arg support! 32 if(!(p = calloc(1,
sizeof(
struct printbuf))))
return NULL;
35 if(!(p->
buf = malloc( (
size_t) p->
size))) {
47 int new_size =
max(p->
size * 2, p->
bpos + size + 8);
49 mc_debug(
"printbuf_memappend: realloc " 50 "bpos=%d wrsize=%d old_size=%d new_size=%d\n",
53 if(!(t = realloc(p->
buf, (
size_t) new_size)))
return -1;
57 memcpy(p->
buf + p->
bpos, buf, (
size_t) size);
63 #if !HAVE_VSNPRINTF && defined(WIN32) 64 # define vsnprintf _vsnprintf 66 # error Need vsnprintf! 74 static char _T_emptybuffer =
'\0';
79 if(!buf) {
return -1; }
82 chars = _vscprintf(fmt, ap)+1;
86 chars = vsnprintf(&_T_emptybuffer, 0, fmt, ap)+1;
87 if(chars < 0) { chars *= -1; }
90 b = (
char*)malloc(
sizeof(
char)*chars);
93 if((chars = vsprintf(b, fmt, ap)) < 0)
113 size = vsnprintf(buf, 128, msg, ap);
119 if(size == -1 || size > 127) {
122 if((size =
vasprintf(&t, msg, ap)) == -1)
return -1;
void mc_debug(const char *msg,...)
struct printbuf * printbuf_new()
void printbuf_free(struct printbuf *p)
static int vasprintf(char **buf, const char *fmt, va_list ap)
int printbuf_memappend(struct printbuf *p, const char *buf, int size)
int sprintbuf(struct printbuf *p, const char *msg,...)
void printbuf_reset(struct printbuf *p)