about summary refs log tree commit diff
path: root/misc/subr.c
diff options
context:
space:
mode:
Diffstat (limited to 'misc/subr.c')
-rw-r--r--misc/subr.c20
1 files changed, 20 insertions, 0 deletions
diff --git a/misc/subr.c b/misc/subr.c
index 5b5261e..b90af81 100644
--- a/misc/subr.c
+++ b/misc/subr.c
@@ -14,6 +14,8 @@
 #include <strings.h>
 #include <unistd.h>
 
+#include "subr.h"
+
 void *
 memfind(const void *sub, size_t sublen, const void *mem, size_t memlen)
 {
@@ -443,3 +445,21 @@ end:
     out[oi] = '\0';
     return 0;
 }
+
+#ifndef HAVE_ASPRINTF
+int
+asprintf(char **strp, const char *fmt, ...)
+{
+    int np;
+    va_list ap;
+    va_start(ap, fmt);
+    np = vsnprintf(NULL, 0, fmt, ap);
+    va_end(ap);
+    if ((*strp = malloc(np + 1)) == NULL)
+        return -1;
+    va_start(ap, fmt);
+    vsnprintf(*strp, np + 1, fmt, ap);
+    va_end(ap);
+    return np;
+}
+#endif