diff options
author | Xavier Roche <xroche@users.noreply.github.com> | 2014-08-27 18:22:56 +0000 |
---|---|---|
committer | Xavier Roche <xroche@users.noreply.github.com> | 2014-08-27 18:22:56 +0000 |
commit | d5d752a1db8ad216db2fe018012d757c080a5927 (patch) | |
tree | f59097ac097a98a8c4d67f8c6a5f61584692534c | |
parent | f25d6c1f24e7dcb9d881c820fe5d269259890ace (diff) |
Fixed HAVE_STRNLEN (sheesh, we don't have strnlen.o)
-rw-r--r-- | config.h.in | 3 | ||||
-rwxr-xr-x | configure | 71 | ||||
-rw-r--r-- | configure.ac | 3 | ||||
-rw-r--r-- | src/htssafe.h | 4 |
4 files changed, 38 insertions, 43 deletions
diff --git a/config.h.in b/config.h.in index 9493984..51aed8d 100644 --- a/config.h.in +++ b/config.h.in @@ -39,6 +39,9 @@ /* Define to 1 if you have the <string.h> header file. */ #undef HAVE_STRING_H +/* Check for strnlen */ +#undef HAVE_STRNLEN + /* Define to 1 if you have the <sys/stat.h> header file. */ #undef HAVE_SYS_STAT_H @@ -14368,62 +14368,51 @@ $as_echo "#define PREFER_PORTABLE_SNPRINTF 1" >>confdefs.h fi ### Check for strnlen - { $as_echo "$as_me:${as_lineno-$LINENO}: checking for working strnlen" >&5 -$as_echo_n "checking for working strnlen... " >&6; } -if ${ac_cv_func_strnlen_working+:} false; then : +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for strnlen in -lc" >&5 +$as_echo_n "checking for strnlen in -lc... " >&6; } +if ${ac_cv_lib_c_strnlen+:} false; then : $as_echo_n "(cached) " >&6 else - if test "$cross_compiling" = yes; then : - # Guess no on AIX systems, yes otherwise. - case "$host_os" in - aix*) ac_cv_func_strnlen_working=no;; - *) ac_cv_func_strnlen_working=yes;; - esac -else - cat confdefs.h - <<_ACEOF >conftest.$ac_ext + ac_check_lib_save_LIBS=$LIBS +LIBS="-lc $LIBS" +cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ -$ac_includes_default + +/* Override any GCC internal prototype to avoid an error. + Use char because int might match the return type of a GCC + builtin and then its argument prototype would still apply. */ +#ifdef __cplusplus +extern "C" +#endif +char strnlen (); int main () { - -#define S "foobar" -#define S_LEN (sizeof S - 1) - - /* At least one implementation is buggy: that of AIX 4.3 would - give strnlen (S, 1) == 3. */ - - int i; - for (i = 0; i < S_LEN + 1; ++i) - { - int expected = i <= S_LEN ? i : S_LEN; - if (strnlen (S, i) != expected) - return 1; - } - return 0; - +return strnlen (); ; return 0; } _ACEOF -if ac_fn_c_try_run "$LINENO"; then : - ac_cv_func_strnlen_working=yes +if ac_fn_c_try_link "$LINENO"; then : + ac_cv_lib_c_strnlen=yes else - ac_cv_func_strnlen_working=no + ac_cv_lib_c_strnlen=no fi -rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext \ - conftest.$ac_objext conftest.beam conftest.$ac_ext +rm -f core conftest.err conftest.$ac_objext \ + conftest$ac_exeext conftest.$ac_ext +LIBS=$ac_check_lib_save_LIBS fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_c_strnlen" >&5 +$as_echo "$ac_cv_lib_c_strnlen" >&6; } +if test "x$ac_cv_lib_c_strnlen" = xyes; then : -fi -{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_func_strnlen_working" >&5 -$as_echo "$ac_cv_func_strnlen_working" >&6; } -test $ac_cv_func_strnlen_working = no && case " $LIBOBJS " in - *" strnlen.$ac_objext "* ) ;; - *) LIBOBJS="$LIBOBJS strnlen.$ac_objext" - ;; -esac +$as_echo "#define HAVE_STRNLEN 1" >>confdefs.h + +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: not found" >&5 +$as_echo "not found" >&6; } +fi ## Online unit tests diff --git a/configure.ac b/configure.ac index 0e3584e..0477767 100644 --- a/configure.ac +++ b/configure.ac @@ -239,7 +239,8 @@ AC_DEFINE(SETUID, 1,[Check for setuid])], AC_MSG_RESULT([not found])) AC_FUNC_SNPRINTF() ### Check for strnlen -AC_FUNC_STRNLEN() +AC_CHECK_LIB(c, strnlen, [ +AC_DEFINE(HAVE_STRNLEN, 1,[Check for strnlen])], AC_MSG_RESULT([not found])) ## Online unit tests AC_MSG_CHECKING(whether to enable online unit tests) diff --git a/src/htssafe.h b/src/htssafe.h index 6dbba56..803534d 100644 --- a/src/htssafe.h +++ b/src/htssafe.h @@ -176,11 +176,13 @@ static HTS_UNUSED void htssafe_compile_time_check_(void) { "overflow while copying '" #B "' to '"#A"'", __FILE__, __LINE__) /** strnlen replacement (autotools). **/ -static HTS_UNUSED size_t rpl_strnlen(const char *s, size_t maxlen) { +#if ( ! defined(WIN32) && ! defined(HAVE_STRNLEN) ) +static HTS_UNUSED size_t strnlen(const char *s, size_t maxlen) { size_t i; for(i = 0 ; i < maxlen && s[i] != '\0' ; i++) ; return i; } +#endif static HTS_INLINE HTS_UNUSED size_t strlen_safe_(const char *source, const size_t sizeof_source, const char *file, int line) { |