Bump to m4 1.4.19
[platform/upstream/m4.git] / m4 / strndup.m4
1 # strndup.m4 serial 23
2 dnl Copyright (C) 2002-2003, 2005-2021 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.
6
7 AC_DEFUN([gl_FUNC_STRNDUP],
8 [
9   dnl Persuade glibc <string.h> to declare strndup().
10   AC_REQUIRE([AC_USE_SYSTEM_EXTENSIONS])
11
12   AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
13   AC_REQUIRE([gl_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
17     HAVE_DECL_STRNDUP=0
18   fi
19
20   if test $ac_cv_func_strndup = yes; then
21     HAVE_STRNDUP=1
22     # AIX 4.3.3, AIX 5.1 have a function that fails to add the terminating '\0'.
23     AC_CACHE_CHECK([for working strndup], [gl_cv_func_strndup_works],
24       [AC_RUN_IFELSE([
25          AC_LANG_PROGRAM([[#include <string.h>
26                            #include <stdlib.h>]], [[
27 #if !HAVE_DECL_STRNDUP
28   extern
29   #ifdef __cplusplus
30   "C"
31   #endif
32   char *strndup (const char *, size_t);
33 #endif
34   int result;
35   char *s;
36   s = strndup ("some longer string", 15);
37   free (s);
38   s = strndup ("shorter string", 13);
39   result = s[13] != '\0';
40   free (s);
41   return result;]])],
42          [gl_cv_func_strndup_works=yes],
43          [gl_cv_func_strndup_works=no],
44          [
45 changequote(,)dnl
46           case $host_os in
47             aix | aix[3-6]*) gl_cv_func_strndup_works="guessing no";;
48             *)               gl_cv_func_strndup_works="guessing yes";;
49           esac
50 changequote([,])dnl
51          ])])
52     case $gl_cv_func_strndup_works in
53       *no) REPLACE_STRNDUP=1 ;;
54     esac
55   else
56     HAVE_STRNDUP=0
57   fi
58 ])