diff --git a/include/nuttx/streams.h b/include/nuttx/streams.h index a55e15c6668288b209e74366a0002609cd83586f..cdba45e9e203ee8a1fc2a7dda6e9d9568f3b4102 100644 --- a/include/nuttx/streams.h +++ b/include/nuttx/streams.h @@ -120,7 +120,7 @@ struct lib_rawinstream_s /**************************************************************************** * Public Variables ****************************************************************************/ - + #undef EXTERN #if defined(__cplusplus) # define EXTERN extern "C" @@ -134,54 +134,134 @@ extern "C" * Public Function Prototypes ****************************************************************************/ -/* Defined in lib/lib_meminstream.c */ +/**************************************************************************** + * Name: lib_meminstream, lib_memoutstream + * + * Description: + * Initializes a stream for use with a fixed-size memory buffer. + * Defined in lib/lib_meminstream.c and lib/lib_memoutstream.c + * + * Input parameters: + * meminstream - User allocated, uninitialized instance of struct + * lib_meminstream_s to be initialized. + * memoutstream - User allocated, uninitialized instance of struct + * lib_memoutstream_s to be initialized. + * bufstart - Address of the beginning of the fixed-size memory buffer + * buflen - Size of the fixed-sized memory buffer in bytes + * + * Returned Value: + * None (User allocated instance initialized). + * + ****************************************************************************/ EXTERN void lib_meminstream(FAR struct lib_meminstream_s *meminstream, FAR const char *bufstart, int buflen); - -/* Defined in lib/lib_memoutstream.c */ - EXTERN void lib_memoutstream(FAR struct lib_memoutstream_s *memoutstream, FAR char *bufstart, int buflen); -/* Defined in lib/lib_stdinstream.c */ +/**************************************************************************** + * Name: lib_stdinstream, lib_stdoutstream + * + * Description: + * Initializes a stream for use with a FILE instance. + * Defined in lib/lib_stdinstream.c and lib/lib_stdoutstream.c + * + * Input parameters: + * stdinstream - User allocated, uninitialized instance of struct + * lib_stdinstream_s to be initialized. + * stdoutstream - User allocated, uninitialized instance of struct + * lib_stdoutstream_s to be initialized. + * stream - User provided stream instance (must have been opened for + * the correct access). + * + * Returned Value: + * None (User allocated instance initialized). + * + ****************************************************************************/ EXTERN void lib_stdinstream(FAR struct lib_stdinstream_s *stdinstream, FAR FILE *stream); - -/* Defined in lib/lib_stdoutstream.c */ - EXTERN void lib_stdoutstream(FAR struct lib_stdoutstream_s *stdoutstream, FAR FILE *stream); -/* Defined in lib/lib_rawinstream.c */ +/**************************************************************************** + * Name: lib_rawinstream, lib_rawoutstream + * + * Description: + * Initializes a stream for use with a file descriptor. + * Defined in lib/lib_rawinstream.c and lib/lib_rawoutstream.c + * + * Input parameters: + * rawinstream - User allocated, uninitialized instance of struct + * lib_rawinstream_s to be initialized. + * rawoutstream - User allocated, uninitialized instance of struct + * lib_rawoutstream_s to be initialized. + * fd - User provided file/socket descriptor (must have been opened + * for the correct access). + * + * Returned Value: + * None (User allocated instance initialized). + * + ****************************************************************************/ EXTERN void lib_rawinstream(FAR struct lib_rawinstream_s *rawinstream, int fd); - -/* Defined in lib/lib_rawoutstream.c */ - EXTERN void lib_rawoutstream(FAR struct lib_rawoutstream_s *rawoutstream, - int fd); + int fd); -/* Defined in lib/lib_lowinstream.c */ +/**************************************************************************** + * Name: lib_lowinstream, lib_lowoutstream + * + * Description: + * Initializes a stream for use with low-level, architecture-specific I/O. + * Defined in lib/lib_lowinstream.c and lib/lib_lowoutstream.c + * + * Input parameters: + * lowinstream - User allocated, uninitialized instance of struct + * lib_lowinstream_s to be initialized. + * lowoutstream - User allocated, uninitialized instance of struct + * lib_lowoutstream_s to be initialized. + * + * Returned Value: + * None (User allocated instance initialized). + * + ****************************************************************************/ #ifdef CONFIG_ARCH_LOWGETC EXTERN void lib_lowinstream(FAR struct lib_instream_s *lowinstream); #endif - -/* Defined in lib/lib_lowoutstream.c */ - #ifdef CONFIG_ARCH_LOWPUTC EXTERN void lib_lowoutstream(FAR struct lib_outstream_s *lowoutstream); #endif -/* Defined in lib/lib_nullinstream.c */ +/**************************************************************************** + * Name: lib_zeroinstream, lib_nullinstream, lib_nulloutstream + * + * Description: + * Initializes NULL streams: + * + * o The stream created by lib_zeroinstream will return an infinitely long + * stream of zeroes. Defined in lib/lib_zeroinstream.c + * o The stream created by lib_nullinstream will return only EOF. + * Defined in lib/lib_nullinstream.c + * o The stream created by lib_nulloutstream will write all data to the + * bit-bucket. Defined in lib/lib_nulloutstream.c + * + * Input parameters: + * zeroinstream - User allocated, uninitialized instance of struct + * lib_instream_s to be initialized. + * nullinstream - User allocated, uninitialized instance of struct + * lib_instream_s to be initialized. + * nulloutstream - User allocated, uninitialized instance of struct + * lib_outstream_s to be initialized. + * + * Returned Value: + * None (User allocated instance initialized). + * + ****************************************************************************/ +EXTERN void lib_zeroinstream(FAR struct lib_instream_s *zeroinstream); EXTERN void lib_nullinstream(FAR struct lib_instream_s *nullinstream); - -/* Defined in lib/lib_nulloutstream.c */ - EXTERN void lib_nulloutstream(FAR struct lib_outstream_s *nulloutstream); #undef EXTERN diff --git a/lib/Makefile b/lib/Makefile index 32c2e620dec5bef3aa7ae92d1960bb171e148837..9b023d04e1fa03659979e763c0d819198fe95d72 100644 --- a/lib/Makefile +++ b/lib/Makefile @@ -56,7 +56,8 @@ STDIO_SRCS = lib_printf.c lib_rawprintf.c lib_lowprintf.c lib_dbg.c \ lib_sprintf.c lib_snprintf.c lib_libsprintf.c lib_vsprintf.c \ lib_vsnprintf.c lib_libvsprintf.c lib_meminstream.c \ lib_memoutstream.c lib_lowinstream.c lib_lowoutstream.c \ - lib_nullinstream.c lib_nulloutstream.c lib_sscanf.c + lib_zeroinstream.c lib_nullinstream.c lib_nulloutstream.c \ + lib_sscanf.c ifneq ($(CONFIG_NFILE_DESCRIPTORS),0) STDIO_SRCS += lib_rawinstream.c lib_rawoutstream.c diff --git a/lib/lib_lowinstream.c b/lib/lib_lowinstream.c index f92fdb5ad0ec931b6b9c33a0dfd7fa62ecbcf3a7..c5016bebe7615478d4fde8bb98fe90982faa6202 100644 --- a/lib/lib_lowinstream.c +++ b/lib/lib_lowinstream.c @@ -69,6 +69,17 @@ static int lowinstream_getc(FAR struct lib_outstream_s *this) /**************************************************************************** * Name: lib_lowinstream + * + * Description: + * Initializes a stream for use with low-level, architecture-specific I/O. + * + * Input parameters: + * lowoutstream - User allocated, uninitialized instance of struct + * lib_lowoutstream_s to be initialized. + * + * Returned Value: + * None (User allocated instance initialized). + * ****************************************************************************/ void lib_lowinstream(FAR struct lib_outstream_s *stream) diff --git a/lib/lib_lowoutstream.c b/lib/lib_lowoutstream.c index dad84ce85145438895ebbf96124ff43751c2d711..0bbf6450fcdc08cd5ec828fab768235f458e4075 100644 --- a/lib/lib_lowoutstream.c +++ b/lib/lib_lowoutstream.c @@ -69,6 +69,17 @@ static void lowoutstream_putc(FAR struct lib_outstream_s *this, int ch) /**************************************************************************** * Name: lib_lowoutstream + * + * Description: + * Initializes a stream for use with low-level, architecture-specific I/O. + * + * Input parameters: + * lowoutstream - User allocated, uninitialized instance of struct + * lib_lowoutstream_s to be initialized. + * + * Returned Value: + * None (User allocated instance initialized). + * ****************************************************************************/ void lib_lowoutstream(FAR struct lib_outstream_s *stream) diff --git a/lib/lib_meminstream.c b/lib/lib_meminstream.c index 5453d2775d1c2fd814a2717315784730a9f110b6..62260c63928a48e0dcad90a325818486e87bff1b 100644 --- a/lib/lib_meminstream.c +++ b/lib/lib_meminstream.c @@ -70,6 +70,19 @@ static int meminstream_getc(FAR struct lib_instream_s *this) /**************************************************************************** * Name: lib_meminstream + * + * Description: + * Initializes a stream for use with a fixed-size memory buffer. + * + * Input parameters: + * meminstream - User allocated, uninitialized instance of struct + * lib_meminstream_s to be initialized. + * bufstart - Address of the beginning of the fixed-size memory buffer + * buflen - Size of the fixed-sized memory buffer in bytes + * + * Returned Value: + * None (meminstream initialized). + * ****************************************************************************/ void lib_meminstream(FAR struct lib_meminstream_s *meminstream, diff --git a/lib/lib_memoutstream.c b/lib/lib_memoutstream.c index 7e6412304a7f2480d9d33a6781808de1e5dbcd82..0395e22a96dc0110673d383b77d4effa21f8b041 100644 --- a/lib/lib_memoutstream.c +++ b/lib/lib_memoutstream.c @@ -64,6 +64,19 @@ static void memoutstream_putc(FAR struct lib_outstream_s *this, int ch) /**************************************************************************** * Name: lib_memoutstream + * + * Description: + * Initializes a stream for use with a fixed-size memory buffer. + * + * Input parameters: + * memoutstream - User allocated, uninitialized instance of struct + * lib_memoutstream_s to be initialized. + * bufstart - Address of the beginning of the fixed-size memory buffer + * buflen - Size of the fixed-sized memory buffer in bytes + * + * Returned Value: + * None (memoutstream initialized). + * ****************************************************************************/ void lib_memoutstream(FAR struct lib_memoutstream_s *memoutstream, diff --git a/lib/lib_nullinstream.c b/lib/lib_nullinstream.c index dec0a191e1bd8e9e9edf3aa06a12f6343fe845e3..cd24bc1f6e4793b30afae14550674bc5edcb5be1 100644 --- a/lib/lib_nullinstream.c +++ b/lib/lib_nullinstream.c @@ -47,14 +47,29 @@ static int nullinstream_getc(FAR struct lib_instream_s *this) { - this->nget++; - return 0; + return EOF; } /**************************************************************************** * Public Functions ****************************************************************************/ +/**************************************************************************** + * Name: lib_nullinstream + * + * Description: + * Initializes a NULL stream. The initialized stream will will return only + * EOF. + * + * Input parameters: + * nullinstream - User allocated, uninitialized instance of struct + * lib_instream_s to be initialized. + * + * Returned Value: + * None (User allocated instance initialized). + * + ****************************************************************************/ + void lib_nullinstream(FAR struct lib_instream_s *nullinstream) { nullinstream->get = nullinstream_getc; diff --git a/lib/lib_nulloutstream.c b/lib/lib_nulloutstream.c index f2638fbcfb9219d057a76f234239eb2efede4671..c3dcfe0f6faeda10f4ce3e303288991d24341f9a 100644 --- a/lib/lib_nulloutstream.c +++ b/lib/lib_nulloutstream.c @@ -54,6 +54,22 @@ static void nulloutstream_putc(FAR struct lib_outstream_s *this, int ch) * Public Functions ****************************************************************************/ +/**************************************************************************** + * Name: lib_nulloutstream + * + * Description: + * Initializes a NULL streams. The initialized stream will write all data + * to the bit-bucket. + * + * Input parameters: + * nulloutstream - User allocated, uninitialized instance of struct + * lib_outstream_s to be initialized. + * + * Returned Value: + * None (User allocated instance initialized). + * + ****************************************************************************/ + void lib_nulloutstream(FAR struct lib_outstream_s *nulloutstream) { nulloutstream->put = nulloutstream_putc; diff --git a/lib/lib_rawinstream.c b/lib/lib_rawinstream.c index 39cfa0b1ebc99c7fdc168844f907dfc4adeb2465..de7301a58245b9208f1ab9031a30902f70243c3e 100644 --- a/lib/lib_rawinstream.c +++ b/lib/lib_rawinstream.c @@ -78,6 +78,19 @@ static int rawinstream_getc(FAR struct lib_instream_s *this) /**************************************************************************** * Name: lib_rawinstream + * + * Description: + * Initializes a stream for use with a file descriptor. + * + * Input parameters: + * rawinstream - User allocated, uninitialized instance of struct + * lib_rawinstream_s to be initialized. + * fd - User provided file/socket descriptor (must have been opened + * for the correct access). + * + * Returned Value: + * None (User allocated instance initialized). + * ****************************************************************************/ void lib_rawinstream(FAR struct lib_rawinstream_s *rawinstream, int fd) diff --git a/lib/lib_rawoutstream.c b/lib/lib_rawoutstream.c index 1772f3927f81036fdd0a55fdd3067795ae3d2bcc..4d102446bd84e04bfe4146e05f04f79ff642b8ac 100644 --- a/lib/lib_rawoutstream.c +++ b/lib/lib_rawoutstream.c @@ -74,6 +74,19 @@ static void rawoutstream_putc(FAR struct lib_outstream_s *this, int ch) /**************************************************************************** * Name: lib_rawoutstream + * + * Description: + * Initializes a stream for use with a file descriptor. + * + * Input parameters: + * rawoutstream - User allocated, uninitialized instance of struct + * lib_rawoutstream_s to be initialized. + * fd - User provided file/socket descriptor (must have been opened + * for write access). + * + * Returned Value: + * None (User allocated instance initialized). + * ****************************************************************************/ void lib_rawoutstream(FAR struct lib_rawoutstream_s *rawoutstream, int fd) diff --git a/lib/lib_stdinstream.c b/lib/lib_stdinstream.c index 1833f3a7ae993f8c80de03bd1dbe11e04ad668e9..182696eade4c2e4aa6b087cbd840f4aa470de1ec 100644 --- a/lib/lib_stdinstream.c +++ b/lib/lib_stdinstream.c @@ -69,6 +69,19 @@ static int stdinstream_getc(FAR struct lib_instream_s *this) /**************************************************************************** * Name: lib_stdinstream + * + * Description: + * Initializes a stream for use with a FILE instance. + * + * Input parameters: + * stdinstream - User allocated, uninitialized instance of struct + * lib_stdinstream_s to be initialized. + * stream - User provided stream instance (must have been opened for + * read access). + * + * Returned Value: + * None (User allocated instance initialized). + * ****************************************************************************/ void lib_stdinstream(FAR struct lib_stdinstream_s *stdinstream, diff --git a/lib/lib_stdoutstream.c b/lib/lib_stdoutstream.c index 66864d07c325a50daecdb8a5fe89fcff696c02a4..d92236edb773f015652341c3c1f7d7034cd30041 100644 --- a/lib/lib_stdoutstream.c +++ b/lib/lib_stdoutstream.c @@ -65,6 +65,19 @@ static void stdoutstream_putc(FAR struct lib_outstream_s *this, int ch) /**************************************************************************** * Name: lib_stdoutstream + * + * Description: + * Initializes a stream for use with a FILE instance. + * + * Input parameters: + * stdoutstream - User allocated, uninitialized instance of struct + * lib_stdoutstream_s to be initialized. + * stream - User provided stream instance (must have been opened for + * write access). + * + * Returned Value: + * None (User allocated instance initialized). + * ****************************************************************************/ void lib_stdoutstream(FAR struct lib_stdoutstream_s *stdoutstream, diff --git a/lib/lib_zeroinstream.c b/lib/lib_zeroinstream.c new file mode 100644 index 0000000000000000000000000000000000000000..8cf55f51dc83701606e64f278af40b904ee5dbd9 --- /dev/null +++ b/lib/lib_zeroinstream.c @@ -0,0 +1,79 @@ +/**************************************************************************** + * lib/lib_zeroinstream.c + * + * Copyright (C) 2009 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt <spudmonkey@racsa.co.cr> + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include <stdio.h> +#include <errno.h> +#include "lib_internal.h" + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +static int zeroinstream_getc(FAR struct lib_instream_s *this) +{ + this->nget++; + return 0; +} + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: lib_zeroinstream + * + * Description: + * Initializes a NULL stream. The initialized stream will return an + * infinitely long stream of zeroes. + * + * Input parameters: + * zeroinstream - User allocated, uninitialized instance of struct + * lib_instream_s to be initialized. + * + * Returned Value: + * None (User allocated instance initialized). + * + ****************************************************************************/ + +void lib_zeroinstream(FAR struct lib_instream_s *zeroinstream) +{ + zeroinstream->get = zeroinstream_getc; + zeroinstream->nget = 0; +} +