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.m452
1 files changed, 30 insertions, 22 deletions
diff --git a/gl/m4/getdelim.m4 b/gl/m4/getdelim.m4
index 61139039..8b6eff47 100644
--- a/gl/m4/getdelim.m4
+++ b/gl/m4/getdelim.m4
@@ -1,11 +1,12 @@
1# getdelim.m4 1# getdelim.m4
2# serial 19 2# serial 21
3 3
4dnl Copyright (C) 2005-2007, 2009-2024 Free Software Foundation, Inc. 4dnl Copyright (C) 2005-2007, 2009-2026 Free Software Foundation, Inc.
5dnl 5dnl
6dnl This file is free software; the Free Software Foundation 6dnl This file is free software; the Free Software Foundation
7dnl gives unlimited permission to copy and/or distribute it, 7dnl gives unlimited permission to copy and/or distribute it,
8dnl 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.
9 10
10AC_PREREQ([2.59]) 11AC_PREREQ([2.59])
11 12
@@ -36,6 +37,7 @@ AC_DEFUN([gl_FUNC_GETDELIM],
36 gl_cv_func_working_getdelim=no ;; 37 gl_cv_func_working_getdelim=no ;;
37 *) 38 *)
38 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
39 AC_RUN_IFELSE([AC_LANG_SOURCE([[ 41 AC_RUN_IFELSE([AC_LANG_SOURCE([[
40# include <stdio.h> 42# include <stdio.h>
41# include <stdlib.h> 43# include <stdlib.h>
@@ -43,6 +45,7 @@ AC_DEFUN([gl_FUNC_GETDELIM],
43 int main () 45 int main ()
44 { 46 {
45 FILE *in = fopen ("./conftest.data", "r"); 47 FILE *in = fopen ("./conftest.data", "r");
48 int result = 0;
46 if (!in) 49 if (!in)
47 return 1; 50 return 1;
48 { 51 {
@@ -52,7 +55,7 @@ AC_DEFUN([gl_FUNC_GETDELIM],
52 size_t siz = 0; 55 size_t siz = 0;
53 int len = getdelim (&line, &siz, '\n', in); 56 int len = getdelim (&line, &siz, '\n', in);
54 if (!(len == 4 && line && strcmp (line, "foo\n") == 0)) 57 if (!(len == 4 && line && strcmp (line, "foo\n") == 0))
55 { free (line); fclose (in); return 2; } 58 result |= 2;
56 free (line); 59 free (line);
57 } 60 }
58 { 61 {
@@ -61,35 +64,40 @@ AC_DEFUN([gl_FUNC_GETDELIM],
61 char *line = NULL; 64 char *line = NULL;
62 size_t siz = (size_t)(~0) / 4; 65 size_t siz = (size_t)(~0) / 4;
63 if (getdelim (&line, &siz, '\n', in) == -1) 66 if (getdelim (&line, &siz, '\n', in) == -1)
64 { fclose (in); return 3; } 67 result |= 4;
65 free (line); 68 free (line);
66 } 69 }
67 fclose (in); 70 fclose (in);
68 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;
69 } 86 }
70 ]])], 87 ]])],
71 [gl_cv_func_working_getdelim=yes], 88 [gl_cv_func_working_getdelim=yes],
72 [gl_cv_func_working_getdelim=no], 89 [gl_cv_func_working_getdelim=no],
73 [dnl We're cross compiling. 90 [case "$host_os" in
74 dnl Guess it works on glibc2 systems and musl systems. 91 # Guess yes on musl.
75 AC_EGREP_CPP([Lucky GNU user], 92 *-musl* | midipix*) gl_cv_func_working_getdelim="guessing yes" ;;
76 [ 93 # Guess no on glibc.
77#include <features.h> 94 *-gnu* | gnu*) gl_cv_func_working_getdelim="guessing no" ;;
78#ifdef __GNU_LIBRARY__ 95 *) gl_cv_func_working_getdelim="$gl_cross_guess_normal" ;;
79 #if (__GLIBC__ >= 2) && !defined __UCLIBC__ 96 esac
80 Lucky GNU user
81 #endif
82#endif
83 ],
84 [gl_cv_func_working_getdelim="guessing yes"],
85 [case "$host_os" in
86 *-musl* | midipix*) gl_cv_func_working_getdelim="guessing yes" ;;
87 *) gl_cv_func_working_getdelim="$gl_cross_guess_normal" ;;
88 esac
89 ])
90 ]) 97 ])
91 ;; 98 ;;
92 esac 99 esac
100 rm -f conftest.data conftest.empty
93 ]) 101 ])
94 case "$gl_cv_func_working_getdelim" in 102 case "$gl_cv_func_working_getdelim" in
95 *yes) ;; 103 *yes) ;;