From d12a41b17a006ccc1b0f98e9df3fc442e4ee7643 Mon Sep 17 00:00:00 2001 From: Guy Harris Date: Fri, 23 Mar 2018 14:21:06 -0700 Subject: [PATCH] Include alloca.h if we have it. Bug: 14552 Change-Id: I799691f7f33ca56748ed4e51d7d548f37769837b Reviewed-on: https://code.wireshark.org/review/26611 Petri-Dish: Guy Harris Tested-by: Petri Dish Buildbot Reviewed-by: Guy Harris --- ConfigureChecks.cmake | 14 ++++++++++++++ cmakeconfig.h.in | 3 +++ configure.ac | 16 +++++++++++++--- wsutil/getopt_long.c | 8 ++++++++ 4 files changed, 38 insertions(+), 3 deletions(-) diff --git a/ConfigureChecks.cmake b/ConfigureChecks.cmake index bd6e977348..9079ee396f 100644 --- a/ConfigureChecks.cmake +++ b/ConfigureChecks.cmake @@ -89,11 +89,25 @@ cmake_pop_check_state() check_function_exists("getopt_long" HAVE_GETOPT_LONG) if(HAVE_GETOPT_LONG) + # + # The OS has getopt_long(), so it might have optreset. + # Do we have it? + # if(HAVE_GETOPT_H) check_symbol_exists("optreset" "getopt.h" HAVE_OPTRESET) else() check_symbol_exists("optreset" HAVE_OPTRESET) endif() +else() + # + # The OS doesn't have getopt_long(), so we're using the GNU libc + # version that we have in wsutil. It doesn't have optreset, so we + # don't need to check for it. + # + # However, it uses alloca(), so we may need to include alloca.h; + # check for it. + # + check_include_file("alloca.h" HAVE_ALLOCA_H) endif() check_function_exists("getifaddrs" HAVE_GETIFADDRS) check_function_exists("issetugid" HAVE_ISSETUGID) diff --git a/cmakeconfig.h.in b/cmakeconfig.h.in index e5f12e3f49..566bfc9d34 100644 --- a/cmakeconfig.h.in +++ b/cmakeconfig.h.in @@ -41,6 +41,9 @@ /* Enable AirPcap */ #cmakedefine HAVE_AIRPCAP 1 +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_ALLOCA_H 1 + /* Define to 1 if you have the header file. */ #cmakedefine HAVE_ARPA_INET_H 1 diff --git a/configure.ac b/configure.ac index 8d743f3b2f..b5ee1f0626 100644 --- a/configure.ac +++ b/configure.ac @@ -2309,16 +2309,26 @@ AC_CHECK_MEMBERS([struct sockaddr.sa_len],,, #endif]) AC_REPLACE_FUNCS(getopt_long) -dnl -dnl Do we have optreset? -dnl if test "x$ac_cv_func_getopt_long" = xyes; then + # + # The OS has getopt_long(), so it might have optreset. Do we have it? + # AC_CACHE_CHECK([whether optreset is defined], ac_cv_have_optreset, AC_LINK_IFELSE([AC_LANG_SOURCE([[extern int optreset;return optreset;]])], ac_cv_have_optreset=yes, ac_cv_have_optreset=no)) if test "$ac_cv_have_optreset" = yes ; then AC_DEFINE(HAVE_OPTRESET, 1, [Define to 1 if you have the optreset variable]) fi +else + # + # The OS doesn't have getopt_long(), so we're using the GNU libc + # version that we have in wsutil. It doesn't have optreset, so we + # don't need to check for it. + # + # However, it uses alloca(), so we may need to include alloca.h; + # check for it. + # + AC_CHECK_HEADERS(alloca.h) fi AC_REPLACE_FUNCS(strptime) diff --git a/wsutil/getopt_long.c b/wsutil/getopt_long.c index 3b19fe6c32..3e2a9bce5e 100644 --- a/wsutil/getopt_long.c +++ b/wsutil/getopt_long.c @@ -64,6 +64,14 @@ # define _(msgid) (msgid) #endif +/* + * If we have alloca.h, we assume we need it. + */ +# +#ifdef HAVE_ALLOCA_H +# include +#endif + #ifdef _WIN32 # define alloca _alloca #endif