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