view m4/strndup.m4 @ 15438:591ddd1ddd1a

Declare system functions in a way that works with C++. * m4/fdopendir.m4 (gl_FUNC_FDOPENDIR) [C++]: In the test program, declare fdopendir as extern "C". * m4/frexpl.m4 (gl_FUNC_FREXPL_WORKS) [C++]: In the test program, declare frexpl as extern "C". * m4/getaddrinfo.m4 (gl_GETADDRINFO) [C++]: In the test program, declare gai_strerror as extern "C". * m4/getdomainname.m4 (gl_FUNC_GETDOMAINNAME) [C++]: In the test programs, declare gai_strerror as extern "C". * m4/getlogin_r.m4 (gl_FUNC_GETLOGIN_R) [C++]: In the test program, declare getlogin_r as extern "C". * m4/ioctl.m4 (gl_FUNC_IOCTL) [C++]: In the test program, declare ioctl as extern "C". * m4/ldexpl.m4 (gl_FUNC_LDEXPL_WORKS) [C++]: In the test program, declare ldexpl as extern "C". * m4/logb.m4 (gl_FUNC_LOGB) [C++]: In the test programs, declare logb as extern "C". * m4/ls-mntd-fs.m4 (gl_LIST_MOUNTED_FILE_SYSTEMS) [C++]: In the test program, declare getmntinfo as extern "C". * m4/stpncpy.m4 (gl_FUNC_STPNCPY) [C++]: In the test program, declare stpncpy as extern "C". * m4/strerror_r.m4 (gl_FUNC_STRERROR_R_WORKS) [C++]: In the test program, declare __xpg_strerror_r as extern "C". * m4/strndup.m4 (gl_FUNC_STRNDUP) [C++]: In the test program, declare strndup as extern "C". * m4/sys_select_h.m4 (gl_HEADER_SYS_SELECT) [C++]: In the test program, declare memset and bzero as extern "C". Reported by Sam Steingold <sds@gnu.org>.
author Bruno Haible <bruno@clisp.org>
date Fri, 22 Jul 2011 00:16:46 +0200
parents ed77fe40c360
children 8250f2777afc
line wrap: on
line source

# strndup.m4 serial 20
dnl Copyright (C) 2002-2003, 2005-2011 Free Software Foundation, Inc.
dnl This file is free software; the Free Software Foundation
dnl gives unlimited permission to copy and/or distribute it,
dnl with or without modifications, as long as this notice is preserved.

AC_DEFUN([gl_FUNC_STRNDUP],
[
  dnl Persuade glibc <string.h> to declare strndup().
  AC_REQUIRE([AC_USE_SYSTEM_EXTENSIONS])

  AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
  AC_REQUIRE([gl_HEADER_STRING_H_DEFAULTS])
  AC_CHECK_DECLS_ONCE([strndup])
  AC_CHECK_FUNCS_ONCE([strndup])
  if test $ac_cv_have_decl_strndup = no; then
    HAVE_DECL_STRNDUP=0
  fi

  if test $ac_cv_func_strndup = yes; then
    HAVE_STRNDUP=1
    # AIX 4.3.3, AIX 5.1 have a function that fails to add the terminating '\0'.
    AC_CACHE_CHECK([for working strndup], [gl_cv_func_strndup_works],
      [AC_RUN_IFELSE([
         AC_LANG_PROGRAM([[#include <string.h>
                           #include <stdlib.h>]], [[
#ifndef HAVE_DECL_STRNDUP
  extern
  #ifdef __cplusplus
  "C"
  #endif
  char *strndup (const char *, size_t);
#endif
  char *s;
  s = strndup ("some longer string", 15);
  free (s);
  s = strndup ("shorter string", 13);
  return s[13] != '\0';]])],
         [gl_cv_func_strndup_works=yes],
         [gl_cv_func_strndup_works=no],
         [
changequote(,)dnl
          case $host_os in
            aix | aix[3-6]*) gl_cv_func_strndup_works="guessing no";;
            *)               gl_cv_func_strndup_works="guessing yes";;
          esac
changequote([,])dnl
         ])])
    case $gl_cv_func_strndup_works in
      *no) REPLACE_STRNDUP=1 ;;
    esac
  else
    HAVE_STRNDUP=0
  fi
])