diff --git a/include/asterisk/compat.h b/include/asterisk/compat.h index afb2901699..4ed0b7a5d8 100644 --- a/include/asterisk/compat.h +++ b/include/asterisk/compat.h @@ -71,6 +71,7 @@ int unsetenv(const char *name); #endif #endif /* __CYGWIN__ */ +#define HAVE_ASPRINTF #define HAVE_VASPRINTF #define HAVE_STRTOQ @@ -89,6 +90,7 @@ int unsetenv(const char *name); #endif #ifdef SOLARIS +#undef HAVE_ASPRINTF #undef HAVE_VASPRINTF #undef HAVE_STRTOQ #endif diff --git a/utils.c b/utils.c index 84ee0b8802..ae4023538e 100644 --- a/utils.c +++ b/utils.c @@ -766,6 +766,40 @@ int vasprintf(char **strp, const char *fmt, va_list ap) } #endif /* !defined(HAVE_VASPRINTF) && !defined(__AST_DEBUG_MALLOC) */ +/* + * Based on Code from bsd-asprintf from OpenSSH + * Copyright (c) 2004 Darren Tucker. + * + * Based originally on asprintf.c from OpenBSD: + * Copyright (c) 1997 Todd C. Miller + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ +#if !defined(HAVE_ASPRINTF) && !defined(__AST_DEBUG_MALLOC) +int asprintf(char **str, const char *fmt, ...) +{ + va_list ap; + int ret; + + *str = NULL; + va_start(ap, fmt); + ret = vasprintf(str, fmt, ap); + va_end(ap); + + return ret; +} +#endif /* !defined(HAVE_ASPRINTF) && !defined(__AST_DEBUG_MALLOC) */ + #ifndef HAVE_STRTOQ #ifndef LONG_MIN #define LONG_MIN (-9223372036854775807L-1L)