Hi,
I am having trouble with printf, and I am positive that its not my
terminal's fault or a buffering problem. First I'll explain the
problem, and second why I think it's not my terminal's fault.
The problem is that printf stops calling the write() syscall after
encountering a line feed character ('\n'). Below is some code and
corresponding output to demonstrate.
The code:
printf("line 0\n");
printf("line 1\nline 2\n");
printf("line 3");
printf("\nline 4\n");
printf("line 5\n");
fflush(stdout);
The expected output:
line 0
line 1
line 2
line 3
line 4
line 5
(my broken) Newlib's output:
line 0
line 1 // stops printing line 2 after line feed
line 3 // stops printing line 4 after line feed
line 5
The reason I don't blame my terminal is because if I replace all calls
to printf with calls to write(1, text, textlen), then everything works
as expected with regards to line feeds. Things also work as expected
if I use sprintf() followed by a call to write().