Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 42 additions & 7 deletions include/nuttx/streams.h
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ struct lib_sistream_s
off_t nget; /* Total number of characters gotten. Written
* by get method, readable by user */
lib_sigetc_t getc; /* Get one character from the instream */
lib_gets_t gets; /* Get the string from the instream */
lib_sigets_t gets; /* Get the string from the instream */
lib_siseek_t seek; /* Seek to a position in the instream */
};

Expand All @@ -135,8 +135,8 @@ struct lib_sostream_s
* by put method, readable by user */
lib_soputc_t putc; /* Put one character to the outstream */
lib_soputs_t puts; /* Writes the string to the outstream */
lib_soflush_t flush; /* Flush any buffered characters in the outstream */
lib_soseek_t seek; /* Seek a position in the output stream */
lib_soflush_t flush; /* Flush any buffered characters in the outstream */
};

/* These are streams that operate on a fixed-sized block of memory */
Expand Down Expand Up @@ -211,9 +211,10 @@ struct lib_rawoutstream_s
int fd;
};

struct lib_fileinstream_s
#ifndef CONFIG_DISABLE_MOUNTPOINT
struct lib_filesistream_s
{
struct lib_instream_s common;
struct lib_sistream_s common;
struct file file;
};

Expand Down Expand Up @@ -285,6 +286,18 @@ struct lib_syslograwstream_s
/* LZF compressed stream pipeline */

#ifdef CONFIG_LIBC_LZF

struct lib_lzfsistream_s
{
struct lib_sistream_s common;
FAR struct lib_sistream_s *backend;
off_t offset;
off_t blkoff;
off_t blkcoff;
char out[LZF_STREAM_BLOCKSIZE];
char in[LZF_MAX_HDR_SIZE + LZF_STREAM_BLOCKSIZE];
};

struct lib_lzfoutstream_s
{
struct lib_outstream_s common;
Expand Down Expand Up @@ -406,7 +419,7 @@ void lib_stdsostream(FAR struct lib_stdsostream_s *stream,
FAR FILE *handle);

/****************************************************************************
* Name: lib_fileinstream_open, lib_fileinstream_close,
* Name: lib_filesistream_open, lib_filesistream_close,
* lib_fileoutstream_open, lib_fileoutstream_close
*
* Description:
Expand All @@ -428,9 +441,10 @@ void lib_stdsostream(FAR struct lib_stdsostream_s *stream,
*
****************************************************************************/

int lib_fileinstream_open(FAR struct lib_fileinstream_s *stream,
#ifndef CONFIG_DISABLE_MOUNTPOINT
int lib_filesistream_open(FAR struct lib_filesistream_s *stream,
FAR const char *path, int oflag, mode_t mode);
void lib_fileinstream_close(FAR struct lib_fileinstream_s *stream);
void lib_filesistream_close(FAR struct lib_filesistream_s *stream);
int lib_fileoutstream_open(FAR struct lib_fileoutstream_s *stream,
FAR const char *path, int oflag, mode_t mode);
void lib_fileoutstream_close(FAR struct lib_fileoutstream_s *stream);
Expand Down Expand Up @@ -627,6 +641,27 @@ void lib_syslograwstream_close(FAR struct lib_syslograwstream_s *stream);
# define lib_syslograwstream_close(s)
#endif

/****************************************************************************
* Name: lib_lzfsistream
*
* Description:
* LZF decompressed pipeline stream
*
* Input Parameters:
* stream - User allocated, uninitialized instance of struct
* lib_lzfsistream_s to be initialized.
* backend - Stream backend port.
*
* Returned Value:
* None (User allocated instance initialized).
*
****************************************************************************/

#ifdef CONFIG_LIBC_LZF
void lib_lzfsistream(FAR struct lib_lzfsistream_s *sistream,
FAR struct lib_sistream_s *backend);
#endif

/****************************************************************************
* Name: lib_lzfoutstream
*
Expand Down
4 changes: 2 additions & 2 deletions libs/libc/stream/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ list(
lib_bufferedoutstream.c
lib_hexdumpstream.c
lib_base64outstream.c
lib_fileinstream.c
lib_filesistream.c
lib_fileoutstream.c
lib_libbsprintf.c
lib_libvscanf.c
Expand All @@ -60,7 +60,7 @@ if(CONFIG_FILE_STREAM)
endif()

if(CONFIG_LIBC_LZF)
list(APPEND SRCS lib_lzfcompress.c)
list(APPEND SRCS lib_lzfcompress.c lib_lzfdecompress.c)
endif()

if(NOT CONFIG_DISABLE_MOUNTPOINT)
Expand Down
4 changes: 2 additions & 2 deletions libs/libc/stream/Make.defs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ CSRCS += lib_zeroinstream.c lib_nullinstream.c lib_nulloutstream.c
CSRCS += lib_mtdoutstream.c lib_libnoflush.c lib_libsnoflush.c
CSRCS += lib_syslogstream.c lib_syslograwstream.c lib_bufferedoutstream.c
CSRCS += lib_hexdumpstream.c lib_base64outstream.c lib_mtdsostream.c
CSRCS += lib_fileinstream.c lib_fileoutstream.c lib_libbsprintf.c
CSRCS += lib_filesistream.c lib_fileoutstream.c lib_libosprintf.c
CSRCS += lib_libvscanf.c lib_libvsprintf.c lib_ultoa_invert.c

ifeq ($(CONFIG_LIBC_FLOATINGPOINT),y)
Expand All @@ -45,7 +45,7 @@ CSRCS += lib_stdsostream.c
endif

ifeq ($(CONFIG_LIBC_LZF),y)
CSRCS += lib_lzfcompress.c
CSRCS += lib_lzfcompress.c lib_lzfdecompress.c
endif

ifeq ($(CONFIG_DISABLE_MOUNTPOINT),)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/****************************************************************************
* libs/libc/stream/lib_fileinstream.c
* libs/libc/stream/lib_filesistream.c
*
* SPDX-License-Identifier: Apache-2.0
*
Expand Down Expand Up @@ -37,60 +37,80 @@
****************************************************************************/

/****************************************************************************
* Name: fileinstream_gets
* Name: filesistream_gets
****************************************************************************/

static ssize_t fileinstream_gets(FAR struct lib_instream_s *self,
static ssize_t filesistream_gets(FAR struct lib_sistream_s *self,
FAR void *buf, size_t len)
{
FAR struct lib_fileinstream_s *stream =
(FAR struct lib_fileinstream_s *)self;
ssize_t nread;
FAR struct lib_filesistream_s *stream =
(FAR struct lib_filesistream_s *)self;
size_t left = len;
ssize_t ret = 0;

do
while (left >= 0)
{
nread = file_read(&stream->file, buf, len);
ret = file_read(&stream->file, buf, left);
if (ret == -EINTR)
{
continue;
}
else if (ret <= 0)
{
break;
}

self->nget += ret;
buf += ret;
left -= ret;
}
while (nread == -EINTR);

if (nread >= 0)
{
self->nget += nread;
}

return nread;
return left == len ? ret : len - left;
}

/****************************************************************************
* Name: fileinstream_getc
* Name: filesistream_getc
****************************************************************************/

static int fileinstream_getc(FAR struct lib_instream_s *self)
static int filesistream_getc(FAR struct lib_sistream_s *self)
{
unsigned char ch;
return fileinstream_gets(self, &ch, 1) == 1 ? ch : EOF;
return filesistream_gets(self, &ch, 1) == 1 ? ch : EOF;
}

/****************************************************************************
* Name: filesistream_getc
****************************************************************************/

static off_t filesistream_seek(FAR struct lib_sistream_s *self, off_t offset,
int whence)
{
FAR struct lib_filesistream_s *stream =
(FAR struct lib_filesistream_s *)self;

return file_seek(&stream->file, offset, whence);
}

/****************************************************************************
* Public Functions
****************************************************************************/

/****************************************************************************
* Name: lib_fileinstream_open
* Name: lib_filesistream_open
*
* Description:
* Initializes a stream for use with a file descriptor.
*
* Input Parameters:
* stream - User allocated, uninitialized instance of struct
* lib_fileinstream_s to be initialized.
* lib_filesistream_s to be initialized.
*
* Returned Value:
* None (User allocated instance initialized).
*
****************************************************************************/

int lib_fileinstream_open(FAR struct lib_fileinstream_s *stream,
int lib_filesistream_open(FAR struct lib_filesistream_s *stream,
FAR const char *path, int oflag, mode_t mode)
{
int ret;
Expand All @@ -101,29 +121,30 @@ int lib_fileinstream_open(FAR struct lib_fileinstream_s *stream,
return ret;
}

stream->common.getc = fileinstream_getc;
stream->common.gets = fileinstream_gets;
stream->common.getc = filesistream_getc;
stream->common.gets = filesistream_gets;
stream->common.seek = filesistream_seek;
stream->common.nget = 0;

return 0;
}

/****************************************************************************
* Name: lib_fileinstream_close
* Name: lib_filesistream_close
*
* Description:
* Close the file associated with the stream.
*
* Input Parameters:
* stream - User allocated, uninitialized instance of struct
* lib_fileinstream_s to be initialized.
* lib_filesistream_s to be initialized.
*
* Returned Value:
* None (User allocated instance initialized).
*
****************************************************************************/

void lib_fileinstream_close(FAR struct lib_fileinstream_s *stream)
void lib_filesistream_close(FAR struct lib_filesistream_s *stream)
{
if (stream != NULL)
{
Expand Down
Loading
Loading