2N/A# strndup.m4 serial 18
2N/Adnl Copyright (C) 2002-2003, 2005-2010 Free Software Foundation, Inc.
2N/Adnl This file is free software; the Free Software Foundation
2N/Adnl gives unlimited permission to copy and/or distribute it,
2N/Adnl with or without modifications, as long as this notice is preserved.
2N/A
2N/AAC_DEFUN([gl_FUNC_STRNDUP],
2N/A[
2N/A dnl Persuade glibc <string.h> to declare strndup().
2N/A AC_REQUIRE([AC_USE_SYSTEM_EXTENSIONS])
2N/A
2N/A AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
2N/A AC_REQUIRE([gl_HEADER_STRING_H_DEFAULTS])
2N/A AC_CHECK_DECLS_ONCE([strndup])
2N/A AC_CHECK_FUNCS_ONCE([strndup])
2N/A if test $ac_cv_have_decl_strndup = no; then
2N/A HAVE_DECL_STRNDUP=0
2N/A fi
2N/A
2N/A if test $ac_cv_func_strndup = yes; then
2N/A # AIX 4.3.3, AIX 5.1 have a function that fails to add the terminating '\0'.
2N/A AC_CACHE_CHECK([for working strndup], [gl_cv_func_strndup_works],
2N/A [AC_RUN_IFELSE([
2N/A AC_LANG_PROGRAM([[#include <string.h>
2N/A #include <stdlib.h>]], [[
2N/A#ifndef HAVE_DECL_STRNDUP
2N/A extern char *strndup (const char *, size_t);
2N/A#endif
2N/A char *s;
2N/A s = strndup ("some longer string", 15);
2N/A free (s);
2N/A s = strndup ("shorter string", 13);
2N/A return s[13] != '\0';]])],
2N/A [gl_cv_func_strndup_works=yes],
2N/A [gl_cv_func_strndup_works=no],
2N/A [
2N/Achangequote(,)dnl
2N/A case $host_os in
2N/A aix | aix[3-6]*) gl_cv_func_strndup_works="guessing no";;
2N/A *) gl_cv_func_strndup_works="guessing yes";;
2N/A esac
2N/Achangequote([,])dnl
2N/A ])])
2N/A case $gl_cv_func_strndup_works in
2N/A *no)
2N/A REPLACE_STRNDUP=1
2N/A AC_LIBOBJ([strndup])
2N/A ;;
2N/A esac
2N/A else
2N/A AC_LIBOBJ([strndup])
2N/A fi
2N/A])