Fixed HAVE_STRNLEN (sheesh, we don't have strnlen.o)

This commit is contained in:
Xavier Roche
2014-08-27 18:22:56 +00:00
parent f25d6c1f24
commit d5d752a1db
4 changed files with 38 additions and 43 deletions

View File

@@ -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

71
configure vendored
View File

@@ -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

View File

@@ -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)

View File

@@ -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) {