getline.m4 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. # getline.m4 serial 26
  2. dnl Copyright (C) 1998-2003, 2005-2007, 2009-2013 Free Software Foundation,
  3. dnl Inc.
  4. dnl
  5. dnl This file is free software; the Free Software Foundation
  6. dnl gives unlimited permission to copy and/or distribute it,
  7. dnl with or without modifications, as long as this notice is preserved.
  8. AC_PREREQ([2.59])
  9. dnl See if there's a working, system-supplied version of the getline function.
  10. dnl We can't just do AC_REPLACE_FUNCS([getline]) because some systems
  11. dnl have a function by that name in -linet that doesn't have anything
  12. dnl to do with the function we need.
  13. AC_DEFUN([gl_FUNC_GETLINE],
  14. [
  15. AC_REQUIRE([gl_STDIO_H_DEFAULTS])
  16. dnl Persuade glibc <stdio.h> to declare getline().
  17. AC_REQUIRE([AC_USE_SYSTEM_EXTENSIONS])
  18. AC_CHECK_DECLS_ONCE([getline])
  19. gl_getline_needs_run_time_check=no
  20. AC_CHECK_FUNC([getline],
  21. [dnl Found it in some library. Verify that it works.
  22. gl_getline_needs_run_time_check=yes],
  23. [am_cv_func_working_getline=no])
  24. if test $gl_getline_needs_run_time_check = yes; then
  25. AC_CACHE_CHECK([for working getline function], [am_cv_func_working_getline],
  26. [echo fooNbarN | tr -d '\012' | tr N '\012' > conftest.data
  27. AC_RUN_IFELSE([AC_LANG_SOURCE([[
  28. # include <stdio.h>
  29. # include <stdlib.h>
  30. # include <string.h>
  31. int main ()
  32. {
  33. FILE *in = fopen ("./conftest.data", "r");
  34. if (!in)
  35. return 1;
  36. {
  37. /* Test result for a NULL buffer and a zero size.
  38. Based on a test program from Karl Heuer. */
  39. char *line = NULL;
  40. size_t siz = 0;
  41. int len = getline (&line, &siz, in);
  42. if (!(len == 4 && line && strcmp (line, "foo\n") == 0))
  43. return 2;
  44. }
  45. {
  46. /* Test result for a NULL buffer and a non-zero size.
  47. This crashes on FreeBSD 8.0. */
  48. char *line = NULL;
  49. size_t siz = (size_t)(~0) / 4;
  50. if (getline (&line, &siz, in) == -1)
  51. return 3;
  52. }
  53. return 0;
  54. }
  55. ]])], [am_cv_func_working_getline=yes] dnl The library version works.
  56. , [am_cv_func_working_getline=no] dnl The library version does NOT work.
  57. , dnl We're cross compiling. Assume it works on glibc2 systems.
  58. [AC_EGREP_CPP([Lucky GNU user],
  59. [
  60. #include <features.h>
  61. #ifdef __GNU_LIBRARY__
  62. #if (__GLIBC__ >= 2) && !defined __UCLIBC__
  63. Lucky GNU user
  64. #endif
  65. #endif
  66. ],
  67. [am_cv_func_working_getline="guessing yes"],
  68. [am_cv_func_working_getline="guessing no"])]
  69. )])
  70. fi
  71. if test $ac_cv_have_decl_getline = no; then
  72. HAVE_DECL_GETLINE=0
  73. fi
  74. case "$am_cv_func_working_getline" in
  75. *no)
  76. dnl Set REPLACE_GETLINE always: Even if we have not found the broken
  77. dnl getline function among $LIBS, it may exist in libinet and the
  78. dnl executable may be linked with -linet.
  79. REPLACE_GETLINE=1
  80. ;;
  81. esac
  82. ])
  83. # Prerequisites of lib/getline.c.
  84. AC_DEFUN([gl_PREREQ_GETLINE],
  85. [
  86. :
  87. ])