syslinux.mk: use $(MAKEDIR) not $(makefiledir)
[syslinux.git] / com32 / lib / bufprintf.c
blob939bcec364fffdae8760e1200e09d710e3991088
1 #include <stdarg.h>
2 #include <stdio.h>
3 #include <stdlib.h>
4 #include <bufprintf.h>
6 int vbufprintf(struct print_buf *buf, const char *format, va_list ap)
8 va_list ap2;
9 int rv;
11 va_copy(ap2, ap);
12 rv = vsnprintf(NULL, 0, format, ap);
14 /* >= to make sure we have space for terminating null */
15 if (rv + buf->len >= buf->size) {
16 size_t newsize = rv + buf->len + BUFPAD;
17 char *newbuf;
19 newbuf = realloc(buf->buf, newsize);
20 if (!newbuf)
21 return -1;
23 buf->buf = newbuf;
24 buf->size = newsize;
27 rv = vsnprintf(buf->buf + buf->len, buf->size - buf->len, format, ap2);
28 buf->len += rv;
29 return rv;
32 int bufprintf(struct print_buf *buf, const char *format, ...)
34 va_list ap;
35 int rv;
37 va_start(ap, format);
38 rv = vbufprintf(buf, format, ap);
39 va_end(ap);
40 return rv;