This is the mail archive of the newlib@sources.redhat.com 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: _IONBF drops all newlines


Nick THOMPSON wrote:
Hi all,

newlib-1.12.0, gcc 3.4 for arm-elf, custom OS.

I'm new to newlib and am trying to embed it on an ARM946. I have my code
booting nicely now with stdin/out as default settings (line buffered??).
However, my code is interactive (i.e. command line editing) and I need
stdio to be unbuffered so I can use getchar for real time char input and
putchar/printf output to control a VT100 cursor. So I added...

    setvbuf(stdin, NULL, _IONBF, 0);
    setvbuf(stdout, NULL, _IONBF, 0);

...early in my code (no output so far), but this seem to make puts not
output a \n and printf also seems to ignore any \n in the format string.
putchar('\n') works fine and my serial driver does the conversion to
CR/LR for the terminal.

I don't use crt0 and have a custom boot sequence, that sets .data and
.bss correctly. It doesn't call any kind of newlib init routines, as
there don't seem to be any (stdio initialised on the fly for example).
Have I missed something obvious?

Thanks in advance,
Nick.



Nick,


The puts() should work as follows: first the original string will be written via a _write call, then the "\n" will be written by a _write call. I have included a simple test case which I used to verify on an mn10300 simulator.

Have you replaced the newlib syscalls? Can you confirm with a debugger what happens with the test case?

-- Jeff J.

#include <stdio.h>

int main()
{
  setvbuf (stdout, NULL, _IONBF, 0);

  puts ("abc");
  putchar ('a');

  exit(0);
}

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