]> git.ipfire.org Git - thirdparty/gnulib.git/commitdiff
getline: Fix compilation error in C++ mode (regression 2025-10-10).
authorBruno Haible <bruno@clisp.org>
Mon, 13 Oct 2025 10:41:39 +0000 (12:41 +0200)
committerBruno Haible <bruno@clisp.org>
Mon, 13 Oct 2025 10:41:39 +0000 (12:41 +0200)
* lib/stdio.in.h (getdelim): On glibc, define __getdelim instead of
rpl_getdelim.
(getline): In C++ mode, define getline as an inline function instead of
as a macro.
* lib/getdelim.c (getdelim): On glibc, don't test whether fp is NULL.

ChangeLog
lib/getdelim.c
lib/stdio.in.h

index 932e94c63067a22abd5b0bdc012dc871a991dadd..0e01db0789deea6ea04e523b506b819185955da1 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2025-10-13  Bruno Haible  <bruno@clisp.org>
+
+       getline: Fix compilation error in C++ mode (regression 2025-10-10).
+       * lib/stdio.in.h (getdelim): On glibc, define __getdelim instead of
+       rpl_getdelim.
+       (getline): In C++ mode, define getline as an inline function instead of
+       as a macro.
+       * lib/getdelim.c (getdelim): On glibc, don't test whether fp is NULL.
+
 2025-10-12  Bruno Haible  <bruno@clisp.org>
 
        stdcountof-h tests: Fix link error on MSVC 14 (regression 2025-06-07).
index 2576d376f06ed67d59ce0c3ff61a38eb30633fa1..4cd5eca1895950ce70531cc5eb1d94c4ed45b33e 100644 (file)
@@ -65,7 +65,13 @@ getdelim (char **lineptr, size_t *n, int delimiter, FILE *fp)
   ssize_t result;
   size_t cur_len = 0;
 
-  if (lineptr == NULL || n == NULL || fp == NULL)
+  if (lineptr == NULL || n == NULL
+      /* glibc already declares this function as __nonnull ((4)).
+         Avoid a gcc warning "‘nonnull’ argument ‘fp’ compared to NULL".  */
+#if !(__GLIBC__ >= 2)
+      || fp == NULL
+#endif
+     )
     {
       errno = EINVAL;
       return -1;
index f3ab7969d198006d2bd9da52dc7d437c5ae26370..2c70bc049fccc5ab17a2647665d50de7b618698d 100644 (file)
@@ -1044,6 +1044,11 @@ _GL_CXXALIASWARN (getchar);
 #   undef getdelim
 #   define getdelim rpl_getdelim
 #  endif
+#  if __GLIBC__ >= 2
+/* Arrange for the inline definition of getline() in <bits/stdio.h>
+   to call our getdelim() override.  */
+#   define rpl_getdelim __getdelim
+#  endif
 _GL_FUNCDECL_RPL (getdelim, ssize_t,
                   (char **restrict lineptr, size_t *restrict linesize,
                    int delimiter,
@@ -1085,14 +1090,27 @@ _GL_WARN_ON_USE (getdelim, "getdelim is unportable - "
    Return the number of bytes read and stored at *LINEPTR (not including the
    NUL terminator), or -1 on error or EOF.  */
 # if @REPLACE_GETLINE@
-#  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
-#   undef getline
-#   define getline rpl_getline
-#  endif
 _GL_FUNCDECL_RPL (getline, ssize_t,
                   (char **restrict lineptr, size_t *restrict linesize,
                    FILE *restrict stream),
                   _GL_ARG_NONNULL ((1, 2, 3)) _GL_ATTRIBUTE_NODISCARD);
+#  if defined __cplusplus
+/* The C++ standard library defines std::basic_istream::getline in <istream>
+   or <string>.  */
+#   if !(__GLIBC__ >= 2)
+extern "C" {
+inline ssize_t
+getline (char **restrict lineptr, size_t *restrict linesize,
+         FILE *restrict stream)
+{
+  return rpl_getline (lineptr, linesize, stream);
+}
+}
+#   endif
+#  else
+#   undef getline
+#   define getline rpl_getline
+#  endif
 _GL_CXXALIAS_RPL (getline, ssize_t,
                   (char **restrict lineptr, size_t *restrict linesize,
                    FILE *restrict stream));