Debian Codegraph @

m4/getdelim.m4

raw
1 # getdelim.m4
2 # serial 21
3
4 dnl Copyright (C) 2005-2007, 2009-2026 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 touch conftest.empty
41 AC_RUN_IFELSE([AC_LANG_SOURCE([[
42 # include <stdio.h>
43 # include <stdlib.h>
44 # include <string.h>
45 int main ()
46 {
47 FILE *in = fopen ("./conftest.data", "r");
48 int result = 0;
49 if (!in)
50 return 1;
51 {
52 /* Test result for a NULL buffer and a zero size.
53 Based on a test program from Karl Heuer. */
54 char *line = NULL;
55 size_t siz = 0;
56 int len = getdelim (&line, &siz, '\n', in);
57 if (!(len == 4 && line && strcmp (line, "foo\n") == 0))
58 result |= 2;
59 free (line);
60 }
61 {
62 /* Test result for a NULL buffer and a non-zero size.
63 This crashes on FreeBSD 8.0. */
64 char *line = NULL;
65 size_t siz = (size_t)(~0) / 4;
66 if (getdelim (&line, &siz, '\n', in) == -1)
67 result |= 4;
68 free (line);
69 }
70 fclose (in);
71 {
72 /* Test that reading EOF as the first character sets the first byte
73 in the buffer to NUL. This fails on glibc 2.42 and earlier. */
74 in = fopen ("./conftest.empty", "r");
75 if (!in)
76 return 1;
77 char *line = malloc (1);
78 line[0] = 'A';
79 size_t siz = 1;
80 if (getdelim (&line, &siz, '\n', in) != -1 || line[0] != '\0')
81 result |= 8;
82 free (line);
83 }
84 fclose (in);
85 return result;
86 }
87 ]])],
88 [gl_cv_func_working_getdelim=yes],
89 [gl_cv_func_working_getdelim=no],
90 [case "$host_os" in
91 # Guess yes on musl.
92 *-musl* | midipix*) gl_cv_func_working_getdelim="guessing yes" ;;
93 # Guess no on glibc.
94 *-gnu* | gnu*) gl_cv_func_working_getdelim="guessing no" ;;
95 *) gl_cv_func_working_getdelim="$gl_cross_guess_normal" ;;
96 esac
97 ])
98 ;;
99 esac
100 rm -f conftest.data conftest.empty
101 ])
102 case "$gl_cv_func_working_getdelim" in
103 *yes) ;;
104 *) REPLACE_GETDELIM=1 ;;
105 esac
106 else
107 HAVE_GETDELIM=0
108 case "$gl_cv_onwards_func_getdelim" in
109 future*) REPLACE_GETDELIM=1 ;;
110 esac
111 fi
112
113 if test $ac_cv_have_decl_getdelim = no; then
114 HAVE_DECL_GETDELIM=0
115 fi
116 ])
117
118 # Prerequisites of lib/getdelim.c.
119 AC_DEFUN([gl_PREREQ_GETDELIM],
120 [
121 AC_CHECK_FUNCS([flockfile funlockfile])
122 AC_CHECK_DECLS([getc_unlocked])
123 ])