#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;
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
} else {
break;
}
- buffer = malloc(size);
+ buffer = (char*)malloc(size);
}
obstack_grow(obst, buffer, len);
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;