Add a separate check for [v]asprintf() instead of checking for _GNU_SOURCE
[email protected] (Timothy Gu) Mon, 8 Sep 2014 14:49:47 +0200 (CEST)
| Newsgroups | gmane.comp.video.videolan.libdvbpsi.devel |
|---|---|
| Message-ID | <[email protected]> |
libdvbpsi | branch: master | Timothy Gu <[email protected]> | Thu Jun 26 16:15:17 2014 -0700| [031aae514b508fe13582106ed6fe5f3ff804dd6a] | committer: 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: Timothy Gu <[email protected]> > http://git.videolan.org/gitweb.cgi/libdvbpsi.git/?a=commit;h=031aae514b508fe13582106ed6fe5f3ff804dd6a --- configure.ac | 21 +++++++++++++++++++++ src/dvbpsi.c | 6 +++--- 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/configure.ac b/configure.ac index 2585a8f..7973bf6 100644 --- a/configure.ac +++ b/configure.ac @@ -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 diff --git a/src/dvbpsi.c b/src/dvbpsi.c index 4ae1cda..b8f5489 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); @@ -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; \ _______________________________________________ libdvbpsi-devel mailing list [email protected] https://mailman.videolan.org/listinfo/libdvbpsi-devel