- va_start(ap, fmt);
- status = vsnprintf (*buf, len, fmt, ap);
- va_end (ap);
+ len = 4096;
+ *buf = xmalloc(len);
+
+ va_start(ap, fmt);
+ status = vsnprintf(*buf, len, fmt, ap);
+ va_end(ap);
+
+ if(status >= 0)
+ *buf = xrealloc(*buf, status + 1);
+
+ if(status > len - 1) {
+ len = status;
+ va_start(ap, fmt);
+ status = vsnprintf(*buf, len, fmt, ap);
+ va_end(ap);
+ }
+
+ return status;
+}
+#endif
+
+#ifndef HAVE_GETTIMEOFDAY
+int gettimeofday(struct timeval *tv, void *tz) {
+ tv->tv_sec = time(NULL);
+ tv->tv_usec = 0;
+ return 0;
+}
+#endif