]> git.ipfire.org Git - thirdparty/gnulib.git/commitdiff
getdelim, getline: Don't replace these functions on glibc.
authorCollin Funk <collin.funk1@gmail.com>
Fri, 23 Jan 2026 05:15:29 +0000 (21:15 -0800)
committerCollin Funk <collin.funk1@gmail.com>
Fri, 23 Jan 2026 05:16:45 +0000 (21:16 -0800)
This largely reverts my 2025-10-10 commits since POSIX has relaxed the
requirements to make glibc's behavior compliant. See:
<https://www.austingroupbugs.net/bug_view_page.php?bug_id=1953>.

* doc/posix-functions/getdelim.texi: Move the text about glibc 2.42
to under "Portability problems not fixed by Gnulib".
* doc/posix-functions/getline.texi: Likewise.
* m4/getdelim.m4 (gl_FUNC_GETDELIM): Remove the test on an empty file.
* m4/getline.m4 (gl_FUNC_GETLINE): Likewise.
* tests/test-getdelim.c (main): Remove the test case.
* tests/test-getline.c (main): Likewise.

ChangeLog
doc/posix-functions/getdelim.texi
doc/posix-functions/getline.texi
m4/getdelim.m4
m4/getline.m4
tests/test-getdelim.c
tests/test-getline.c

index 2444097d60ff43c88916bc783a714b7a4a8d9052..29bd6c6200912e3a77b795610061086ad2bfe08f 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,17 @@
 2026-01-22  Collin Funk  <collin.funk1@gmail.com>
 
+       getdelim, getline: Don't replace these functions on glibc.
+       This largely reverts my 2025-10-10 commits since POSIX has relaxed the
+       requirements to make glibc's behavior compliant. See:
+       <https://www.austingroupbugs.net/bug_view_page.php?bug_id=1953>.
+       * doc/posix-functions/getdelim.texi: Move the text about glibc 2.42
+       to under "Portability problems not fixed by Gnulib".
+       * doc/posix-functions/getline.texi: Likewise.
+       * m4/getdelim.m4 (gl_FUNC_GETDELIM): Remove the test on an empty file.
+       * m4/getline.m4 (gl_FUNC_GETLINE): Likewise.
+       * tests/test-getdelim.c (main): Remove the test case.
+       * tests/test-getline.c (main): Likewise.
+
        doc: document a portability issue with macOS getrusage.
        * doc/posix-functions/getrusage.texi: Document that the 'ru_maxrss'
        field of 'struct rusage' is measured in bytes on macOS.
index 5801452212356fcb9c247250e90ebed8630aaca0..abccdd0496f48dccd88c6afce0d824d533a9ff14 100644 (file)
@@ -19,11 +19,6 @@ macOS 10.13.
 This function crashes when passed a pointer to a NULL buffer together with a
 pointer to a non-zero buffer size on some platforms:
 FreeBSD 8.0.
-@item
-This function does not NUL terminate the buffer when the first
-character read is EOF on some platforms:
-@c https://sourceware.org/PR28038
-glibc 2.42.
 @end itemize
 
 Portability problems not fixed by Gnulib:
@@ -31,4 +26,9 @@ Portability problems not fixed by Gnulib:
 @item
 This function has quadratic running time for long lines on some platforms:
 uClibc 0.9.31.
+@item
+This function does not NUL terminate the buffer when the first
+character read is EOF on some platforms:
+@c https://sourceware.org/PR28038
+glibc 2.42.
 @end itemize
index cfef3c88674dfa903e0a03528ec44c17d6b992bc..48281a916842916b99077b817780163074133a51 100644 (file)
@@ -22,11 +22,6 @@ signature, for example in -linet.
 This function crashes when passed a pointer to a NULL buffer together with a
 pointer to a non-zero buffer size on some platforms:
 FreeBSD 8.0.
-@item
-This function does not NUL terminate the buffer when the first
-character read is EOF on some platforms:
-@c https://sourceware.org/PR28038
-glibc 2.42.
 @end itemize
 
 Portability problems not fixed by Gnulib:
@@ -34,4 +29,9 @@ Portability problems not fixed by Gnulib:
 @item
 This function has quadratic running time for long lines on some platforms:
 uClibc 0.9.31.
+@item
+This function does not NUL terminate the buffer when the first
+character read is EOF on some platforms:
+@c https://sourceware.org/PR28038
+glibc 2.42.
 @end itemize
index 8b6eff47aa22c1fb2cc23389a4f409416df7f974..736c4e8b2ebab8f68cc3ccaef74a40fe2bf5b600 100644 (file)
@@ -1,5 +1,5 @@
 # getdelim.m4
-# serial 21
+# serial 22
 
 dnl Copyright (C) 2005-2007, 2009-2026 Free Software Foundation, Inc.
 dnl
@@ -37,7 +37,6 @@ AC_DEFUN([gl_FUNC_GETDELIM],
            gl_cv_func_working_getdelim=no ;;
          *)
            echo fooNbarN | tr -d '\012' | tr N '\012' > conftest.data
-           touch conftest.empty
            AC_RUN_IFELSE([AC_LANG_SOURCE([[
 #    include <stdio.h>
 #    include <stdlib.h>
@@ -68,36 +67,32 @@ AC_DEFUN([gl_FUNC_GETDELIM],
         free (line);
       }
       fclose (in);
-      {
-        /* Test that reading EOF as the first character sets the first byte
-           in the buffer to NUL.  This fails on glibc 2.42 and earlier.  */
-        in = fopen ("./conftest.empty", "r");
-        if (!in)
-          return 1;
-        char *line = malloc (1);
-        line[0] = 'A';
-        size_t siz = 1;
-        if (getdelim (&line, &siz, '\n', in) != -1 || line[0] != '\0')
-          result |= 8;
-        free (line);
-      }
-      fclose (in);
       return result;
     }
     ]])],
              [gl_cv_func_working_getdelim=yes],
              [gl_cv_func_working_getdelim=no],
-             [case "$host_os" in
-                                    # Guess yes on musl.
-                *-musl* | midipix*) gl_cv_func_working_getdelim="guessing yes" ;;
-                                    # Guess no on glibc.
-                *-gnu* | gnu*)      gl_cv_func_working_getdelim="guessing no" ;;
-                *)                  gl_cv_func_working_getdelim="$gl_cross_guess_normal" ;;
-              esac
+             [dnl We're cross compiling.
+              dnl Guess it works on glibc2 systems and musl systems.
+              AC_EGREP_CPP([Lucky GNU user],
+                [
+#include <features.h>
+#ifdef __GNU_LIBRARY__
+ #if (__GLIBC__ >= 2) && !defined __UCLIBC__
+  Lucky GNU user
+ #endif
+#endif
+                ],
+                [gl_cv_func_working_getdelim="guessing yes"],
+                [case "$host_os" in
+                   *-musl* | midipix*) gl_cv_func_working_getdelim="guessing yes" ;;
+                   *)                  gl_cv_func_working_getdelim="$gl_cross_guess_normal" ;;
+                 esac
+                ])
              ])
            ;;
        esac
-       rm -f conftest.data conftest.empty
+       rm -f conftest.data
       ])
     case "$gl_cv_func_working_getdelim" in
       *yes) ;;
index ed32fa10bfb9b83bca0a0e23935f7e2636e3e298..25539dc20c3f979337f6b6b9b69ea379824c7328 100644 (file)
@@ -1,5 +1,5 @@
 # getline.m4
-# serial 35
+# serial 36
 
 dnl Copyright (C) 1998-2003, 2005-2007, 2009-2026 Free Software Foundation,
 dnl Inc.
@@ -31,7 +31,6 @@ AC_DEFUN([gl_FUNC_GETLINE],
     AC_CACHE_CHECK([for working getline function],
       [am_cv_func_working_getline],
       [echo fooNbarN | tr -d '\012' | tr N '\012' > conftest.data
-       touch conftest.empty
        AC_RUN_IFELSE([AC_LANG_SOURCE([[
 #    include <stdio.h>
 #    include <stdlib.h>
@@ -62,34 +61,30 @@ AC_DEFUN([gl_FUNC_GETLINE],
         free (line);
       }
       fclose (in);
-      {
-        /* Test that reading EOF as the first character sets the first byte
-           in the buffer to NUL.  This fails on glibc 2.42 and earlier.  */
-        in = fopen ("./conftest.empty", "r");
-        if (!in)
-          return 1;
-        char *line = malloc (1);
-        line[0] = 'A';
-        size_t siz = 1;
-        if (getline (&line, &siz, in) != -1 || line[0] != '\0')
-          result |= 8;
-        free (line);
-      }
-      fclose (in);
       return result;
     }
     ]])],
          [am_cv_func_working_getline=yes],
          [am_cv_func_working_getline=no],
-         [case "$host_os" in
-                                # Guess yes on musl.
-            *-musl* | midipix*) am_cv_func_working_getline="guessing yes" ;;
-                                # Guess no on glibc.
-            *-gnu* | gnu*)      am_cv_func_working_getline="guessing no" ;;
-            *)                  am_cv_func_working_getline="$gl_cross_guess_normal" ;;
-          esac
+         [dnl We're cross compiling.
+          dnl Guess it works on glibc2 systems and musl systems.
+          AC_EGREP_CPP([Lucky GNU user],
+            [
+#include <features.h>
+#ifdef __GNU_LIBRARY__
+ #if (__GLIBC__ >= 2) && !defined __UCLIBC__
+  Lucky GNU user
+ #endif
+#endif
+            ],
+            [am_cv_func_working_getline="guessing yes"],
+            [case "$host_os" in
+               *-musl* | midipix*) am_cv_func_working_getline="guessing yes" ;;
+               *)                  am_cv_func_working_getline="$gl_cross_guess_normal" ;;
+             esac
+            ])
          ])
-       rm -f conftest.data conftest.empty
+       rm -f conftest.data
       ])
   else
     am_cv_func_working_getline=no
index d472285c5eeb69ecd8d418335ae8dd5d051febd2..25b53ee1d5fe91ed860e21f24d147e2268db4d6a 100644 (file)
@@ -84,11 +84,7 @@ main (void)
   ASSERT (memcmp (line, "d\0f", 4) == 0);
   ASSERT (3 < len);
 
-  /* Test that reading an EOF will terminate the buffer with a NUL
-     character.  */
   result = getdelim (&line, &len, 'n', f);
-  ASSERT (0 < len);
-  ASSERT (line[0] == '\0');
   ASSERT (result == -1);
 
   free (line);
index 8572611d656646152f17e5e3d143856ac8c602d5..eda571eeed4cf2cf7f2611bfd71c5d846c871f91 100644 (file)
@@ -84,11 +84,7 @@ main (void)
   ASSERT (memcmp (line, "d\0f", 4) == 0);
   ASSERT (3 < len);
 
-  /* Test that reading an EOF will terminate the buffer with a NUL
-     character.  */
   result = getline (&line, &len, f);
-  ASSERT (0 < len);
-  ASSERT (line[0] == '\0');
   ASSERT (result == -1);
 
   free (line);