2 dnl Copyright (C) 2002-2003, 2005-2010 Free Software Foundation, Inc.
3 dnl This file is free software; the Free Software Foundation
4 dnl gives unlimited permission to copy and/or distribute it,
5 dnl with or without modifications, as long as this notice is preserved.
7 AC_DEFUN([gl_FUNC_STRNDUP],
9 dnl Persuade glibc <string.h> to declare strndup().
10 AC_REQUIRE([AC_USE_SYSTEM_EXTENSIONS])
12 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
13 AC_REQUIRE([gl_HEADER_STRING_H_DEFAULTS])
14 AC_CHECK_DECLS_ONCE([strndup])
15 AC_CHECK_FUNCS_ONCE([strndup])
16 if test $ac_cv_have_decl_strndup = no; then
20 if test $ac_cv_func_strndup = yes; then
21 # AIX 4.3.3, AIX 5.1 have a function that fails to add the terminating '\0'.
22 AC_CACHE_CHECK([for working strndup], [gl_cv_func_strndup_works],
24 AC_LANG_PROGRAM([[#include <string.h>
25 #include <stdlib.h>]], [[
26 #ifndef HAVE_DECL_STRNDUP
27 extern char *strndup (const char *, size_t);
30 s = strndup ("some longer string", 15);
32 s = strndup ("shorter string", 13);
33 return s[13] != '\0';]])],
34 [gl_cv_func_strndup_works=yes],
35 [gl_cv_func_strndup_works=no],
37 aix*) gl_cv_func_strndup_works="guessing no";;
38 *) gl_cv_func_strndup_works="guessing yes";;
40 case $gl_cv_func_strndup_works in