Newlib stdout buffering

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
justin
Member
Member
Posts: 43
Joined: Sun Jan 11, 2009 2:09 pm

Newlib stdout buffering

Post by justin »

I am using newlib 1.20.0 and it isn't flushing stdout whenever scanf() is called. In particular,

Code: Select all

#include <stdio.h>
int main()
{
	int a;
	printf("Hello!");
	scanf("%d",&a);
	return 0;
}
This writes "Hello!" to the screen and then waits for my input on Linux. On my OS, it writes nothing and then waits for input. The buffer only gets flushed when I print a newline character. Is there something I have to do on my end to make this happen?

Thank you.
gerryg400
Member
Member
Posts: 1801
Joined: Thu Mar 25, 2010 11:26 pm
Location: Melbourne, Australia

Re: Newlib stdout buffering

Post by gerryg400 »

Before reading from a line buffered or unbuffered file newlib will flush all line buffered output files. So, if your stdout is line-buffered and your stdin is NOT fully buffered it will flush automatically.

Can you check the buffer flags of stdin and stdout ?

[edit] my guess is that your isatty() is not implemented. It is used internally by newlib to decide which type of buffering to use.
If a trainstation is where trains stop, what is a workstation ?
justin
Member
Member
Posts: 43
Joined: Sun Jan 11, 2009 2:09 pm

Re: Newlib stdout buffering

Post by justin »

Thanks. It turns out that isatty isn't getting called but fstat is. I guess it is using fstat to make that determination. I haven't implemented fstat yet.
Post Reply