This is the mail archive of the
newlib@sourceware.org
mailing list for the newlib project.
Re: Buffered I/O issues (stdout, stdin)
- From: Xavier Guérin <xavier dot guerin at imag dot fr>
- To: Matthew Iselin <matthew at theiselins dot net>
- Cc: newlib at sources dot redhat dot com
- Date: Tue, 26 Feb 2008 11:36:01 +0100
- Subject: Re: Buffered I/O issues (stdout, stdin)
- References: <f88ae150802260219m3065e2eeic7c5776e381036b4@mail.gmail.com>
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.
Regards,
Xavier
--
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