From 1a751216e7c2f6ecb1d9c2a1f78ab1ff52a6674a Mon Sep 17 00:00:00 2001 From: schodet Date: Sun, 9 Oct 2005 15:50:44 +0000 Subject: Quand on utilise stdio : toujour buffer ligne par ligne et exit si EOF. --- n/avr/modules/uart/uart.host.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) (limited to 'n') diff --git a/n/avr/modules/uart/uart.host.c b/n/avr/modules/uart/uart.host.c index e39b15a..d6aa848 100644 --- a/n/avr/modules/uart/uart.host.c +++ b/n/avr/modules/uart/uart.host.c @@ -38,6 +38,7 @@ #include #include #include +#include /* Check uart driver. */ #if UART_N == 0 @@ -84,6 +85,8 @@ uart_init (void) #ifdef DRIVER_STDIO # define uart_pt_fd_in 0 # define uart_pt_fd_out 1 + /* Always use line buffering. */ + assert (setvbuf (stdout, 0, _IOLBF, BUFSIZ) == 0); #else # define uart_pt_fd_in uart_pt_fd # define uart_pt_fd_out uart_pt_fd @@ -124,12 +127,16 @@ uart_getc (void) n = read (uart_pt_fd_in, &c, 1); if (n == -1) assert_perror (errno); - /* This is a quite unusual behavior... */ - if (n == 0) - return 0xff; #ifdef DRIVER_STDIO + /* Quit if EOF from stdin. */ + if (n == 0) + exit (0); if (c == '\n') c = '\r'; +#else + /* This is a quite unusual and dangerous behavior... */ + if (n == 0) + return 0xff; #endif return c; } -- cgit v1.2.3