diff options
Diffstat (limited to 'common/uart_printf.c')
-rw-r--r-- | common/uart_printf.c | 29 |
1 files changed, 17 insertions, 12 deletions
diff --git a/common/uart_printf.c b/common/uart_printf.c index 6f8ebb5cbc..55b8a40cde 100644 --- a/common/uart_printf.c +++ b/common/uart_printf.c @@ -3,12 +3,12 @@ * found in the LICENSE file. */ -#include <stddef.h> - #include "common.h" #include "printf.h" #include "uart.h" +#include <stddef.h> + static int __tx_char(void *context, int c) { /* @@ -31,9 +31,10 @@ int uart_putc(int c) int uart_puts(const char *outstr) { /* Put all characters in the output buffer */ - while (*outstr) { - if (__tx_char(NULL, *outstr++) != 0) + for (; *outstr != '\0'; ++outstr) { + if (__tx_char(NULL, *outstr) != 0) { break; + } } uart_tx_start(); @@ -44,30 +45,34 @@ int uart_puts(const char *outstr) int uart_put(const char *out, int len) { + int written; + /* Put all characters in the output buffer */ - while (len--) { - if (__tx_char(NULL, *out++) != 0) + for (written = 0; written < len; written++) { + if (__tx_char(NULL, *out++) != 0) { break; + } } uart_tx_start(); - /* Successful if we consumed all output */ - return len ? EC_ERROR_OVERFLOW : EC_SUCCESS; + return written; } int uart_put_raw(const char *out, int len) { + int written; + /* Put all characters in the output buffer */ - while (len--) { - if (uart_tx_char_raw(NULL, *out++) != 0) + for (written = 0; written < len; written++) { + if (uart_tx_char_raw(NULL, *out++) != 0) { break; + } } uart_tx_start(); - /* Successful if we consumed all output */ - return len ? EC_ERROR_OVERFLOW : EC_SUCCESS; + return written; } int uart_vprintf(const char *format, va_list args) |