From 141bec642703d3f1f1d842398ee25ffe91f8b6e5 Mon Sep 17 00:00:00 2001 From: Ludwig Ortmann Date: Sun, 18 Aug 2013 11:21:38 +0200 Subject: [PATCH] improve uart0_puts --- native/drivers/native-uart0.c | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/native/drivers/native-uart0.c b/native/drivers/native-uart0.c index 419b043cc5..9f77a72d0c 100644 --- a/native/drivers/native-uart0.c +++ b/native/drivers/native-uart0.c @@ -20,13 +20,26 @@ fd_set _native_uart_rfds; inline int uart0_puts(char *astring, int length) { + int nwritten, offset; + + nwritten = 0; + offset = 0; + _native_in_syscall = 1; - /* XXX: handle short writes: */ - if (write(_native_uart_out, astring, length) == -1) { - err(EXIT_FAILURE, "uart0_puts: write"); - return -1; + + while ((length > 0) &&(nwritten = write(_native_uart_out, astring+offset, length-offset)) > 0) { + offset += nwritten; } + if (nwritten == -1) { + err(EXIT_FAILURE, "uart0_puts: write"); + } + else if ((length > 0) && (nwritten == 0)) { + /* XXX: handle properly */ + errx(EXIT_FAILURE, "uart0_puts: Could not write to stdout. I don't know what to do now."); + } + _native_in_syscall = 0; + return length; }