Debian Codegraph @

m4/getdelim.m4

raw
1 # getdelim.m4
2 # serial 19
3
4 dnl Copyright (C) 2005-2007, 2009-2024 Free Software Foundation, 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 dnl This file is offered as-is, without any warranty.
10
11 AC_PREREQ([2.59])
12
13 AC_DEFUN([gl_FUNC_GETDELIM],
14 [
15 AC_REQUIRE([gl_STDIO_H_DEFAULTS])
16 AC_REQUIRE([AC_CANONICAL_HOST])
17
18 dnl Persuade glibc <stdio.h> to declare getdelim().
19 AC_REQUIRE([AC_USE_SYSTEM_EXTENSIONS])
20
21 AC_CHECK_DECLS_ONCE([getdelim])
22
23 gl_CHECK_FUNCS_ANDROID([getdelim], [[#include <stdio.h>]])
24 if test $ac_cv_func_getdelim = yes; then
25 HAVE_GETDELIM=1
26 dnl Found it in some library. Verify that it works.
27 AC_CACHE_CHECK([for working getdelim function],
28 [gl_cv_func_working_getdelim],
29 [case "$host_os" in
30 darwin*)
31 dnl On macOS 10.13, valgrind detected an out-of-bounds read during
32 dnl the GNU sed test suite:
33 dnl Invalid read of size 16
34 dnl at 0x100EE6A05: _platform_memchr$VARIANT$Base (in /usr/lib/system/libsystem_platform.dylib)
35 dnl by 0x100B7B0BD: getdelim (in /usr/lib/system/libsystem_c.dylib)
36 dnl by 0x10000B0BE: ck_getdelim (utils.c:254)
37 gl_cv_func_working_getdelim=no ;;
38 *)
39 echo fooNbarN | tr -d '\012' | tr N '\012' > conftest.data
40 AC_RUN_IFELSE([AC_LANG_SOURCE([[
41 # include <stdio.h>
42 # include <stdlib.h>
43 # include <string.h>
44 int main ()
45 {
46 FILE *in = fopen ("./conftest.data", "r");
47 if (!in)
48 return 1;
49 {
50 /* Test result for a NULL buffer and a zero size.
51 Based on a test program from Karl Heuer. */
52 char *line = NULL;
53 size_t siz = 0;
54 int len = getdelim (&line, &siz, '\n', in);
55 if (!(len == 4 && line && strcmp (line, "foo\n") == 0))
56 { free (line); fclose (in); return 2; }
57 free (line);
58 }
59 {
60 /* Test result for a NULL buffer and a non-zero size.
61 This crashes on FreeBSD 8.0. */
62 char *line = NULL;
63 size_t siz = (size_t)(~0) / 4;
64 if (getdelim (&line, &siz, '\n', in) == -1)
65 { fclose (in); return 3; }
66 free (line);
67 }
68 fclose (in);
69 return 0;
70 }
71 ]])],
72 [gl_cv_func_working_getdelim=yes],
73 [gl_cv_func_working_getdelim=no],
74 [dnl We're cross compiling.
75 dnl Guess it works on glibc2 systems and musl systems.
76 AC_EGREP_CPP([Lucky GNU user],
77 [
78 #include <features.h>
79 #ifdef __GNU_LIBRARY__
80 #if (__GLIBC__ >= 2) && !defined __UCLIBC__
81 Lucky GNU user
82 #endif
83 #endif
84 ],
85 [gl_cv_func_working_getdelim="guessing yes"],
86 [case "$host_os" in
87 *-musl* | midipix*) gl_cv_func_working_getdelim="guessing yes" ;;
88 *) gl_cv_func_working_getdelim="$gl_cross_guess_normal" ;;
89 esac
90 ])
91 ])
92 ;;
93 esac
94 ])
95 case "$gl_cv_func_working_getdelim" in
96 *yes) ;;
97 *) REPLACE_GETDELIM=1 ;;
98 esac
99 else
100 HAVE_GETDELIM=0
101 case "$gl_cv_onwards_func_getdelim" in
102 future*) REPLACE_GETDELIM=1 ;;
103 esac
104 fi
105
106 if test $ac_cv_have_decl_getdelim = no; then
107 HAVE_DECL_GETDELIM=0
108 fi
109 ])
110
111 # Prerequisites of lib/getdelim.c.
112 AC_DEFUN([gl_PREREQ_GETDELIM],
113 [
114 AC_CHECK_FUNCS([flockfile funlockfile])
115 AC_CHECK_DECLS([getc_unlocked])
116 ])