The "getline" function is specified by POSIX to be declared
in <stdio.h>.  It is not specified by the ISO C standard, so the
identifier should be available for use in strictly conforming
programs.

$ cat getline_bug.c
#include <stdio.h>
int getline = 0;
int main(void) {
    return getline;
}
$ gcc --version
gcc (GCC) 16.0.0 20250907 (experimental)
Copyright (C) 2025 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

$ gcc getline_bug.c -o getline_bug
getline_bug.c:2:5: error: ‘getline’ redeclared as different kind of symbol
    2 | int getline = 0;
      |     ^~~~~~~
In file included from /usr/include/stdio.h:85,
                 from getline_bug.c:1:
/usr/include/sys/stdio.h:35:9: note: previous declaration of ‘getline’ with
type ‘ssize_t(char **, size_t *, FILE *)’ {aka ‘long int(char **, long
unsigned int *, FILE *)’}
   35 | ssize_t getline (char **, size_t *, FILE *);
      |         ^~~~~~~

$

Stack Overflow user "pmor" reports the same problem with gcc 12.4.0.

The problem is in newlib, winsup/cygwin/include/sys/stdio.h, line 35.
I expect getdelim() to exhibit the same problem, but I haven't checked that.

GNU libc's <stdio.h> avoids this problem by surrounding the
declarations of getline() and getdelim() by an appropriate #ifdef.

-- 
Problem reports:      https://cygwin.com/problems.html
FAQ:                  https://cygwin.com/faq/
Documentation:        https://cygwin.com/docs.html
Unsubscribe info:     https://cygwin.com/ml/#unsubscribe-simple

Reply via email to