From 3069841b285021d960aa03f325e8389d07d290a3 Mon Sep 17 00:00:00 2001 From: des Date: Mon, 7 Aug 2006 15:24:24 +0000 Subject: [PATCH] Add implementations of asprintf(3) and vasprintf(3). git-svn-id: svn+ssh://projects.linpro.no/svn/varnish/trunk@721 d4fa192b-c00b-0410-8231-f00ffab90ce4 --- varnish-cache/configure.ac | 2 ++ varnish-cache/include/compat.h | 8 ++++++++ varnish-cache/lib/libcompat/Makefile.am | 2 ++ varnish-cache/lib/libcompat/asprintf.c | 23 ++++++++++++++++++++++ varnish-cache/lib/libcompat/strlcat.c | 1 - varnish-cache/lib/libcompat/strlcpy.c | 1 - varnish-cache/lib/libcompat/vasprintf.c | 26 +++++++++++++++++++++++++ 7 files changed, 61 insertions(+), 2 deletions(-) create mode 100644 varnish-cache/lib/libcompat/asprintf.c create mode 100644 varnish-cache/lib/libcompat/vasprintf.c diff --git a/varnish-cache/configure.ac b/varnish-cache/configure.ac index d2adc25f..3986669e 100644 --- a/varnish-cache/configure.ac +++ b/varnish-cache/configure.ac @@ -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]) diff --git a/varnish-cache/include/compat.h b/varnish-cache/include/compat.h index d18e7bf7..9bf3dbf4 100644 --- a/varnish-cache/include/compat.h +++ b/varnish-cache/include/compat.h @@ -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 diff --git a/varnish-cache/lib/libcompat/Makefile.am b/varnish-cache/lib/libcompat/Makefile.am index 61e45064..01f59815 100644 --- a/varnish-cache/lib/libcompat/Makefile.am +++ b/varnish-cache/lib/libcompat/Makefile.am @@ -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 index 00000000..2347e327 --- /dev/null +++ b/varnish-cache/lib/libcompat/asprintf.c @@ -0,0 +1,23 @@ +/* + * $Id$ + * + */ + +#include +#include + +#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 diff --git a/varnish-cache/lib/libcompat/strlcat.c b/varnish-cache/lib/libcompat/strlcat.c index 61aed920..21f09e7b 100644 --- a/varnish-cache/lib/libcompat/strlcat.c +++ b/varnish-cache/lib/libcompat/strlcat.c @@ -20,7 +20,6 @@ #include #include -#include "config.h" #include "compat.h" #ifndef HAVE_STRLCAT diff --git a/varnish-cache/lib/libcompat/strlcpy.c b/varnish-cache/lib/libcompat/strlcpy.c index d167e45c..bf22e472 100644 --- a/varnish-cache/lib/libcompat/strlcpy.c +++ b/varnish-cache/lib/libcompat/strlcpy.c @@ -20,7 +20,6 @@ #include #include -#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 index 00000000..41ac20e7 --- /dev/null +++ b/varnish-cache/lib/libcompat/vasprintf.c @@ -0,0 +1,26 @@ +/* + * $Id$ + * + */ + +#include +#include + +#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 -- 2.39.5