mirror of
https://github.com/apache/nuttx.git
synced 2026-06-02 01:21:26 +08:00
libc/stdoutstream: restore the output method to fputc()
keep the default behavior for stdoutstream since the character needs to flush every output Signed-off-by: chao.an <anchao@xiaomi.com>
This commit is contained in:
committed by
Masayuki Ishikawa
parent
e228434cea
commit
f3b019d1d2
@@ -46,9 +46,9 @@ static int rawoutstream_puts(FAR struct lib_outstream_s *this,
|
|||||||
FAR struct lib_rawoutstream_s *rthis =
|
FAR struct lib_rawoutstream_s *rthis =
|
||||||
(FAR struct lib_rawoutstream_s *)this;
|
(FAR struct lib_rawoutstream_s *)this;
|
||||||
int nwritten = 0;
|
int nwritten = 0;
|
||||||
int ret;
|
int ret = 0;
|
||||||
|
|
||||||
while (1)
|
while (nwritten != len)
|
||||||
{
|
{
|
||||||
ret = _NX_WRITE(rthis->fd, (FAR const char *)buf + nwritten,
|
ret = _NX_WRITE(rthis->fd, (FAR const char *)buf + nwritten,
|
||||||
len - nwritten);
|
len - nwritten);
|
||||||
|
|||||||
@@ -32,49 +32,36 @@
|
|||||||
* Private Functions
|
* Private Functions
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
/****************************************************************************
|
|
||||||
* Name: stdoutstream_puts
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
static int stdoutstream_puts(FAR struct lib_outstream_s *this,
|
|
||||||
FAR const void *buf, int len)
|
|
||||||
{
|
|
||||||
FAR struct lib_stdoutstream_s *sthis =
|
|
||||||
(FAR struct lib_stdoutstream_s *)this;
|
|
||||||
int nwritten = 0;
|
|
||||||
int ret;
|
|
||||||
|
|
||||||
DEBUGASSERT(this && sthis->stream);
|
|
||||||
|
|
||||||
while (1)
|
|
||||||
{
|
|
||||||
ret = fwrite((FAR char *)buf + nwritten,
|
|
||||||
len - nwritten, 1, sthis->stream);
|
|
||||||
if (ret <= 0)
|
|
||||||
{
|
|
||||||
if (_NX_GETERRNO(ret) == EINTR)
|
|
||||||
{
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
this->nput += ret;
|
|
||||||
nwritten += ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
return nwritten > 0 ? nwritten : ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Name: stdoutstream_putc
|
* Name: stdoutstream_putc
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
static void stdoutstream_putc(FAR struct lib_outstream_s *this, int ch)
|
static void stdoutstream_putc(FAR struct lib_outstream_s *this, int ch)
|
||||||
{
|
{
|
||||||
char tmp = ch;
|
FAR struct lib_stdoutstream_s *sthis =
|
||||||
(void)stdoutstream_puts(this, &tmp, 1);
|
(FAR struct lib_stdoutstream_s *)this;
|
||||||
|
int result;
|
||||||
|
|
||||||
|
DEBUGASSERT(this && sthis->stream);
|
||||||
|
|
||||||
|
/* Loop until the character is successfully transferred or an irrecoverable
|
||||||
|
* error occurs.
|
||||||
|
*/
|
||||||
|
|
||||||
|
do
|
||||||
|
{
|
||||||
|
result = fputc(ch, sthis->stream);
|
||||||
|
if (result != EOF)
|
||||||
|
{
|
||||||
|
this->nput++;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* EINTR (meaning that fputc was interrupted by a signal) is the only
|
||||||
|
* recoverable error.
|
||||||
|
*/
|
||||||
|
}
|
||||||
|
while (get_errno() == EINTR);
|
||||||
}
|
}
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
@@ -119,7 +106,6 @@ void lib_stdoutstream(FAR struct lib_stdoutstream_s *outstream,
|
|||||||
/* Select the put operation */
|
/* Select the put operation */
|
||||||
|
|
||||||
outstream->public.put = stdoutstream_putc;
|
outstream->public.put = stdoutstream_putc;
|
||||||
outstream->public.puts = stdoutstream_puts;
|
|
||||||
|
|
||||||
/* Select the correct flush operation. This flush is only called when
|
/* Select the correct flush operation. This flush is only called when
|
||||||
* a newline is encountered in the output stream. However, we do not
|
* a newline is encountered in the output stream. However, we do not
|
||||||
|
|||||||
Reference in New Issue
Block a user