mirror of https://gerrit.osmocom.org/asn1c
Solaris does not have vasnprintf()
This commit is contained in:
parent
d28b45fd93
commit
a06b1b4ddf
|
@ -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.
|
||||
|
|
|
@ -5,9 +5,14 @@
|
|||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include <assert.h>
|
||||
#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
|
||||
|
|
Loading…
Reference in New Issue