This is an automated email from the ASF dual-hosted git repository. xiaoxiang pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/nuttx.git
The following commit(s) were added to refs/heads/master by this push: new b8e622ea5d libc/stream: unify stream behavior b8e622ea5d is described below commit b8e622ea5dcadd2c3f10007c69b4980c2ee7e157 Author: yinshengkai <yinsheng...@xiaomi.com> AuthorDate: Fri Mar 3 12:33:16 2023 +0800 libc/stream: unify stream behavior Return the error code when all gets occur when an error is wrong and return immediately when obtaining any valid data Signed-off-by: yinshengkai <yinsheng...@xiaomi.com> --- libs/libc/stream/lib_rawoutstream.c | 28 ++++++++++++++-------------- libs/libc/stream/lib_rawsostream.c | 5 ++--- libs/libc/stream/lib_stdsistream.c | 4 ++++ 3 files changed, 20 insertions(+), 17 deletions(-) diff --git a/libs/libc/stream/lib_rawoutstream.c b/libs/libc/stream/lib_rawoutstream.c index e895067743..34d383f18d 100644 --- a/libs/libc/stream/lib_rawoutstream.c +++ b/libs/libc/stream/lib_rawoutstream.c @@ -46,27 +46,27 @@ static int rawoutstream_puts(FAR struct lib_outstream_s *this, FAR struct lib_rawoutstream_s *rthis = (FAR struct lib_rawoutstream_s *)this; int nwritten = 0; - int ret = 0; - while (nwritten != len) + do { - ret = _NX_WRITE(rthis->fd, (FAR const char *)buf + nwritten, - len - nwritten); - if (ret <= 0) + nwritten = _NX_WRITE(rthis->fd, buf, len); + if (nwritten >= 0) { - if (_NX_GETERRNO(ret) == EINTR) - { - continue; - } - - break; + this->nput += nwritten; + return nwritten; } - this->nput += ret; - nwritten += ret; + /* The only expected error is EINTR, meaning that the write operation + * was awakened by a signal. Zero would not be a valid return value + * from _NX_WRITE(). + */ + + nwritten = _NX_GETERRVAL(nwritten); + DEBUGASSERT(nwritten < 0); } + while (nwritten == -EINTR); - return nwritten > 0 ? nwritten : ret; + return nwritten; } /**************************************************************************** diff --git a/libs/libc/stream/lib_rawsostream.c b/libs/libc/stream/lib_rawsostream.c index 2f286c386d..61a5d93d9a 100644 --- a/libs/libc/stream/lib_rawsostream.c +++ b/libs/libc/stream/lib_rawsostream.c @@ -45,7 +45,6 @@ static void rawsostream_putc(FAR struct lib_sostream_s *this, int ch) FAR struct lib_rawsostream_s *rthis = (FAR struct lib_rawsostream_s *)this; char buffer = ch; int nwritten; - int errcode; DEBUGASSERT(this && rthis->fd >= 0); @@ -67,10 +66,10 @@ static void rawsostream_putc(FAR struct lib_sostream_s *this, int ch) * from _NX_WRITE(). */ - errcode = _NX_GETERRNO(nwritten); + nwritten = _NX_GETERRVAL(nwritten); DEBUGASSERT(nwritten < 0); } - while (errcode == EINTR); + while (nwritten == -EINTR); } /**************************************************************************** diff --git a/libs/libc/stream/lib_stdsistream.c b/libs/libc/stream/lib_stdsistream.c index 9feb39ab8c..9732492539 100644 --- a/libs/libc/stream/lib_stdsistream.c +++ b/libs/libc/stream/lib_stdsistream.c @@ -71,6 +71,10 @@ static int stdsistream_gets(FAR struct lib_instream_s *this, { this->nget += nread; } + else + { + nread = _NX_GETERRVAL(nread); + } return nread; }