Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

libc: implement gets() #66945

Open
ycsin opened this issue Dec 24, 2023 · 2 comments
Open

libc: implement gets() #66945

ycsin opened this issue Dec 24, 2023 · 2 comments
Assignees
Labels
area: C Library C Standard Library Enhancement Changes/Updates/Additions to existing features Good first issue Good for a first time contributor to take

Comments

@ycsin
Copy link
Member

ycsin commented Dec 24, 2023

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.

@ycsin ycsin added Feature Request A request for a new feature Good first issue Good for a first time contributor to take area: POSIX POSIX API Library labels Dec 24, 2023
@cfriedt
Copy link
Member

cfriedt commented Jan 4, 2024

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

@keith-packard
Copy link
Collaborator

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.

@nashif nashif added Enhancement Changes/Updates/Additions to existing features and removed Feature Request A request for a new feature labels Jan 19, 2024
@cfriedt cfriedt added area: C Library C Standard Library and removed area: POSIX POSIX API Library labels Jun 11, 2024
@cfriedt cfriedt removed their assignment Jun 11, 2024
@cfriedt cfriedt changed the title posix: implement gets() libc: implement gets() Jun 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: C Library C Standard Library Enhancement Changes/Updates/Additions to existing features Good first issue Good for a first time contributor to take
Projects
None yet
Development

No branches or pull requests

5 participants