Page 1 of 1

Newlib stdout buffering

Posted: Mon Jan 07, 2013 7:45 pm
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.

Re: Newlib stdout buffering

Posted: Mon Jan 07, 2013 9:53 pm
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.

Re: Newlib stdout buffering

Posted: Tue Jan 08, 2013 12:17 pm
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.