diff options
Diffstat (limited to 'gl/m4/getline.m4')
| -rw-r--r-- | gl/m4/getline.m4 | 51 |
1 files changed, 29 insertions, 22 deletions
diff --git a/gl/m4/getline.m4 b/gl/m4/getline.m4 index b97b8011..ed32fa10 100644 --- a/gl/m4/getline.m4 +++ b/gl/m4/getline.m4 | |||
| @@ -1,7 +1,7 @@ | |||
| 1 | # getline.m4 | 1 | # getline.m4 |
| 2 | # serial 33 | 2 | # serial 35 |
| 3 | 3 | ||
| 4 | dnl Copyright (C) 1998-2003, 2005-2007, 2009-2025 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 |
| @@ -31,6 +31,7 @@ AC_DEFUN([gl_FUNC_GETLINE], | |||
| 31 | AC_CACHE_CHECK([for working getline function], | 31 | AC_CACHE_CHECK([for working getline function], |
| 32 | [am_cv_func_working_getline], | 32 | [am_cv_func_working_getline], |
| 33 | [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 | ||
| 34 | AC_RUN_IFELSE([AC_LANG_SOURCE([[ | 35 | AC_RUN_IFELSE([AC_LANG_SOURCE([[ |
| 35 | # include <stdio.h> | 36 | # include <stdio.h> |
| 36 | # include <stdlib.h> | 37 | # include <stdlib.h> |
| @@ -38,6 +39,7 @@ AC_DEFUN([gl_FUNC_GETLINE], | |||
| 38 | int main () | 39 | int main () |
| 39 | { | 40 | { |
| 40 | FILE *in = fopen ("./conftest.data", "r"); | 41 | FILE *in = fopen ("./conftest.data", "r"); |
| 42 | int result = 0; | ||
| 41 | if (!in) | 43 | if (!in) |
| 42 | return 1; | 44 | return 1; |
| 43 | { | 45 | { |
| @@ -47,7 +49,7 @@ AC_DEFUN([gl_FUNC_GETLINE], | |||
| 47 | size_t siz = 0; | 49 | size_t siz = 0; |
| 48 | int len = getline (&line, &siz, in); | 50 | int len = getline (&line, &siz, in); |
| 49 | if (!(len == 4 && line && strcmp (line, "foo\n") == 0)) | 51 | if (!(len == 4 && line && strcmp (line, "foo\n") == 0)) |
| 50 | { free (line); fclose (in); return 2; } | 52 | result |= 2; |
| 51 | free (line); | 53 | free (line); |
| 52 | } | 54 | } |
| 53 | { | 55 | { |
| @@ -56,33 +58,38 @@ AC_DEFUN([gl_FUNC_GETLINE], | |||
| 56 | char *line = NULL; | 58 | char *line = NULL; |
| 57 | size_t siz = (size_t)(~0) / 4; | 59 | size_t siz = (size_t)(~0) / 4; |
| 58 | if (getline (&line, &siz, in) == -1) | 60 | if (getline (&line, &siz, in) == -1) |
| 59 | { fclose (in); return 3; } | 61 | result |= 4; |
| 60 | free (line); | 62 | free (line); |
| 61 | } | 63 | } |
| 62 | fclose (in); | 64 | fclose (in); |
| 63 | 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; | ||
| 64 | } | 80 | } |
| 65 | ]])], | 81 | ]])], |
| 66 | [am_cv_func_working_getline=yes], | 82 | [am_cv_func_working_getline=yes], |
| 67 | [am_cv_func_working_getline=no], | 83 | [am_cv_func_working_getline=no], |
| 68 | [dnl We're cross compiling. | 84 | [case "$host_os" in |
| 69 | dnl Guess it works on glibc2 systems and musl systems. | 85 | # Guess yes on musl. |
| 70 | AC_EGREP_CPP([Lucky GNU user], | 86 | *-musl* | midipix*) am_cv_func_working_getline="guessing yes" ;; |
| 71 | [ | 87 | # Guess no on glibc. |
| 72 | #include <features.h> | 88 | *-gnu* | gnu*) am_cv_func_working_getline="guessing no" ;; |
| 73 | #ifdef __GNU_LIBRARY__ | 89 | *) am_cv_func_working_getline="$gl_cross_guess_normal" ;; |
| 74 | #if (__GLIBC__ >= 2) && !defined __UCLIBC__ | 90 | esac |
| 75 | Lucky GNU user | ||
| 76 | #endif | ||
| 77 | #endif | ||
| 78 | ], | ||
| 79 | [am_cv_func_working_getline="guessing yes"], | ||
| 80 | [case "$host_os" in | ||
| 81 | *-musl* | midipix*) am_cv_func_working_getline="guessing yes" ;; | ||
| 82 | *) am_cv_func_working_getline="$gl_cross_guess_normal" ;; | ||
| 83 | esac | ||
| 84 | ]) | ||
| 85 | ]) | 91 | ]) |
| 92 | rm -f conftest.data conftest.empty | ||
| 86 | ]) | 93 | ]) |
| 87 | else | 94 | else |
| 88 | am_cv_func_working_getline=no | 95 | am_cv_func_working_getline=no |
