strndup.m4 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. # strndup.m4 serial 16
  2. dnl Copyright (C) 2002-2003, 2005-2009 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. AC_DEFUN([gl_FUNC_STRNDUP],
  7. [
  8. dnl Persuade glibc <string.h> to declare strndup().
  9. AC_REQUIRE([AC_USE_SYSTEM_EXTENSIONS])
  10. AC_REQUIRE([gl_HEADER_STRING_H_DEFAULTS])
  11. AC_CHECK_DECLS_ONCE([strndup])
  12. if test $ac_cv_have_decl_strndup = no; then
  13. HAVE_DECL_STRNDUP=0
  14. fi
  15. # AIX 4.3.3, AIX 5.1 have a function that fails to add the terminating '\0'.
  16. AC_CACHE_CHECK([for working strndup], [gl_cv_func_strndup],
  17. [AC_RUN_IFELSE([
  18. AC_LANG_PROGRAM([[#include <string.h>
  19. #include <stdlib.h>]], [[
  20. #ifndef HAVE_DECL_STRNDUP
  21. extern char *strndup (const char *, size_t);
  22. #endif
  23. char *s;
  24. s = strndup ("some longer string", 15);
  25. free (s);
  26. s = strndup ("shorter string", 13);
  27. return s[13] != '\0';]])],
  28. [gl_cv_func_strndup=yes],
  29. [gl_cv_func_strndup=no],
  30. [AC_CHECK_FUNC([strndup],
  31. [AC_EGREP_CPP([too risky], [
  32. #ifdef _AIX
  33. too risky
  34. #endif
  35. ],
  36. [gl_cv_func_strndup=no],
  37. [gl_cv_func_strndup=yes])],
  38. [gl_cv_func_strndup=no])])])
  39. if test $gl_cv_func_strndup = yes; then
  40. AC_DEFINE([HAVE_STRNDUP], [1],
  41. [Define if you have the strndup() function and it works.])
  42. else
  43. HAVE_STRNDUP=0
  44. AC_LIBOBJ([strndup])
  45. gl_PREREQ_STRNDUP
  46. fi
  47. ])
  48. # Prerequisites of lib/strndup.c.
  49. AC_DEFUN([gl_PREREQ_STRNDUP], [:])