[PATCH 3/6] Add a separate check for [v]asprintf() instead of checking for _GNU_SOURCE
Timothy Gu <[email protected]> Thu, 26 Jun 2014 16:15:17 -0700
| Newsgroups | gmane.comp.video.videolan.libdvbpsi.devel |
|---|---|
| Message-ID | <[email protected]> |
Platforms like i686-pc-mingw32 defines _GNU_SOURCE but does not contain the functions. Signed-off-by: Timothy Gu <[email protected]> --- configure.ac | 21 +++++++++++++++++++++ src/dvbpsi.c | 6 +++--- 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/configure.ac b/configure.ac index 2a97e5b..f95c186 100644 --- a/configure.ac +++ b/configure.ac @@ -100,6 +100,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 diff --git a/src/dvbpsi.c b/src/dvbpsi.c index 141e3df..29ae2b0 100644 --- a/src/dvbpsi.c +++ b/src/dvbpsi.c @@ -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); @@ -545,7 +545,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; \ -- 1.9.1 _______________________________________________ libdvbpsi-devel mailing list [email protected] https://mailman.videolan.org/listinfo/libdvbpsi-devel