summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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;
}