From bb6d574bb9c74fca9f205b94aef021e57832aaad Mon Sep 17 00:00:00 2001 From: Matthias Braun Date: Tue, 4 May 2010 13:13:45 +0000 Subject: [PATCH] implement obstack_vprintf [r27479] --- include/libfirm/adt/obstack.h | 2 ++ ir/obstack/obstack_printf.c | 17 +++++++++++++---- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/include/libfirm/adt/obstack.h b/include/libfirm/adt/obstack.h index 7132a7a26..5863b05bf 100644 --- a/include/libfirm/adt/obstack.h +++ b/include/libfirm/adt/obstack.h @@ -140,6 +140,7 @@ extern "C" { P, A) #include +#include struct _obstack_chunk /* Lives at front of each chunk. */ { @@ -502,6 +503,7 @@ __extension__ \ #endif /* not __GNUC__ or not __STDC__ */ +int obstack_vprintf(struct obstack *obst, const char *fmt, va_list ap); int obstack_printf(struct obstack *obst, const char *fmt, ...); #ifdef __cplusplus diff --git a/ir/obstack/obstack_printf.c b/ir/obstack/obstack_printf.c index 836ffa8d0..a8b5a98b0 100644 --- a/ir/obstack/obstack_printf.c +++ b/ir/obstack/obstack_printf.c @@ -8,18 +8,15 @@ #define vsnprintf _vsnprintf #endif -int obstack_printf(struct obstack *obst, const char *fmt, ...) +int obstack_vprintf(struct obstack *obst, const char *fmt, va_list ap) { char buf[128]; char *buffer = buf; size_t size = sizeof(buf); - va_list ap; int len; for (;;) { - va_start(ap, fmt); len = vsnprintf(buffer, sizeof(buffer), fmt, ap); - va_end(ap); /* snprintf should return -1 only in the error case, but older glibcs * and probably other systems are buggy in this respect and return -1 if @@ -47,3 +44,15 @@ int obstack_printf(struct obstack *obst, const char *fmt, ...) return len; } + +int obstack_printf(struct obstack *obst, const char *fmt, ...) +{ + va_list ap; + int res; + + va_start(ap, fmt); + res = obstack_vprintf(obst, fmt, ap); + va_end(ap); + + return res; +} -- 2.20.1