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 <yinshengkai@xiaomi.com>
This commit is contained in:
parent
9f44391828
commit
b8e622ea5d
@ -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().
|
||||
*/
|
||||
|
||||
return nwritten > 0 ? nwritten : ret;
|
||||
nwritten = _NX_GETERRVAL(nwritten);
|
||||
DEBUGASSERT(nwritten < 0);
|
||||
}
|
||||
while (nwritten == -EINTR);
|
||||
|
||||
return nwritten;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
|
@ -71,6 +71,10 @@ static int stdsistream_gets(FAR struct lib_instream_s *this,
|
||||
{
|
||||
this->nget += nread;
|
||||
}
|
||||
else
|
||||
{
|
||||
nread = _NX_GETERRVAL(nread);
|
||||
}
|
||||
|
||||
return nread;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user