+
+void
+log_f (Log * log, char *fmt, ...)
+{
+
+ int n;
+ static char *buf;
+ va_list ap;
+ static int size;
+
+ if (!log)
+ return;
+
+ if (!size)
+ {
+ size = 128;
+ buf = malloc (size);
+ }
+
+ if (!buf)
+ return;
+
+ while (1)
+ {
+ va_start (ap, fmt);
+ n = vsnprintf (buf, size, fmt, ap);
+ va_end (ap);
+
+ if (n > -1 && n < size)
+ {
+ log->log (log, buf);
+ return;
+ }
+
+ if (n > -1) /* glibc 2.1 */
+ size = n + 1;
+ else /* glibc 2.0 */
+ size *= 2; /* twice the old size */
+
+ buf = realloc (buf, size);
+
+ if (!buf)
+ return;
+ }
+}