From: Bruno Haible Date: Mon, 13 Oct 2025 10:41:39 +0000 (+0200) Subject: getline: Fix compilation error in C++ mode (regression 2025-10-10). X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b028dcc83f4a3781ebc6217979fffb1f6cd6d3cb;p=thirdparty%2Fgnulib.git 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. --- diff --git a/ChangeLog b/ChangeLog index 932e94c630..0e01db0789 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +2025-10-13 Bruno Haible + + 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 stdcountof-h tests: Fix link error on MSVC 14 (regression 2025-06-07). diff --git a/lib/getdelim.c b/lib/getdelim.c index 2576d376f0..4cd5eca189 100644 --- a/lib/getdelim.c +++ b/lib/getdelim.c @@ -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; diff --git a/lib/stdio.in.h b/lib/stdio.in.h index f3ab7969d1..2c70bc049f 100644 --- a/lib/stdio.in.h +++ b/lib/stdio.in.h @@ -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 + 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 + or . */ +# 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));