Open ycsin opened 6 months ago
This API call is deprecated / unsafe.
The man pages say never use it and to use fgets instead.
https://man7.org/linux/man-pages/man3/gets.3.html
It might be worth making a note that this call is simply not supported in the documentation.
Likely picolibc / newlib has it though... 🤔
Wouldn't mind a second opinion from @keith-packard or @stephanosio
glibc follows c11/c17 standards and doesn't even define gets
unless you build with an older C standard (gcc -std=c99 provides gets). Even in that case, the API is marked as deprecated and you get a warning at compile time. And another warning at link time. Even building with _POSIX_C_SOURCE=200809L
leaves gets undefined without also using the older ISO C standard.
This seems like a reasonable plan to me. Applications that want gets
newline semantics (which differ from fgets
, of course), should use the new ISO C gets_s
API instead.
Picolibc and newlib don't provide gets_s
, which should probably get fixed.
This was originally added as a ticket under POSIX, but
gets()
is not a POSIX function. It is from C89.https://en.cppreference.com/w/c/io/gets
The expectation from the POSIX API is that this function is implemented as part of whatever C library is in use.