From a06b1b4ddf2878c6686f4f963006fa7761b6b880 Mon Sep 17 00:00:00 2001 From: Lev Walkin Date: Thu, 5 Oct 2017 23:07:22 -0700 Subject: [PATCH] Solaris does not have vasnprintf() --- configure.ac | 1 + libasn1common/asn1_buffer.c | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+) diff --git a/configure.ac b/configure.ac index adb52457..191d0131 100644 --- a/configure.ac +++ b/configure.ac @@ -244,6 +244,7 @@ AC_CHECK_FUNCS(mergesort) AC_CHECK_FUNCS(mkstemps) AC_CHECK_FUNCS(timegm) AC_CHECK_DECLS(alloca strcasecmp) +AC_CHECK_DECLS(vasprintf) AC_TRY_LINK_FUNC([symlink],[AC_DEFINE([HAVE_SYMLINK], 1, [Define to 1 if you have the symlink function.])]) dnl Use pandoc to generate manual pages. diff --git a/libasn1common/asn1_buffer.c b/libasn1common/asn1_buffer.c index a3d3a242..8cc4bc81 100644 --- a/libasn1common/asn1_buffer.c +++ b/libasn1common/asn1_buffer.c @@ -5,9 +5,14 @@ #include #include #include +#include "config.h" #include "asn1_buffer.h" +#ifndef HAVE_DECL_VASPRINTF +int vasprintf(char **ret, const char *fmt, va_list args); +#endif + /* * Create and destroy the buffer. */ @@ -134,3 +139,33 @@ int abuf_vprintf(abuf *ab, const char *fmt, va_list ap) { return ret; } +#ifndef HAVE_DECL_VASPRINTF +/* Solaris doesn't have vasprintf(3). */ +int +vasprintf(char **ret, const char *fmt, va_list args) { + int actual_length = -1; + va_list copy; + va_copy(copy, args); + + int suggested = vsnprintf(NULL, 0, fmt, args); + if(suggested >= 0) { + *ret = malloc(suggested + 1); + if(*ret) { + int actual_length = vsnprintf(*ret, suggested + 1, fmt, copy); + if(actual_length >= 0) { + assert(actual_length == suggested); + assert((*ret)[actual_length] == '\0'); + } else { + free(*ret); + *ret = 0; + } + } + } else { + *ret = NULL; + assert(suggested >= 0); /* Can't function like this */ + } + va_end(args); + + return actual_length; +} +#endif