Commit 031aae51 authored by Timothy Gu's avatar Timothy Gu Committed by Jean-Paul Saman

Add a separate check for [v]asprintf() instead of checking for _GNU_SOURCE

Platforms like i686-pc-mingw32 defines _GNU_SOURCE but does not contain
the functions.
Signed-off-by: default avatarTimothy Gu <timothygu99@gmail.com>
parent 568fca6f
......@@ -110,6 +110,27 @@ if test "${ac_cv_cpp_variadic_macros}" != "no"; then
AC_DEFINE(HAVE_VARIADIC_MACROS, 1, Support for variadic macros)
fi
dnl Check for asprintf(). Systems with asprintf() must also have vasprintf(),
dnl so it is not checked separately.
AC_CACHE_CHECK([for asprintf()],
[ac_cv_asprintf],
[AC_COMPILE_IFELSE([
AC_LANG_SOURCE([[
#include <stdio.h>
#include <stdlib.h>
int main(void) {
char *text = NULL;
int ret = asprintf(&text, "test");
if (ret >= 0) free(text);
return 0;
}
]])],
ac_cv_asprintf=yes,
ac_cv_asprintf=no)])
if test "${ac_cv_asprintf}" != "no"; then
AC_DEFINE(HAVE_ASPRINTF, 1, [Support for asprintf() and vasprintf()])
fi
dnl
dnl Generate Makefiles and other output files
dnl
......
......@@ -508,7 +508,7 @@ bool dvbpsi_packet_push(dvbpsi_t *p_dvbpsi, uint8_t* p_data)
* 1 is warning and errors
* 2 is debug, warning and errors
*****************************************************************************/
#if !defined(_GNU_SOURCE)
#if !defined(HAVE_ASPRINTF)
# define DVBPSI_MSG_SIZE 1024
#endif
......@@ -523,7 +523,7 @@ void dvbpsi_message(dvbpsi_t *dvbpsi, const dvbpsi_msg_level_t level, const char
va_list ap;
va_start(ap, fmt);
char *msg = NULL;
#if defined(_GNU_SOURCE)
#if defined(HAVE_ASPRINTF)
int err = vasprintf(&msg, fmt, ap);
#else
msg = malloc(DVBPSI_MSG_SIZE);
......@@ -544,7 +544,7 @@ void dvbpsi_message(dvbpsi_t *dvbpsi, const dvbpsi_msg_level_t level, const char
#else
/* Common code for printing messages */
# if defined(_GNU_SOURCE)
# if defined(HAVE_ASPRINTF)
# define DVBPSI_MSG_COMMON(level) \
do { \
va_list ap; \
......
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