Skip to content

Commit

Permalink
Export asprintf() and vasprintf() compatibility functions
Browse files Browse the repository at this point in the history
We'll want this for legacy charset handling.

Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>
  • Loading branch information
David Woodhouse authored and David Woodhouse committed Jul 28, 2014
1 parent 5f10185 commit 94affa1
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 8 deletions.
9 changes: 5 additions & 4 deletions compat.c
Expand Up @@ -42,9 +42,8 @@ time_t openconnect__time(time_t *t)
}
#endif

#ifndef HAVE_ASPRINTF

static int oc_vasprintf(char **strp, const char *fmt, va_list ap)
#ifndef HAVE_VASPRINTF
int openconnect__vasprintf(char **strp, const char *fmt, va_list ap)
{
va_list ap2;
char *res = NULL;
Expand Down Expand Up @@ -102,14 +101,16 @@ static int oc_vasprintf(char **strp, const char *fmt, va_list ap)
*strp = res;
return ret;
}
#endif

#ifndef HAVE_ASPRINTF
int openconnect__asprintf(char **strp, const char *fmt, ...)
{
va_list ap;
int ret;

va_start(ap, fmt);
ret = oc_vasprintf(strp, fmt, ap);
ret = vasprintf(strp, fmt, ap);
va_end(ap);
return ret;
}
Expand Down
14 changes: 11 additions & 3 deletions configure.ac
Expand Up @@ -23,6 +23,8 @@ m4_ifdef([PKG_INSTALLDIR], [PKG_INSTALLDIR],
use_openbsd_libtool=
symver_time=
symver_getline=
symver_asprintf=
symver_vasprintf=

case $host_os in
*linux* | *gnu*)
Expand Down Expand Up @@ -106,8 +108,12 @@ AC_CHECK_FUNC(getline, [AC_DEFINE(HAVE_GETLINE, 1, [Have getline() function])],
[symver_getline="openconnect__getline;"])
AC_CHECK_FUNC(strcasestr, [AC_DEFINE(HAVE_STRCASESTR, 1, [Have strcasestr() function])], [])
AC_CHECK_FUNC(strndup, [AC_DEFINE(HAVE_STRNDUP, 1, [Have strndup() function])], [])
AC_CHECK_FUNC(asprintf, [AC_DEFINE(HAVE_ASPRINTF, 1, [Have asprintf() function])], [])
if test -n "$symver_asprintf"; then
AC_CHECK_FUNC(asprintf, [AC_DEFINE(HAVE_ASPRINTF, 1, [Have asprintf() function])],
[symver_asprintf="openconnect__asprintf;"])
AC_CHECK_FUNC(vasprintf, [AC_DEFINE(HAVE_VASPRINTF, 1, [Have vasprintf() function])],
[symver_vasprintf="openconnect__vasprintf;"])

if test -n "$symver_vasprintf"; then
AC_MSG_CHECKING([for va_copy])
AC_LINK_IFELSE([AC_LANG_PROGRAM([
#include <stdarg.h>
Expand All @@ -126,11 +132,13 @@ if test -n "$symver_asprintf"; then
[AC_DEFINE(HAVE___VA_COPY, 1, [Have __va_copy()])
AC_MSG_RESULT(__va_copy)],
[AC_MSG_RESULT(no)
AC_MSG_ERROR([Your system lacks asprintf() and va_copy()])])
AC_MSG_ERROR([Your system lacks vasprintf() and va_copy()])])
])
fi
AC_SUBST(SYMVER_TIME, $symver_time)
AC_SUBST(SYMVER_GETLINE, $symver_getline)
AC_SUBST(SYMVER_ASPRINTF, $symver_asprintf)
AC_SUBST(SYMVER_VASPRINTF, $symver_vasprintf)

AS_COMPILER_FLAGS(WFLAGS,
"-Wall
Expand Down
2 changes: 1 addition & 1 deletion libopenconnect.map.in
Expand Up @@ -62,7 +62,7 @@ OPENCONNECT_3.3 {
} OPENCONNECT_3.1;

OPENCONNECT_PRIVATE {
global: @SYMVER_TIME@ @SYMVER_GETLINE@ @SYMVER_JAVA@
global: @SYMVER_TIME@ @SYMVER_GETLINE@ @SYMVER_JAVA@ @SYMVER_ASPRINTF@ @SYMVER_VASPRINTF@
openconnect_version_str;
openconnect_sha1;
local:
Expand Down
4 changes: 4 additions & 0 deletions openconnect-internal.h
Expand Up @@ -445,6 +445,10 @@ struct openconnect_info {
#define time(x) openconnect__time(x)
time_t openconnect__time(time_t *t);
#endif
#ifndef HAVE_VASPRINTF
#define vasprintf openconnect__vasprintf
int openconnect__vasprintf(char **strp, const char *fmt, va_list ap);
#endif
#ifndef HAVE_ASPRINTF
#define asprintf openconnect__asprintf
int openconnect__asprintf(char **strp, const char *fmt, ...);
Expand Down

0 comments on commit 94affa1

Please sign in to comment.