summaryrefslogtreecommitdiff
path: root/nuttx/lib
diff options
context:
space:
mode:
authorpatacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3>2011-05-14 15:21:04 +0000
committerpatacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3>2011-05-14 15:21:04 +0000
commitf62084035feaf8b9a22804821b22e2a3c15e6eda (patch)
treee2d1548a5bf0d8e33386a178103c756473b90ad6 /nuttx/lib
parent6f8fd8927787deda605f6fb070bab21ee4022084 (diff)
downloadpx4-nuttx-f62084035feaf8b9a22804821b22e2a3c15e6eda.tar.gz
px4-nuttx-f62084035feaf8b9a22804821b22e2a3c15e6eda.tar.bz2
px4-nuttx-f62084035feaf8b9a22804821b22e2a3c15e6eda.zip
Implemented line-oriented buffering for std output
git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@3606 42af7a65-404d-4744-a932-0658087f49c3
Diffstat (limited to 'nuttx/lib')
-rw-r--r--nuttx/lib/lib_internal.h10
-rw-r--r--nuttx/lib/stdio/Make.defs5
-rw-r--r--nuttx/lib/stdio/lib_libnoflush.c103
-rw-r--r--nuttx/lib/stdio/lib_libvsprintf.c13
-rw-r--r--nuttx/lib/stdio/lib_lowinstream.c4
-rw-r--r--nuttx/lib/stdio/lib_lowoutstream.c7
-rw-r--r--nuttx/lib/stdio/lib_memoutstream.c11
-rw-r--r--nuttx/lib/stdio/lib_nulloutstream.c7
-rw-r--r--nuttx/lib/stdio/lib_rawoutstream.c9
-rw-r--r--nuttx/lib/stdio/lib_stdoutstream.c25
10 files changed, 176 insertions, 18 deletions
diff --git a/nuttx/lib/lib_internal.h b/nuttx/lib/lib_internal.h
index b9c74304e..6c9b9c14c 100644
--- a/nuttx/lib/lib_internal.h
+++ b/nuttx/lib/lib_internal.h
@@ -110,10 +110,16 @@ extern void stream_semtake(FAR struct streamlist *list);
extern void stream_semgive(FAR struct streamlist *list);
#endif
+/* Defined in lib_libnoflush.c */
+
+#ifdef CONFIG_STDIO_LINEBUFFER
+extern int lib_noflush(FAR struct lib_outstream_s *this);
+#endif
+
/* Defined in lib_libsprintf.c */
-extern int lib_sprintf (FAR struct lib_outstream_s *obj,
- const char *fmt, ...);
+extern int lib_sprintf(FAR struct lib_outstream_s *obj,
+ const char *fmt, ...);
/* Defined lib_libvsprintf.c */
diff --git a/nuttx/lib/stdio/Make.defs b/nuttx/lib/stdio/Make.defs
index 9478369f3..fe6e106bb 100644
--- a/nuttx/lib/stdio/Make.defs
+++ b/nuttx/lib/stdio/Make.defs
@@ -51,6 +51,11 @@ STDIO_SRCS += lib_fopen.c lib_fclose.c lib_fread.c lib_libfread.c lib_fseek.c \
lib_fprintf.c lib_vfprintf.c lib_stdinstream.c lib_stdoutstream.c
endif
endif
+
ifeq ($(CONFIG_LIBC_FLOATINGPOINT),y)
STDIO_SRCS += lib_dtoa.c
endif
+
+ifeq ($(CONFIG_STDIO_LINEBUFFER),y)
+STDIO_SRCS += lib_libnoflush.c
+endif
diff --git a/nuttx/lib/stdio/lib_libnoflush.c b/nuttx/lib/stdio/lib_libnoflush.c
new file mode 100644
index 000000000..90e5f9f5c
--- /dev/null
+++ b/nuttx/lib/stdio/lib_libnoflush.c
@@ -0,0 +1,103 @@
+/****************************************************************************
+ * lib/stdio/lib_libnoflush.c
+ *
+ * Copyright (C) 2011 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 <nuttx/config.h>
+
+#include <stdbool.h>
+#include <stdio.h>
+#include <fcntl.h>
+#include <errno.h>
+
+#include <nuttx/fs.h>
+
+#include "lib_internal.h"
+
+#ifdef CONFIG_STDIO_LINEBUFFER
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Private Type Declarations
+ ****************************************************************************/
+
+/****************************************************************************
+ * Private Function Prototypes
+ ****************************************************************************/
+
+/****************************************************************************
+ * Global Constant Data
+ ****************************************************************************/
+
+/****************************************************************************
+ * Global Variables
+ ****************************************************************************/
+
+/****************************************************************************
+ * Private Constant Data
+ ****************************************************************************/
+
+/****************************************************************************
+ * Private Variables
+ ****************************************************************************/
+
+/****************************************************************************
+ * Global Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: lib_noflush
+ *
+ * Description:
+ * lib_noflush() provides a common, dummy flush method for output streams
+ * that are not flushable. Only used if CONFIG_STDIO_LINEBUFFER is selected.
+ *
+ * Return:
+ * Always returns OK
+ *
+ ****************************************************************************/
+
+int lib_noflush(FAR struct lib_outstream_s *this)
+{
+ return OK;
+}
+
+#endif /* CONFIG_STDIO_LINEBUFFER */
+
diff --git a/nuttx/lib/stdio/lib_libvsprintf.c b/nuttx/lib/stdio/lib_libvsprintf.c
index 24591d875..8e0709ec9 100644
--- a/nuttx/lib/stdio/lib_libvsprintf.c
+++ b/nuttx/lib/stdio/lib_libvsprintf.c
@@ -1127,7 +1127,20 @@ int lib_vsprintf(FAR struct lib_outstream_s *obj, const char *src, va_list ap)
if (*src != '%')
{
+ /* Output the character */
+
obj->put(obj, *src);
+
+ /* Flush the buffer if a newline is encountered */
+
+#ifdef CONFIG_STDIO_LINEBUFFER
+ if (*src == '\n')
+ {
+ (void)obj->flush(obj);
+ }
+#endif
+ /* Process the next character in the format */
+
continue;
}
diff --git a/nuttx/lib/stdio/lib_lowinstream.c b/nuttx/lib/stdio/lib_lowinstream.c
index 85f916acb..6dcc4a37e 100644
--- a/nuttx/lib/stdio/lib_lowinstream.c
+++ b/nuttx/lib/stdio/lib_lowinstream.c
@@ -55,7 +55,7 @@
* Name: lowinstream_getc
****************************************************************************/
-static int lowinstream_getc(FAR struct lib_outstream_s *this)
+static int lowinstream_getc(FAR struct lib_instream_s *this)
{
if (this && up_getc(ch) != EOF)
{
@@ -82,7 +82,7 @@ static int lowinstream_getc(FAR struct lib_outstream_s *this)
*
****************************************************************************/
-void lib_lowinstream(FAR struct lib_outstream_s *stream)
+void lib_lowinstream(FAR struct lib_instream_s *stream)
{
stream->get = lowinstream_getc;
stream->nget = 0;
diff --git a/nuttx/lib/stdio/lib_lowoutstream.c b/nuttx/lib/stdio/lib_lowoutstream.c
index 2ab7c9f67..3b3d467b2 100644
--- a/nuttx/lib/stdio/lib_lowoutstream.c
+++ b/nuttx/lib/stdio/lib_lowoutstream.c
@@ -84,8 +84,11 @@ static void lowoutstream_putc(FAR struct lib_outstream_s *this, int ch)
void lib_lowoutstream(FAR struct lib_outstream_s *stream)
{
- stream->put = lowoutstream_putc;
- stream->nput = 0;
+ stream->put = lowoutstream_putc;
+#ifdef CONFIG_STDIO_LINEBUFFER
+ stream->flush = lib_noflush;
+#endif
+ stream->nput = 0;
}
#endif /* CONFIG_ARCH_LOWPUTC */
diff --git a/nuttx/lib/stdio/lib_memoutstream.c b/nuttx/lib/stdio/lib_memoutstream.c
index 1cf2a8f29..d5a673b3a 100644
--- a/nuttx/lib/stdio/lib_memoutstream.c
+++ b/nuttx/lib/stdio/lib_memoutstream.c
@@ -82,10 +82,13 @@ static void memoutstream_putc(FAR struct lib_outstream_s *this, int ch)
void lib_memoutstream(FAR struct lib_memoutstream_s *memoutstream,
FAR char *bufstart, int buflen)
{
- memoutstream->public.put = memoutstream_putc;
- memoutstream->public.nput = 0; /* Will be buffer index */
- memoutstream->buffer = bufstart; /* Start of buffer */
- memoutstream->buflen = buflen - 1; /* Save space for null terminator */
+ memoutstream->public.put = memoutstream_putc;
+#ifdef CONFIG_STDIO_LINEBUFFER
+ memoutstream->public.flush = lib_noflush;
+#endif
+ memoutstream->public.nput = 0; /* Will be buffer index */
+ memoutstream->buffer = bufstart; /* Start of buffer */
+ memoutstream->buflen = buflen - 1; /* Save space for null terminator */
}
diff --git a/nuttx/lib/stdio/lib_nulloutstream.c b/nuttx/lib/stdio/lib_nulloutstream.c
index 85b7daa9e..f92cb0f33 100644
--- a/nuttx/lib/stdio/lib_nulloutstream.c
+++ b/nuttx/lib/stdio/lib_nulloutstream.c
@@ -72,7 +72,10 @@ static void nulloutstream_putc(FAR struct lib_outstream_s *this, int ch)
void lib_nulloutstream(FAR struct lib_outstream_s *nulloutstream)
{
- nulloutstream->put = nulloutstream_putc;
- nulloutstream->nput = 0;
+ nulloutstream->put = nulloutstream_putc;
+#ifdef CONFIG_STDIO_LINEBUFFER
+ nulloutstream->flush = lib_noflush;
+#endif
+ nulloutstream->nput = 0;
}
diff --git a/nuttx/lib/stdio/lib_rawoutstream.c b/nuttx/lib/stdio/lib_rawoutstream.c
index 05cb5853f..bea47f3ce 100644
--- a/nuttx/lib/stdio/lib_rawoutstream.c
+++ b/nuttx/lib/stdio/lib_rawoutstream.c
@@ -91,8 +91,11 @@ static void rawoutstream_putc(FAR struct lib_outstream_s *this, int ch)
void lib_rawoutstream(FAR struct lib_rawoutstream_s *rawoutstream, int fd)
{
- rawoutstream->public.put = rawoutstream_putc;
- rawoutstream->public.nput = 0;
- rawoutstream->fd = fd;
+ rawoutstream->public.put = rawoutstream_putc;
+#ifdef CONFIG_STDIO_LINEBUFFER
+ rawoutstream->public.flush = lib_noflush;
+#endif
+ rawoutstream->public.nput = 0;
+ rawoutstream->fd = fd;
}
diff --git a/nuttx/lib/stdio/lib_stdoutstream.c b/nuttx/lib/stdio/lib_stdoutstream.c
index 272a93309..99fae11b2 100644
--- a/nuttx/lib/stdio/lib_stdoutstream.c
+++ b/nuttx/lib/stdio/lib_stdoutstream.c
@@ -60,6 +60,18 @@ static void stdoutstream_putc(FAR struct lib_outstream_s *this, int ch)
}
/****************************************************************************
+ * Name: stdoutstream_flush
+ ****************************************************************************/
+
+#if defined(CONFIG_STDIO_LINEBUFFER) && CONFIG_STDIO_BUFFER_SIZE > 0
+int stdoutstream_flush(FAR struct lib_outstream_s *this)
+{
+ FAR struct lib_stdoutstream_s *sthis = (FAR struct lib_stdoutstream_s *)this;
+ return lib_fflush(sthis->stream, true);
+}
+#endif
+
+/****************************************************************************
* Public Functions
****************************************************************************/
@@ -83,9 +95,16 @@ static void stdoutstream_putc(FAR struct lib_outstream_s *this, int ch)
void lib_stdoutstream(FAR struct lib_stdoutstream_s *stdoutstream,
FAR FILE *stream)
{
- stdoutstream->public.put = stdoutstream_putc;
- stdoutstream->public.nput = 0;
- stdoutstream->stream = stream;
+ stdoutstream->public.put = stdoutstream_putc;
+#ifdef CONFIG_STDIO_LINEBUFFER
+#if CONFIG_STDIO_BUFFER_SIZE > 0
+ stdoutstream->public.flush = stdoutstream_flush;
+#else
+ stdoutstream->public.flush = lib_noflush;
+#endif
+#endif
+ stdoutstream->public.nput = 0;
+ stdoutstream->stream = stream;
}