stream: Exchange name of lib_rawsostream.c and lib_rawoutstream.c

Signed-off-by: Huang Qi <huangqi3@xiaomi.com>
This commit is contained in:
Huang Qi 2023-03-01 16:42:46 +08:00 committed by Alan Carvalho de Assis
parent 266455f01c
commit b99a96a7d0
2 changed files with 69 additions and 69 deletions

View File

@ -37,53 +37,46 @@
****************************************************************************/
/****************************************************************************
* Name: rawsostream_putc
* Name: rawoutstream_puts
****************************************************************************/
static void rawsostream_putc(FAR struct lib_sostream_s *this, int ch)
static int rawoutstream_puts(FAR struct lib_outstream_s *this,
FAR const void *buf, int len)
{
FAR struct lib_rawsostream_s *rthis = (FAR struct lib_rawsostream_s *)this;
char buffer = ch;
int nwritten;
int errcode;
FAR struct lib_rawoutstream_s *rthis =
(FAR struct lib_rawoutstream_s *)this;
int nwritten = 0;
int ret = 0;
DEBUGASSERT(this && rthis->fd >= 0);
/* Loop until the character is successfully transferred or until an
* irrecoverable error occurs.
*/
do
while (nwritten != len)
{
nwritten = _NX_WRITE(rthis->fd, &buffer, 1);
if (nwritten == 1)
ret = _NX_WRITE(rthis->fd, (FAR const char *)buf + nwritten,
len - nwritten);
if (ret <= 0)
{
this->nput++;
return;
if (_NX_GETERRNO(ret) == EINTR)
{
continue;
}
/* 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().
*/
errcode = _NX_GETERRNO(nwritten);
DEBUGASSERT(nwritten < 0);
break;
}
while (errcode == EINTR);
this->nput += ret;
nwritten += ret;
}
return nwritten > 0 ? nwritten : ret;
}
/****************************************************************************
* Name: rawsostream_seek
* Name: rawoutstream_putc
****************************************************************************/
static off_t rawsostream_seek(FAR struct lib_sostream_s *this, off_t offset,
int whence)
static void rawoutstream_putc(FAR struct lib_outstream_s *this, int ch)
{
FAR struct lib_rawsostream_s *mthis = (FAR struct lib_rawsostream_s *)this;
DEBUGASSERT(this);
return _NX_SEEK(mthis->fd, offset, whence);
char tmp = ch;
rawoutstream_puts(this, &tmp, 1);
}
/****************************************************************************
@ -91,14 +84,14 @@ static off_t rawsostream_seek(FAR struct lib_sostream_s *this, off_t offset,
****************************************************************************/
/****************************************************************************
* Name: lib_rawsostream
* Name: lib_rawoutstream
*
* Description:
* Initializes a stream for use with a file descriptor.
*
* Input Parameters:
* outstream - User allocated, uninitialized instance of struct
* lib_rawsostream_s to be initialized.
* lib_rawoutstream_s to be initialized.
* fd - User provided file/socket descriptor (must have been opened
* for write access).
*
@ -107,11 +100,11 @@ static off_t rawsostream_seek(FAR struct lib_sostream_s *this, off_t offset,
*
****************************************************************************/
void lib_rawsostream(FAR struct lib_rawsostream_s *outstream, int fd)
void lib_rawoutstream(FAR struct lib_rawoutstream_s *outstream, int fd)
{
outstream->public.putc = rawsostream_putc;
outstream->public.flush = lib_snoflush;
outstream->public.seek = rawsostream_seek;
outstream->public.putc = rawoutstream_putc;
outstream->public.puts = rawoutstream_puts;
outstream->public.flush = lib_noflush;
outstream->public.nput = 0;
outstream->fd = fd;
}

View File

@ -37,46 +37,53 @@
****************************************************************************/
/****************************************************************************
* Name: rawoutstream_puts
* Name: rawsostream_putc
****************************************************************************/
static int rawoutstream_puts(FAR struct lib_outstream_s *this,
FAR const void *buf, int len)
static void rawsostream_putc(FAR struct lib_sostream_s *this, int ch)
{
FAR struct lib_rawoutstream_s *rthis =
(FAR struct lib_rawoutstream_s *)this;
int nwritten = 0;
int ret = 0;
FAR struct lib_rawsostream_s *rthis = (FAR struct lib_rawsostream_s *)this;
char buffer = ch;
int nwritten;
int errcode;
while (nwritten != len)
DEBUGASSERT(this && rthis->fd >= 0);
/* Loop until the character is successfully transferred or until an
* irrecoverable error occurs.
*/
do
{
ret = _NX_WRITE(rthis->fd, (FAR const char *)buf + nwritten,
len - nwritten);
if (ret <= 0)
nwritten = _NX_WRITE(rthis->fd, &buffer, 1);
if (nwritten == 1)
{
if (_NX_GETERRNO(ret) == EINTR)
{
continue;
this->nput++;
return;
}
break;
}
/* 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().
*/
this->nput += ret;
nwritten += ret;
errcode = _NX_GETERRNO(nwritten);
DEBUGASSERT(nwritten < 0);
}
return nwritten > 0 ? nwritten : ret;
while (errcode == EINTR);
}
/****************************************************************************
* Name: rawoutstream_putc
* Name: rawsostream_seek
****************************************************************************/
static void rawoutstream_putc(FAR struct lib_outstream_s *this, int ch)
static off_t rawsostream_seek(FAR struct lib_sostream_s *this, off_t offset,
int whence)
{
char tmp = ch;
rawoutstream_puts(this, &tmp, 1);
FAR struct lib_rawsostream_s *mthis = (FAR struct lib_rawsostream_s *)this;
DEBUGASSERT(this);
return _NX_SEEK(mthis->fd, offset, whence);
}
/****************************************************************************
@ -84,14 +91,14 @@ static void rawoutstream_putc(FAR struct lib_outstream_s *this, int ch)
****************************************************************************/
/****************************************************************************
* Name: lib_rawoutstream
* Name: lib_rawsostream
*
* Description:
* Initializes a stream for use with a file descriptor.
*
* Input Parameters:
* outstream - User allocated, uninitialized instance of struct
* lib_rawoutstream_s to be initialized.
* lib_rawsostream_s to be initialized.
* fd - User provided file/socket descriptor (must have been opened
* for write access).
*
@ -100,11 +107,11 @@ static void rawoutstream_putc(FAR struct lib_outstream_s *this, int ch)
*
****************************************************************************/
void lib_rawoutstream(FAR struct lib_rawoutstream_s *outstream, int fd)
void lib_rawsostream(FAR struct lib_rawsostream_s *outstream, int fd)
{
outstream->public.putc = rawoutstream_putc;
outstream->public.puts = rawoutstream_puts;
outstream->public.flush = lib_noflush;
outstream->public.putc = rawsostream_putc;
outstream->public.flush = lib_snoflush;
outstream->public.seek = rawsostream_seek;
outstream->public.nput = 0;
outstream->fd = fd;
}