summaryrefslogtreecommitdiffstats
path: root/gl/m4/getdelim.m4
diff options
context:
space:
mode:
Diffstat (limited to 'gl/m4/getdelim.m4')
-rw-r--r--gl/m4/getdelim.m458
1 files changed, 35 insertions, 23 deletions
diff --git a/gl/m4/getdelim.m4 b/gl/m4/getdelim.m4
index 9aaed202..8b6eff47 100644
--- a/gl/m4/getdelim.m4
+++ b/gl/m4/getdelim.m4
@@ -1,10 +1,12 @@
1# getdelim.m4 serial 16 1# getdelim.m4
2# serial 21
2 3
3dnl Copyright (C) 2005-2007, 2009-2023 Free Software Foundation, Inc. 4dnl Copyright (C) 2005-2007, 2009-2026 Free Software Foundation, Inc.
4dnl 5dnl
5dnl This file is free software; the Free Software Foundation 6dnl This file is free software; the Free Software Foundation
6dnl gives unlimited permission to copy and/or distribute it, 7dnl gives unlimited permission to copy and/or distribute it,
7dnl with or without modifications, as long as this notice is preserved. 8dnl with or without modifications, as long as this notice is preserved.
9dnl This file is offered as-is, without any warranty.
8 10
9AC_PREREQ([2.59]) 11AC_PREREQ([2.59])
10 12
@@ -18,7 +20,7 @@ AC_DEFUN([gl_FUNC_GETDELIM],
18 20
19 AC_CHECK_DECLS_ONCE([getdelim]) 21 AC_CHECK_DECLS_ONCE([getdelim])
20 22
21 AC_CHECK_FUNCS_ONCE([getdelim]) 23 gl_CHECK_FUNCS_ANDROID([getdelim], [[#include <stdio.h>]])
22 if test $ac_cv_func_getdelim = yes; then 24 if test $ac_cv_func_getdelim = yes; then
23 HAVE_GETDELIM=1 25 HAVE_GETDELIM=1
24 dnl Found it in some library. Verify that it works. 26 dnl Found it in some library. Verify that it works.
@@ -35,6 +37,7 @@ AC_DEFUN([gl_FUNC_GETDELIM],
35 gl_cv_func_working_getdelim=no ;; 37 gl_cv_func_working_getdelim=no ;;
36 *) 38 *)
37 echo fooNbarN | tr -d '\012' | tr N '\012' > conftest.data 39 echo fooNbarN | tr -d '\012' | tr N '\012' > conftest.data
40 touch conftest.empty
38 AC_RUN_IFELSE([AC_LANG_SOURCE([[ 41 AC_RUN_IFELSE([AC_LANG_SOURCE([[
39# include <stdio.h> 42# include <stdio.h>
40# include <stdlib.h> 43# include <stdlib.h>
@@ -42,6 +45,7 @@ AC_DEFUN([gl_FUNC_GETDELIM],
42 int main () 45 int main ()
43 { 46 {
44 FILE *in = fopen ("./conftest.data", "r"); 47 FILE *in = fopen ("./conftest.data", "r");
48 int result = 0;
45 if (!in) 49 if (!in)
46 return 1; 50 return 1;
47 { 51 {
@@ -51,7 +55,7 @@ AC_DEFUN([gl_FUNC_GETDELIM],
51 size_t siz = 0; 55 size_t siz = 0;
52 int len = getdelim (&line, &siz, '\n', in); 56 int len = getdelim (&line, &siz, '\n', in);
53 if (!(len == 4 && line && strcmp (line, "foo\n") == 0)) 57 if (!(len == 4 && line && strcmp (line, "foo\n") == 0))
54 { free (line); fclose (in); return 2; } 58 result |= 2;
55 free (line); 59 free (line);
56 } 60 }
57 { 61 {
@@ -60,35 +64,40 @@ AC_DEFUN([gl_FUNC_GETDELIM],
60 char *line = NULL; 64 char *line = NULL;
61 size_t siz = (size_t)(~0) / 4; 65 size_t siz = (size_t)(~0) / 4;
62 if (getdelim (&line, &siz, '\n', in) == -1) 66 if (getdelim (&line, &siz, '\n', in) == -1)
63 { fclose (in); return 3; } 67 result |= 4;
64 free (line); 68 free (line);
65 } 69 }
66 fclose (in); 70 fclose (in);
67 return 0; 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;
68 } 86 }
69 ]])], 87 ]])],
70 [gl_cv_func_working_getdelim=yes], 88 [gl_cv_func_working_getdelim=yes],
71 [gl_cv_func_working_getdelim=no], 89 [gl_cv_func_working_getdelim=no],
72 [dnl We're cross compiling. 90 [case "$host_os" in
73 dnl Guess it works on glibc2 systems and musl systems. 91 # Guess yes on musl.
74 AC_EGREP_CPP([Lucky GNU user], 92 *-musl* | midipix*) gl_cv_func_working_getdelim="guessing yes" ;;
75 [ 93 # Guess no on glibc.
76#include <features.h> 94 *-gnu* | gnu*) gl_cv_func_working_getdelim="guessing no" ;;
77#ifdef __GNU_LIBRARY__ 95 *) gl_cv_func_working_getdelim="$gl_cross_guess_normal" ;;
78 #if (__GLIBC__ >= 2) && !defined __UCLIBC__ 96 esac
79 Lucky GNU user
80 #endif
81#endif
82 ],
83 [gl_cv_func_working_getdelim="guessing yes"],
84 [case "$host_os" in
85 *-musl*) gl_cv_func_working_getdelim="guessing yes" ;;
86 *) gl_cv_func_working_getdelim="$gl_cross_guess_normal" ;;
87 esac
88 ])
89 ]) 97 ])
90 ;; 98 ;;
91 esac 99 esac
100 rm -f conftest.data conftest.empty
92 ]) 101 ])
93 case "$gl_cv_func_working_getdelim" in 102 case "$gl_cv_func_working_getdelim" in
94 *yes) ;; 103 *yes) ;;
@@ -96,6 +105,9 @@ AC_DEFUN([gl_FUNC_GETDELIM],
96 esac 105 esac
97 else 106 else
98 HAVE_GETDELIM=0 107 HAVE_GETDELIM=0
108 case "$gl_cv_onwards_func_getdelim" in
109 future*) REPLACE_GETDELIM=1 ;;
110 esac
99 fi 111 fi
100 112
101 if test $ac_cv_have_decl_getdelim = no; then 113 if test $ac_cv_have_decl_getdelim = no; then