1 From e626f4ca5169036a0042e55e58aca2bb5cc19ad7 Mon Sep 17 00:00:00 2001
2 From: Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
3 Date: Fri, 19 Aug 2016 22:39:17 +0200
4 Subject: [PATCH] Use autoconf checks for strndup and asprintf
6 The current code in config.c can provide its own implementation of
7 asprintf() and strndup() if not provided by the system. However, in
8 order to decide if they should be provided, the check done is:
10 #if !defined(name_of_function)
12 which only works if the function is actually defined as a macro, which
13 is not necessarily the case.
15 Therefore, we replace this logic by a proper AC_CHECK_FUNCS() check in
18 Signed-off-by: Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
22 2 files changed, 4 insertions(+), 2 deletions(-)
24 diff --git a/config.c b/config.c
25 index 8731348..8741e48 100644
32 -#if !defined(asprintf) && !defined(_FORTIFY_SOURCE)
33 +#if !defined(HAVE_ASPRINTF) && !defined(_FORTIFY_SOURCE)
36 int asprintf(char **string_ptr, const char *format, ...)
37 @@ -78,7 +78,7 @@ int asprintf(char **string_ptr, const char *format, ...)
41 -#if !defined(strndup)
42 +#if !defined(HAVE_STRNDUP)
43 char *strndup(const char *s, size_t n)
46 diff --git a/configure.ac b/configure.ac
47 index 5c83d20..51da52a 100644
50 @@ -18,6 +18,8 @@ AC_SYS_LARGEFILE
51 AC_CHECK_LIB([popt],[poptParseArgvString],,
52 AC_MSG_ERROR([libpopt required but not found]))
54 +AC_CHECK_FUNCS([strndup asprintf])
56 dnl Needed for out-of-source builds