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