-
Notifications
You must be signed in to change notification settings - Fork 2.1k
native/stdio: Explicitly provide getchar #19330
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
Conversation
This ensures that even when libc does not implement getchar through getc, any custom stdio is still in the loop when getchar is used.
@@ -308,6 +308,10 @@ int fgetc(FILE *fp) | |||
return getc(fp); | |||
} | |||
|
|||
int getchar(void) { | |||
return getc(stdin); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this Linux stdin
or RIOT stdin
(which might be through a different stdio implementation)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure, but either way, through getc
this gets forwarded to _native_read
, which runs if (fd == STDIN_FILENO) return stdio_read(buf, count);
.
So as long as its fileno() is STDIN_FILENO, it's fine.
[edit: does RIOT even have a dedicated FILE *
for stdin?]
Thanks bors merge |
🕐 Waiting for PR status (GitHub check) to be set, probably by CI. Bors will automatically try to run when all required PR statuses are set. |
bors merge |
Stopped waiting for PR status (GitHub check) without running due to duplicate requests to run. You may check Bors to see that this PR is included in a batch by one of the other requests. |
Build succeeded: |
Contribution description
This ensures that even when libc does not implement getchar through getc, any custom stdio is still in the loop when getchar is used.
Frankly, I don't know when this broke -- I'm pretty sure custom stdio worked just a few days ago -- but either way, without this patch RIOT on native currently bypasses a configured stdio for me.
Testing procedure
make -C examples/saul all debug
break stdio_read
run
Without this patch, observe how the shell runs w/o ever breaking. After, lots of breakpoint hits.
This is the way it behaves for me (Debian sid, libc6:i386 2.36-8). If it works for you before this patch, we might start bisecting the differences between the systems, but we may also accept that libcs may imlpement getchar in different ways, and not all of them pass by the getc which we're patching.
Issues/PRs references
This is needed for testing #19289.
The implementation stems from the
fgetc(3)
man page, which states that "getchar() is equivalent to getc(stdin)".