printf not working, if buffering disabled

Marc Donner marc.donner@mdet.de
Mon Sep 19 15:18:00 GMT 2011


Hi,

i've wrote a small program using newlib's printf funktion. All works
well as long as buffering is enabled. If I disable buffering using the
following code

setvbuf(stdout, NULL, _IONBF, 0);

the printf functions are not working anymore, while a call to putchar
produces the expected result.

The code looks like this

#include <stdio.h>

void
main (void) {
	/* init USB CDC device */
	usbcdc_init();

	//setvbuf(stdout, NULL, _IONBF, 0);
	putchar('y');
	putchar('\n');
	iprintf("test\n"); /* <- not working if buffering disabled */

	while (1);
}

The _write syscall is implemented as

int _write(int file, char *ptr, int len) {
	while (len--) {
		if (*ptr == '\n') {
			usbcdc_putch('\r');
		}
	}
	return len;
}

Anybody an idea?

Regards,

Marc



More information about the Newlib mailing list