Buffered I/O issues (stdout, stdin)

Xavier Guérin xavier.guerin@imag.fr
Thu Feb 28 21:24:00 GMT 2008

Hi Matthew,
> I'm having some trouble with a port of Newlib 1.15.0 to my operating
> system in the printf function. It seems that the streams are all using
> buffered I/O and if the last string printed does not have a newline it
> simply is not printed at all.
FILEs are by default line buffered, meaning that nothing will be written 
or read until a newline symbol is encountered.
You can modify this behavior by using the setbuf() or setvbuf() methods.
> I also notice strange behavior with this sort of code:
> printf( "testing 123: %s\n", "hello\nworld" );
> The output will be "testing 123: hello\n", which doesn't seem to be
> correct. The write system call is only called for the characters
> actually printed, not for the ones after, and including, the newline
> (ie, "\nworld").
Did you check errno after calling printf ? You will probably get something.
This happens if you don't return the correct numbers of bytes written by 
your stdout driver.


Xavier Guérin - Doctoral student
TIMA Laboratory, SLS Group
46, av. Félix Viallet, 38000 GRENOBLE, FR
Mail : xavier.guerin@imag.fr
Phone : +33(0)4 76 57 47 59
Ad Astra Per Aspera

More information about the Newlib mailing list