diff options
Diffstat (limited to 'nuttx/lib/stdio/lib_rawoutstream.c')
-rw-r--r-- | nuttx/lib/stdio/lib_rawoutstream.c | 29 |
1 files changed, 20 insertions, 9 deletions
diff --git a/nuttx/lib/stdio/lib_rawoutstream.c b/nuttx/lib/stdio/lib_rawoutstream.c index ce9d33280..b4a20958b 100644 --- a/nuttx/lib/stdio/lib_rawoutstream.c +++ b/nuttx/lib/stdio/lib_rawoutstream.c @@ -38,7 +38,9 @@ ****************************************************************************/ #include <unistd.h> +#include <assert.h> #include <errno.h> + #include "lib_internal.h" /**************************************************************************** @@ -52,19 +54,28 @@ static void rawoutstream_putc(FAR struct lib_outstream_s *this, int ch) { FAR struct lib_rawoutstream_s *rthis = (FAR struct lib_rawoutstream_s *)this; + int nwritten; char buffer = ch; - if (this && rthis->fd >= 0) + + DEBUGASSERT(this && rthis->fd >= 0); + + /* Loop until the character is successfully transferred */ + + for (;;) { - int nwritten; - do + nwritten = write(rthis->fd, &buffer, 1); + if (nwritten == 1) { - nwritten = write(rthis->fd, &buffer, 1); - if (nwritten == 1) - { - this->nput++; - } + this->nput++; + return; } - while (nwritten < 0 && get_errno() == EINTR); + + /* The only expected error is EINTR, meaning that the write operation + * was awakened by a signal. Zero would not be a valid return value + * either. + */ + + DEBUGASSERT(nwritten < 0 && get_errno() == EINTR); } } |