getdelim.m4 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. # getdelim.m4 serial 10
  2. dnl Copyright (C) 2005-2007, 2009-2013 Free Software Foundation, Inc.
  3. dnl
  4. dnl This file is free software; the Free Software Foundation
  5. dnl gives unlimited permission to copy and/or distribute it,
  6. dnl with or without modifications, as long as this notice is preserved.
  7. AC_PREREQ([2.59])
  8. AC_DEFUN([gl_FUNC_GETDELIM],
  9. [
  10. AC_REQUIRE([gl_STDIO_H_DEFAULTS])
  11. dnl Persuade glibc <stdio.h> to declare getdelim().
  12. AC_REQUIRE([AC_USE_SYSTEM_EXTENSIONS])
  13. AC_CHECK_DECLS_ONCE([getdelim])
  14. AC_CHECK_FUNCS_ONCE([getdelim])
  15. if test $ac_cv_func_getdelim = yes; then
  16. HAVE_GETDELIM=1
  17. dnl Found it in some library. Verify that it works.
  18. AC_CACHE_CHECK([for working getdelim function], [gl_cv_func_working_getdelim],
  19. [echo fooNbarN | tr -d '\012' | tr N '\012' > conftest.data
  20. AC_RUN_IFELSE([AC_LANG_SOURCE([[
  21. # include <stdio.h>
  22. # include <stdlib.h>
  23. # include <string.h>
  24. int main ()
  25. {
  26. FILE *in = fopen ("./conftest.data", "r");
  27. if (!in)
  28. return 1;
  29. {
  30. /* Test result for a NULL buffer and a zero size.
  31. Based on a test program from Karl Heuer. */
  32. char *line = NULL;
  33. size_t siz = 0;
  34. int len = getdelim (&line, &siz, '\n', in);
  35. if (!(len == 4 && line && strcmp (line, "foo\n") == 0))
  36. return 2;
  37. }
  38. {
  39. /* Test result for a NULL buffer and a non-zero size.
  40. This crashes on FreeBSD 8.0. */
  41. char *line = NULL;
  42. size_t siz = (size_t)(~0) / 4;
  43. if (getdelim (&line, &siz, '\n', in) == -1)
  44. return 3;
  45. }
  46. return 0;
  47. }
  48. ]])], [gl_cv_func_working_getdelim=yes] dnl The library version works.
  49. , [gl_cv_func_working_getdelim=no] dnl The library version does NOT work.
  50. , dnl We're cross compiling. Assume it works on glibc2 systems.
  51. [AC_EGREP_CPP([Lucky GNU user],
  52. [
  53. #include <features.h>
  54. #ifdef __GNU_LIBRARY__
  55. #if (__GLIBC__ >= 2) && !defined __UCLIBC__
  56. Lucky GNU user
  57. #endif
  58. #endif
  59. ],
  60. [gl_cv_func_working_getdelim="guessing yes"],
  61. [gl_cv_func_working_getdelim="guessing no"])]
  62. )])
  63. case "$gl_cv_func_working_getdelim" in
  64. *no)
  65. REPLACE_GETDELIM=1
  66. ;;
  67. esac
  68. else
  69. HAVE_GETDELIM=0
  70. fi
  71. if test $ac_cv_have_decl_getdelim = no; then
  72. HAVE_DECL_GETDELIM=0
  73. fi
  74. ])
  75. # Prerequisites of lib/getdelim.c.
  76. AC_DEFUN([gl_PREREQ_GETDELIM],
  77. [
  78. AC_CHECK_FUNCS([flockfile funlockfile])
  79. AC_CHECK_DECLS([getc_unlocked])
  80. ])