strndup.m4 1.4 KB

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