]> err.no Git - varnish/commitdiff
Add implementations of asprintf(3) and vasprintf(3).
authordes <des@d4fa192b-c00b-0410-8231-f00ffab90ce4>
Mon, 7 Aug 2006 15:24:24 +0000 (15:24 +0000)
committerdes <des@d4fa192b-c00b-0410-8231-f00ffab90ce4>
Mon, 7 Aug 2006 15:24:24 +0000 (15:24 +0000)
git-svn-id: svn+ssh://projects.linpro.no/svn/varnish/trunk@721 d4fa192b-c00b-0410-8231-f00ffab90ce4

varnish-cache/configure.ac
varnish-cache/include/compat.h
varnish-cache/lib/libcompat/Makefile.am
varnish-cache/lib/libcompat/asprintf.c [new file with mode: 0644]
varnish-cache/lib/libcompat/strlcat.c
varnish-cache/lib/libcompat/strlcpy.c
varnish-cache/lib/libcompat/vasprintf.c [new file with mode: 0644]

index d2adc25f3c56c2adb135b5bbf14b4b2018dab9dc..3986669ebbb481dced39e1c0531d937e6bcbc3df 100644 (file)
@@ -61,6 +61,8 @@ AC_FUNC_VPRINTF
 AC_CHECK_FUNCS([strerror])
 AC_FUNC_STRERROR_R
 AC_CHECK_FUNCS([socket])
+AC_CHECK_FUNCS([vasprintf])
+AC_CHECK_FUNCS([asprintf])
 AC_CHECK_FUNCS([strlcat])
 AC_CHECK_FUNCS([strlcpy])
 
index d18e7bf70d067b32836a82a3e716690e398ecc58..9bf3dbf400bfcf9eebfaeecc5247c19e7b99f86e 100644 (file)
@@ -5,6 +5,14 @@
 #ifndef COMPAT_H_INCLUDED
 #define COMPAT_H_INCLUDED
 
+#ifndef HAVE_VASPRINTF
+int asprintf(char **strp, const char *fmt, va_list ap)
+#endif
+
+#ifndef HAVE_ASPRINTF
+int asprintf(char **strp, const char *fmt, ...)
+#endif
+
 #ifndef HAVE_STRLCPY
 size_t strlcpy(char *dst, const char *src, size_t size);
 #endif
index 61e450640e8e60cbc27dea2843d66e969cc3b9f0..01f5981586af18c7c66899656ffc8d9e49c7ed2d 100644 (file)
@@ -5,6 +5,8 @@ INCLUDES = -I$(top_srcdir)/include
 lib_LIBRARIES = libcompat.a
 
 libcompat_a_SOURCES = \
+       asprintf.c \
+       vasprintf.c \
        strlcat.c \
        strlcpy.c
 
diff --git a/varnish-cache/lib/libcompat/asprintf.c b/varnish-cache/lib/libcompat/asprintf.c
new file mode 100644 (file)
index 0000000..2347e32
--- /dev/null
@@ -0,0 +1,23 @@
+/*
+ * $Id$
+ *
+ */
+
+#include <stdarg.h>
+#include <stdio.h>
+
+#include "compat.h"
+
+#ifndef HAVE_ASPRINTF
+int
+asprintf(char **strp, const char *fmt, ...)
+{
+       va_list ap;
+       int ret;
+
+       va_start(ap, fmt);
+       ret = vasprintf(strp, fmt, ap);
+       va_end(ap);
+       return (ret);
+}
+#endif
index 61aed9202dd5650ba899fc9bceea0ccf2dd7aed6..21f09e7b18681437858321f6fa4b7e469881cba5 100644 (file)
@@ -20,7 +20,6 @@
 #include <sys/types.h>
 #include <string.h>
 
-#include "config.h"
 #include "compat.h"
 
 #ifndef HAVE_STRLCAT
index d167e45c48af3a46bc201a948b86448be5271b1e..bf22e472fbdd1a8dcabc386e4c0632f5b2306f51 100644 (file)
@@ -20,7 +20,6 @@
 #include <sys/types.h>
 #include <string.h>
 
-#include "config.h"
 #include "compat.h"
 
 #ifndef HAVE_STRLCPY
diff --git a/varnish-cache/lib/libcompat/vasprintf.c b/varnish-cache/lib/libcompat/vasprintf.c
new file mode 100644 (file)
index 0000000..41ac20e
--- /dev/null
@@ -0,0 +1,26 @@
+/*
+ * $Id$
+ *
+ */
+
+#include <stdarg.h>
+#include <stdio.h>
+
+#include "compat.h"
+
+#ifndef HAVE_VASPRINTF
+int
+asprintf(char **strp, const char *fmt, va_list ap)
+{
+       va_list ap, aq;
+       int ret;
+
+       va_copy(aq, ap);
+       ret = vsnprintf(NULL, 0, fmt, aq);
+       va_end(aq);
+       if ((*strp = malloc(ret + 1)) == NULL)
+               return (-1);
+       ret = vsnprintf(*strp, ret + 1, fmt, ap);
+       return (ret);
+}
+#endif