summaryrefslogtreecommitdiff
path: root/n/avr/modules
diff options
context:
space:
mode:
authorschodet2005-10-09 15:50:44 +0000
committerschodet2005-10-09 15:50:44 +0000
commit1a751216e7c2f6ecb1d9c2a1f78ab1ff52a6674a (patch)
treefff991f26c145cad47378b5493172fecdb04606a /n/avr/modules
parenta1582933ef0b267ef71cd870d4b4e3c4688de7a7 (diff)
Quand on utilise stdio : toujour buffer ligne par ligne et exit si EOF.
Diffstat (limited to 'n/avr/modules')
-rw-r--r--n/avr/modules/uart/uart.host.c13
1 files changed, 10 insertions, 3 deletions
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 <unistd.h>
#include <pty.h>
#include <fcntl.h>
+#include <stdio.h>
/* 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;
}