Debian Codegraph @

m4/getdelim.m4

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