Debian Codegraph @

m4/getline.m4

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