X-Git-Url: http://nsz.repo.hu/git/?a=blobdiff_plain;f=ir%2Fobstack%2Fobstack_printf.c;h=7ade5ef138b363adc88f4b58b7d92addab2b9cce;hb=1a3b7d363474ab544c13093a2f0b578718d37c7a;hp=836ffa8d077436950846565f08ac358838cf647e;hpb=9427d14adb43b7c17865951c51a0ae4e39a51bb2;p=libfirm diff --git a/ir/obstack/obstack_printf.c b/ir/obstack/obstack_printf.c index 836ffa8d0..7ade5ef13 100644 --- a/ir/obstack/obstack_printf.c +++ b/ir/obstack/obstack_printf.c @@ -5,21 +5,26 @@ #include "obstack.h" #ifdef _WIN32 -#define vsnprintf _vsnprintf -#endif - -int obstack_printf(struct obstack *obst, const char *fmt, ...) +/* win32/C89 has no va_copy function... so we have to use the stupid fixed-length version */ +int obstack_vprintf(struct obstack *obst, const char *fmt, va_list ap) FIRM_NOTHROW +{ + char buf[16384]; + int len = _vsnprintf(buf, sizeof(buf), fmt, ap); + obstack_grow(obst, buf, len); + return len; +} +#else +int obstack_vprintf(struct obstack *obst, const char *fmt, va_list ap) FIRM_NOTHROW { 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); + va_list tap; + va_copy(tap, ap); + len = vsnprintf(buffer, size, fmt, tap); /* 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 @@ -38,7 +43,7 @@ int obstack_printf(struct obstack *obst, const char *fmt, ...) } else { break; } - buffer = malloc(size); + buffer = (char*)malloc(size); } obstack_grow(obst, buffer, len); @@ -47,3 +52,16 @@ int obstack_printf(struct obstack *obst, const char *fmt, ...) return len; } +#endif + +int obstack_printf(struct obstack *obst, const char *fmt, ...) FIRM_NOTHROW +{ + va_list ap; + int res; + + va_start(ap, fmt); + res = obstack_vprintf(obst, fmt, ap); + va_end(ap); + + return res; +}