X-Git-Url: http://nsz.repo.hu/git/?a=blobdiff_plain;f=ir%2Fobstack%2Fobstack_printf.c;h=a270fea800623ff41b1866675aab28eb135fca10;hb=4de03dcc6a6b5cff24c69afeeb2698c4a4506b19;hp=9d92092ebf4db39bdb5bad897f2e7f06a7d0ec81;hpb=6aaf054f627b488daf78d8d9c47cca4370012a55;p=libfirm diff --git a/ir/obstack/obstack_printf.c b/ir/obstack/obstack_printf.c index 9d92092eb..a270fea80 100644 --- a/ir/obstack/obstack_printf.c +++ b/ir/obstack/obstack_printf.c @@ -1,3 +1,4 @@ +#include #include #include #include @@ -5,10 +6,16 @@ #include "obstack.h" #ifdef _WIN32 -#define vsnprintf _vsnprintf -#endif - -int obstack_vprintf(struct obstack *obst, const char *fmt, va_list ap) +/* 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; @@ -16,7 +23,9 @@ int obstack_vprintf(struct obstack *obst, const char *fmt, va_list ap) int len; for (;;) { - len = vsnprintf(buffer, size, fmt, 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 @@ -35,7 +44,7 @@ int obstack_vprintf(struct obstack *obst, const char *fmt, va_list ap) } else { break; } - buffer = malloc(size); + buffer = (char*)malloc(size); } obstack_grow(obst, buffer, len); @@ -44,8 +53,9 @@ int obstack_vprintf(struct obstack *obst, const char *fmt, va_list ap) return len; } +#endif -int obstack_printf(struct obstack *obst, const char *fmt, ...) +int obstack_printf(struct obstack *obst, const char *fmt, ...) FIRM_NOTHROW { va_list ap; int res;