Porting to SunOS 5.8:
[tinc] / lib / utils.c
index 795ece9..7f588b4 100644 (file)
 #include <sys/types.h>
 #include <ctype.h>
 #include <string.h>
+#include <stdarg.h>
 
 #include "config.h"
 
 #include <utils.h>
 #include <syslog.h>
+#include <xalloc.h>
 
 volatile int (cp_line[]) = {0, 0, 0, 0, 0, 0, 0, 0};
 volatile char (*cp_file[]) = {"?", "?", "?", "?", "?", "?", "?", "?"};
@@ -72,3 +74,32 @@ void cp_trace()
            cp_file[cp_index], cp_line[cp_index]
         );
 }
+
+#ifndef HAVE_ASPRINTF
+int asprintf(char **buf, const char *fmt, ...)
+{
+  int status;
+  va_list ap;
+  int len;
+  
+  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);
+
+  if(status > len-1)
+    {
+      len = status;
+      va_start(ap, fmt);
+      status = vsnprintf (*buf, len, fmt, ap);
+      va_end (ap);
+    }
+
+  return status;
+}
+#endif