Commit bd2b6872 authored by Dag Erling Smørgrav's avatar Dag Erling Smørgrav

Add implementations of asprintf(3) and vasprintf(3).

git-svn-id: http://www.varnish-cache.org/svn/trunk/varnish-cache@721 d4fa192b-c00b-0410-8231-f00ffab90ce4
parent cd7c8b7a
......@@ -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])
......
......@@ -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
......
......@@ -5,6 +5,8 @@ INCLUDES = -I$(top_srcdir)/include
lib_LIBRARIES = libcompat.a
libcompat_a_SOURCES = \
asprintf.c \
vasprintf.c \
strlcat.c \
strlcpy.c
......
/*
* $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
......@@ -20,7 +20,6 @@
#include <sys/types.h>
#include <string.h>
#include "config.h"
#include "compat.h"
#ifndef HAVE_STRLCAT
......
......@@ -20,7 +20,6 @@
#include <sys/types.h>
#include <string.h>
#include "config.h"
#include "compat.h"
#ifndef HAVE_STRLCPY
......
/*
* $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
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment