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; FAR struct lib_rawoutstream_s *rthis =
char buffer = ch; (FAR struct lib_rawoutstream_s *)this;
int nwritten; int nwritten = 0;
int errcode; int ret = 0;
DEBUGASSERT(this && rthis->fd >= 0); while (nwritten != len)
/* Loop until the character is successfully transferred or until an
* irrecoverable error occurs.
*/
do
{ {
nwritten = _NX_WRITE(rthis->fd, &buffer, 1); ret = _NX_WRITE(rthis->fd, (FAR const char *)buf + nwritten,
if (nwritten == 1) len - nwritten);
if (ret <= 0)
{ {
this->nput++; if (_NX_GETERRNO(ret) == EINTR)
return; {
continue;
} }
/* The only expected error is EINTR, meaning that the write operation break;
* was awakened by a signal. Zero would not be a valid return value
* from _NX_WRITE().
*/
errcode = _NX_GETERRNO(nwritten);
DEBUGASSERT(nwritten < 0);
} }
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, static void rawoutstream_putc(FAR struct lib_outstream_s *this, int ch)
int whence)
{ {
FAR struct lib_rawsostream_s *mthis = (FAR struct lib_rawsostream_s *)this; char tmp = ch;
rawoutstream_puts(this, &tmp, 1);
DEBUGASSERT(this);
return _NX_SEEK(mthis->fd, offset, whence);
} }
/**************************************************************************** /****************************************************************************
@ -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: * Description:
* Initializes a stream for use with a file descriptor. * Initializes a stream for use with a file descriptor.
* *
* Input Parameters: * Input Parameters:
* outstream - User allocated, uninitialized instance of struct * 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 * fd - User provided file/socket descriptor (must have been opened
* for write access). * 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.putc = rawoutstream_putc;
outstream->public.flush = lib_snoflush; outstream->public.puts = rawoutstream_puts;
outstream->public.seek = rawsostream_seek; outstream->public.flush = lib_noflush;
outstream->public.nput = 0; outstream->public.nput = 0;
outstream->fd = fd; 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, static void rawsostream_putc(FAR struct lib_sostream_s *this, int ch)
FAR const void *buf, int len)
{ {
FAR struct lib_rawoutstream_s *rthis = FAR struct lib_rawsostream_s *rthis = (FAR struct lib_rawsostream_s *)this;
(FAR struct lib_rawoutstream_s *)this; char buffer = ch;
int nwritten = 0; int nwritten;
int ret = 0; 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, nwritten = _NX_WRITE(rthis->fd, &buffer, 1);
len - nwritten); if (nwritten == 1)
if (ret <= 0)
{ {
if (_NX_GETERRNO(ret) == EINTR) this->nput++;
{ return;
continue;
} }
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; errcode = _NX_GETERRNO(nwritten);
nwritten += ret; DEBUGASSERT(nwritten < 0);
} }
while (errcode == EINTR);
return nwritten > 0 ? nwritten : ret;
} }
/**************************************************************************** /****************************************************************************
* 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; FAR struct lib_rawsostream_s *mthis = (FAR struct lib_rawsostream_s *)this;
rawoutstream_puts(this, &tmp, 1);
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: * Description:
* Initializes a stream for use with a file descriptor. * Initializes a stream for use with a file descriptor.
* *
* Input Parameters: * Input Parameters:
* outstream - User allocated, uninitialized instance of struct * 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 * fd - User provided file/socket descriptor (must have been opened
* for write access). * 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.putc = rawsostream_putc;
outstream->public.puts = rawoutstream_puts; outstream->public.flush = lib_snoflush;
outstream->public.flush = lib_noflush; outstream->public.seek = rawsostream_seek;
outstream->public.nput = 0; outstream->public.nput = 0;
outstream->fd = fd; outstream->fd = fd;
} }