summaryrefslogtreecommitdiff
path: root/common/uart_printf.c
diff options
context:
space:
mode:
Diffstat (limited to 'common/uart_printf.c')
-rw-r--r--common/uart_printf.c29
1 files changed, 12 insertions, 17 deletions
diff --git a/common/uart_printf.c b/common/uart_printf.c
index 55b8a40cde..6f8ebb5cbc 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,10 +31,9 @@ int uart_putc(int c)
int uart_puts(const char *outstr)
{
/* Put all characters in the output buffer */
- for (; *outstr != '\0'; ++outstr) {
- if (__tx_char(NULL, *outstr) != 0) {
+ while (*outstr) {
+ if (__tx_char(NULL, *outstr++) != 0)
break;
- }
}
uart_tx_start();
@@ -45,34 +44,30 @@ int uart_puts(const char *outstr)
int uart_put(const char *out, int len)
{
- int written;
-
/* Put all characters in the output buffer */
- for (written = 0; written < len; written++) {
- if (__tx_char(NULL, *out++) != 0) {
+ while (len--) {
+ if (__tx_char(NULL, *out++) != 0)
break;
- }
}
uart_tx_start();
- return written;
+ /* Successful if we consumed all output */
+ return len ? EC_ERROR_OVERFLOW : EC_SUCCESS;
}
int uart_put_raw(const char *out, int len)
{
- int written;
-
/* Put all characters in the output buffer */
- for (written = 0; written < len; written++) {
- if (uart_tx_char_raw(NULL, *out++) != 0) {
+ while (len--) {
+ if (uart_tx_char_raw(NULL, *out++) != 0)
break;
- }
}
uart_tx_start();
- return written;
+ /* Successful if we consumed all output */
+ return len ? EC_ERROR_OVERFLOW : EC_SUCCESS;
}
int uart_vprintf(const char *format, va_list args)