From 772a71a95943f4f8fcb45d74e4e398abbe6c74f7 Mon Sep 17 00:00:00 2001 From: Ian Lance Taylor Date: Tue, 18 Sep 2012 16:06:53 +0000 Subject: [PATCH] configure.ac: Check whether strnlen is declared. * configure.ac: Check whether strnlen is declared. * dwarf.c: Declare strnlen if not declared. * configure, config.h.in: Rebuild. From-SVN: r191433 --- libbacktrace/ChangeLog | 6 ++++ libbacktrace/config.h.in | 4 +++ libbacktrace/configure | 62 +++++++++++++++++++++++++++++++++++++-- libbacktrace/configure.ac | 2 ++ libbacktrace/dwarf.c | 5 ++++ 5 files changed, 77 insertions(+), 2 deletions(-) diff --git a/libbacktrace/ChangeLog b/libbacktrace/ChangeLog index 277927bc3bc..8275ebcaa6a 100644 --- a/libbacktrace/ChangeLog +++ b/libbacktrace/ChangeLog @@ -1,3 +1,9 @@ +2012-09-18 Ian Lance Taylor + + * configure.ac: Check whether strnlen is declared. + * dwarf.c: Declare strnlen if not declared. + * configure, config.h.in: Rebuild. + 2012-09-18 Rainer Orth * fileline.c: Include . diff --git a/libbacktrace/config.h.in b/libbacktrace/config.h.in index c7b534b3e69..e6464c60597 100644 --- a/libbacktrace/config.h.in +++ b/libbacktrace/config.h.in @@ -3,6 +3,10 @@ /* ELF size: 32 or 64 */ #undef BACKTRACE_ELF_SIZE +/* Define to 1 if you have the declaration of `strnlen', and to 0 if you + don't. */ +#undef HAVE_DECL_STRNLEN + /* Define to 1 if you have the header file. */ #undef HAVE_DLFCN_H diff --git a/libbacktrace/configure b/libbacktrace/configure index d566922a95c..d8c1a02425c 100755 --- a/libbacktrace/configure +++ b/libbacktrace/configure @@ -1823,6 +1823,51 @@ fi eval $as_lineno_stack; test "x$as_lineno_stack" = x && { as_lineno=; unset as_lineno;} } # ac_fn_c_check_header_mongrel + +# ac_fn_c_check_decl LINENO SYMBOL VAR +# ------------------------------------ +# Tests whether SYMBOL is declared, setting cache variable VAR accordingly. +ac_fn_c_check_decl () +{ + as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack + as_decl_name=`echo $2|sed 's/ *(.*//'` + as_decl_use=`echo $2|sed -e 's/(/((/' -e 's/)/) 0&/' -e 's/,/) 0& (/g'` + { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether $as_decl_name is declared" >&5 +$as_echo_n "checking whether $as_decl_name is declared... " >&6; } +if { as_var=$3; eval "test \"\${$as_var+set}\" = set"; }; then : + $as_echo_n "(cached) " >&6 +else + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +$4 +int +main () +{ +#ifndef $as_decl_name +#ifdef __cplusplus + (void) $as_decl_use; +#else + (void) $as_decl_name; +#endif +#endif + + ; + return 0; +} +_ACEOF +if ac_fn_c_try_compile "$LINENO"; then : + eval "$3=yes" +else + eval "$3=no" +fi +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext +fi +eval ac_res=\$$3 + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5 +$as_echo "$ac_res" >&6; } + eval $as_lineno_stack; test "x$as_lineno_stack" = x && { as_lineno=; unset as_lineno;} + +} # ac_fn_c_check_decl cat >config.log <<_ACEOF This file contains any messages produced by compilers while running configure, to aid debugging if configure makes a mistake. @@ -7442,6 +7487,7 @@ $as_echo_n "checking for $compiler option to produce PIC... " >&6; } # AIX 5 now supports IA64 processor lt_prog_compiler_static='-Bstatic' fi + lt_prog_compiler_pic='-fPIC' ;; amigaos*) @@ -10388,7 +10434,7 @@ else lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2 lt_status=$lt_dlunknown cat > conftest.$ac_ext <<_LT_EOF -#line 10391 "configure" +#line 10437 "configure" #include "confdefs.h" #if HAVE_DLFCN_H @@ -10494,7 +10540,7 @@ else lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2 lt_status=$lt_dlunknown cat > conftest.$ac_ext <<_LT_EOF -#line 10497 "configure" +#line 10543 "configure" #include "confdefs.h" #if HAVE_DLFCN_H @@ -11061,6 +11107,18 @@ if test "$ALLOC_FILE" = "alloc.lo"; then fi +ac_fn_c_check_decl "$LINENO" "strnlen" "ac_cv_have_decl_strnlen" "$ac_includes_default" +if test "x$ac_cv_have_decl_strnlen" = x""yes; then : + ac_have_decl=1 +else + ac_have_decl=0 +fi + +cat >>confdefs.h <<_ACEOF +#define HAVE_DECL_STRNLEN $ac_have_decl +_ACEOF + + { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether tests can run" >&5 $as_echo_n "checking whether tests can run... " >&6; } if test "${libbacktrace_cv_sys_native+set}" = set; then : diff --git a/libbacktrace/configure.ac b/libbacktrace/configure.ac index 7a44fdfc7a8..35ed987eff3 100644 --- a/libbacktrace/configure.ac +++ b/libbacktrace/configure.ac @@ -199,6 +199,8 @@ if test "$ALLOC_FILE" = "alloc.lo"; then fi AC_SUBST(BACKTRACE_USES_MALLOC) +AC_CHECK_DECLS(strnlen) + AC_CACHE_CHECK([whether tests can run], [libbacktrace_cv_sys_native], [AC_RUN_IFELSE([AC_LANG_PROGRAM([], [return 0;])], diff --git a/libbacktrace/dwarf.c b/libbacktrace/dwarf.c index dffd20bb154..34861fce484 100644 --- a/libbacktrace/dwarf.c +++ b/libbacktrace/dwarf.c @@ -44,6 +44,11 @@ POSSIBILITY OF SUCH DAMAGE. */ #include "backtrace.h" #include "internal.h" +#ifndef HAVE_DECL_STRNLEN +/* The function is defined in libiberty if needed. */ +extern size_t strnlen (const char *, size_t); +#endif + /* A buffer to read DWARF info. */ struct dwarf_buf