This is the mail archive of the newlib@sourceware.org mailing list for the newlib project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: printf and line buffering


Andrew Pamment wrote:
Hi there,

I have been porting newlib to run on my OS, it runs really well, but I am having a problem and can't work out what I am doing wrong.

Trying to write a shell, I want to print "Mort$ " without a line break, but printf won't do this. I have been going through the newlib source and found some comments, the first was about defaulting to line buffered if I don't supply an fcntl system call, so I implemented one, the second was that as per ANSI standard ttys are by default line buffered.

I can't work out how to switch line buffering off. I have been tracing the system calls to my OS, I have isatty being called (to which my OS responds 1 (yes)) but no fcntl - so i guess I am not setting flags incorrectly. Also, putchar works fine, it puts a char immediatly.

I have tried "setvbuf(stdout, NULL, _IONBF, 0);" but that didn't work,

You have to issue the setvbuf before any operations to stdout. What return code do you get back from setvbuf()? Have you verified via debugging that your write syscall is not being called appropriately under the covers?


The following simple test case debugged under both x86-linux and mn10300 newlib has already issued the line "some line" by the time we get to line 7: return 0. What happens on your system?

#include <stdio.h>

int main()
{
   setvbuf(stdout, NULL, _IONBF, 0);
   printf ("some line");
   return 0;
}

-- Jeff J.





Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]