Debian Codegraph @

m4/getline.m4

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