diff options
Diffstat (limited to 'gl/m4/getline.m4')
| -rw-r--r-- | gl/m4/getline.m4 | 52 |
1 files changed, 30 insertions, 22 deletions
diff --git a/gl/m4/getline.m4 b/gl/m4/getline.m4 index 36513cd4..ed32fa10 100644 --- a/gl/m4/getline.m4 +++ b/gl/m4/getline.m4 | |||
| @@ -1,12 +1,13 @@ | |||
| 1 | # getline.m4 | 1 | # getline.m4 |
| 2 | # serial 33 | 2 | # serial 35 |
| 3 | 3 | ||
| 4 | dnl Copyright (C) 1998-2003, 2005-2007, 2009-2024 Free Software Foundation, | 4 | dnl Copyright (C) 1998-2003, 2005-2007, 2009-2026 Free Software Foundation, |
| 5 | dnl Inc. | 5 | dnl Inc. |
| 6 | dnl | 6 | dnl |
| 7 | dnl This file is free software; the Free Software Foundation | 7 | dnl This file is free software; the Free Software Foundation |
| 8 | dnl gives unlimited permission to copy and/or distribute it, | 8 | dnl gives unlimited permission to copy and/or distribute it, |
| 9 | dnl with or without modifications, as long as this notice is preserved. | 9 | dnl with or without modifications, as long as this notice is preserved. |
| 10 | dnl This file is offered as-is, without any warranty. | ||
| 10 | 11 | ||
| 11 | AC_PREREQ([2.59]) | 12 | AC_PREREQ([2.59]) |
| 12 | 13 | ||
| @@ -30,6 +31,7 @@ AC_DEFUN([gl_FUNC_GETLINE], | |||
| 30 | AC_CACHE_CHECK([for working getline function], | 31 | AC_CACHE_CHECK([for working getline function], |
| 31 | [am_cv_func_working_getline], | 32 | [am_cv_func_working_getline], |
| 32 | [echo fooNbarN | tr -d '\012' | tr N '\012' > conftest.data | 33 | [echo fooNbarN | tr -d '\012' | tr N '\012' > conftest.data |
| 34 | touch conftest.empty | ||
| 33 | AC_RUN_IFELSE([AC_LANG_SOURCE([[ | 35 | AC_RUN_IFELSE([AC_LANG_SOURCE([[ |
| 34 | # include <stdio.h> | 36 | # include <stdio.h> |
| 35 | # include <stdlib.h> | 37 | # include <stdlib.h> |
| @@ -37,6 +39,7 @@ AC_DEFUN([gl_FUNC_GETLINE], | |||
| 37 | int main () | 39 | int main () |
| 38 | { | 40 | { |
| 39 | FILE *in = fopen ("./conftest.data", "r"); | 41 | FILE *in = fopen ("./conftest.data", "r"); |
| 42 | int result = 0; | ||
| 40 | if (!in) | 43 | if (!in) |
| 41 | return 1; | 44 | return 1; |
| 42 | { | 45 | { |
| @@ -46,7 +49,7 @@ AC_DEFUN([gl_FUNC_GETLINE], | |||
| 46 | size_t siz = 0; | 49 | size_t siz = 0; |
| 47 | int len = getline (&line, &siz, in); | 50 | int len = getline (&line, &siz, in); |
| 48 | if (!(len == 4 && line && strcmp (line, "foo\n") == 0)) | 51 | if (!(len == 4 && line && strcmp (line, "foo\n") == 0)) |
| 49 | { free (line); fclose (in); return 2; } | 52 | result |= 2; |
| 50 | free (line); | 53 | free (line); |
| 51 | } | 54 | } |
| 52 | { | 55 | { |
| @@ -55,33 +58,38 @@ AC_DEFUN([gl_FUNC_GETLINE], | |||
| 55 | char *line = NULL; | 58 | char *line = NULL; |
| 56 | size_t siz = (size_t)(~0) / 4; | 59 | size_t siz = (size_t)(~0) / 4; |
| 57 | if (getline (&line, &siz, in) == -1) | 60 | if (getline (&line, &siz, in) == -1) |
| 58 | { fclose (in); return 3; } | 61 | result |= 4; |
| 59 | free (line); | 62 | free (line); |
| 60 | } | 63 | } |
| 61 | fclose (in); | 64 | fclose (in); |
| 62 | return 0; | 65 | { |
| 66 | /* Test that reading EOF as the first character sets the first byte | ||
| 67 | in the buffer to NUL. This fails on glibc 2.42 and earlier. */ | ||
| 68 | in = fopen ("./conftest.empty", "r"); | ||
| 69 | if (!in) | ||
| 70 | return 1; | ||
| 71 | char *line = malloc (1); | ||
| 72 | line[0] = 'A'; | ||
| 73 | size_t siz = 1; | ||
| 74 | if (getline (&line, &siz, in) != -1 || line[0] != '\0') | ||
| 75 | result |= 8; | ||
| 76 | free (line); | ||
| 77 | } | ||
| 78 | fclose (in); | ||
| 79 | return result; | ||
| 63 | } | 80 | } |
| 64 | ]])], | 81 | ]])], |
| 65 | [am_cv_func_working_getline=yes], | 82 | [am_cv_func_working_getline=yes], |
| 66 | [am_cv_func_working_getline=no], | 83 | [am_cv_func_working_getline=no], |
| 67 | [dnl We're cross compiling. | 84 | [case "$host_os" in |
| 68 | dnl Guess it works on glibc2 systems and musl systems. | 85 | # Guess yes on musl. |
| 69 | AC_EGREP_CPP([Lucky GNU user], | 86 | *-musl* | midipix*) am_cv_func_working_getline="guessing yes" ;; |
| 70 | [ | 87 | # Guess no on glibc. |
| 71 | #include <features.h> | 88 | *-gnu* | gnu*) am_cv_func_working_getline="guessing no" ;; |
| 72 | #ifdef __GNU_LIBRARY__ | 89 | *) am_cv_func_working_getline="$gl_cross_guess_normal" ;; |
| 73 | #if (__GLIBC__ >= 2) && !defined __UCLIBC__ | 90 | esac |
| 74 | Lucky GNU user | ||
| 75 | #endif | ||
| 76 | #endif | ||
| 77 | ], | ||
| 78 | [am_cv_func_working_getline="guessing yes"], | ||
| 79 | [case "$host_os" in | ||
| 80 | *-musl* | midipix*) am_cv_func_working_getline="guessing yes" ;; | ||
| 81 | *) am_cv_func_working_getline="$gl_cross_guess_normal" ;; | ||
| 82 | esac | ||
| 83 | ]) | ||
| 84 | ]) | 91 | ]) |
| 92 | rm -f conftest.data conftest.empty | ||
| 85 | ]) | 93 | ]) |
| 86 | else | 94 | else |
| 87 | am_cv_func_working_getline=no | 95 | am_cv_func_working_getline=no |
