summaryrefslogtreecommitdiff
path: root/nuttx/lib
diff options
context:
space:
mode:
Diffstat (limited to 'nuttx/lib')
-rw-r--r--nuttx/lib/stdio/lib_libfwrite.c2
-rw-r--r--nuttx/lib/stdio/lib_lowinstream.c17
-rw-r--r--nuttx/lib/stdio/lib_lowoutstream.c5
-rw-r--r--nuttx/lib/stdio/lib_meminstream.c13
-rw-r--r--nuttx/lib/stdio/lib_memoutstream.c6
-rw-r--r--nuttx/lib/stdio/lib_nullinstream.c5
-rw-r--r--nuttx/lib/stdio/lib_nulloutstream.c3
-rw-r--r--nuttx/lib/stdio/lib_rawinstream.c34
-rw-r--r--nuttx/lib/stdio/lib_rawoutstream.c29
-rw-r--r--nuttx/lib/stdio/lib_stdinstream.c25
-rw-r--r--nuttx/lib/stdio/lib_stdoutstream.c24
-rw-r--r--nuttx/lib/stdio/lib_syslogstream.c30
12 files changed, 141 insertions, 52 deletions
diff --git a/nuttx/lib/stdio/lib_libfwrite.c b/nuttx/lib/stdio/lib_libfwrite.c
index e2c35e3e9..e71866b49 100644
--- a/nuttx/lib/stdio/lib_libfwrite.c
+++ b/nuttx/lib/stdio/lib_libfwrite.c
@@ -2,7 +2,7 @@
* lib/stdio/lib_libfwrite.c
*
* Copyright (C) 2007-2009, 2011 Gregory Nutt. All rights reserved.
- * Author: Gregory Nutt <spudmonkey@racsa.co.cr>
+ * Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
diff --git a/nuttx/lib/stdio/lib_lowinstream.c b/nuttx/lib/stdio/lib_lowinstream.c
index 6dcc4a37e..c97a4721f 100644
--- a/nuttx/lib/stdio/lib_lowinstream.c
+++ b/nuttx/lib/stdio/lib_lowinstream.c
@@ -1,8 +1,8 @@
/****************************************************************************
* lib/stdio/lib_lowinstream.c
*
- * Copyright (C) 2007-2009, 2011 Gregory Nutt. All rights reserved.
- * Author: Gregory Nutt <spudmonkey@racsa.co.cr>
+ * Copyright (C) 2007-2009, 2011-2012 Gregory Nutt. All rights reserved.
+ * Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -42,7 +42,9 @@
#ifdef CONFIG_ARCH_LOWGETC
#include <stdio.h>
+#include <assert.h>
#include <errno.h>
+
#include <nuttx/arch.h>
#include "lib_internal.h"
@@ -57,10 +59,19 @@
static int lowinstream_getc(FAR struct lib_instream_s *this)
{
- if (this && up_getc(ch) != EOF)
+ int ret;
+
+ DEBUGASSERT(this);
+
+ /* Get the next character from the incoming stream */
+
+ ret = up_getc(ch)
+ if (ret != EOF)
{
this->nget++;
}
+
+ return ret;
}
/****************************************************************************
diff --git a/nuttx/lib/stdio/lib_lowoutstream.c b/nuttx/lib/stdio/lib_lowoutstream.c
index 726bd84d7..092f39ca2 100644
--- a/nuttx/lib/stdio/lib_lowoutstream.c
+++ b/nuttx/lib/stdio/lib_lowoutstream.c
@@ -42,6 +42,7 @@
#ifdef CONFIG_ARCH_LOWPUTC
#include <stdio.h>
+#include <assert.h>
#include <errno.h>
#include <nuttx/arch.h>
@@ -57,7 +58,9 @@
static void lowoutstream_putc(FAR struct lib_outstream_s *this, int ch)
{
- if (this && up_putc(ch) != EOF)
+ DEBUGASSERT(this);
+
+ if (up_putc(ch) != EOF)
{
this->nput++;
}
diff --git a/nuttx/lib/stdio/lib_meminstream.c b/nuttx/lib/stdio/lib_meminstream.c
index 839e56219..a842096fb 100644
--- a/nuttx/lib/stdio/lib_meminstream.c
+++ b/nuttx/lib/stdio/lib_meminstream.c
@@ -1,8 +1,8 @@
/****************************************************************************
* lib/stdio/lib_meminstream.c
*
- * Copyright (C) 2007-2009, 2011 Gregory Nutt. All rights reserved.
- * Author: Gregory Nutt <spudmonkey@racsa.co.cr>
+ * Copyright (C) 2007-2009, 2011-2012 Gregory Nutt. All rights reserved.
+ * Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -37,6 +37,8 @@
* Included Files
****************************************************************************/
+#include <assert.h>
+
#include "lib_internal.h"
/****************************************************************************
@@ -52,7 +54,11 @@ static int meminstream_getc(FAR struct lib_instream_s *this)
FAR struct lib_meminstream_s *mthis = (FAR struct lib_meminstream_s *)this;
int ret;
- if (this && this->nget < mthis->buflen)
+ DEBUGASSERT(this);
+
+ /* Get the next character (if any) from the buffer */
+
+ if (this->nget < mthis->buflen)
{
ret = mthis->buffer[this->nget];
this->nget++;
@@ -61,6 +67,7 @@ static int meminstream_getc(FAR struct lib_instream_s *this)
{
ret = EOF;
}
+
return ret;
}
diff --git a/nuttx/lib/stdio/lib_memoutstream.c b/nuttx/lib/stdio/lib_memoutstream.c
index 007ab8976..21197358b 100644
--- a/nuttx/lib/stdio/lib_memoutstream.c
+++ b/nuttx/lib/stdio/lib_memoutstream.c
@@ -37,6 +37,8 @@
* Included Files
****************************************************************************/
+#include <assert.h>
+
#include "lib_internal.h"
/****************************************************************************
@@ -51,12 +53,14 @@ static void memoutstream_putc(FAR struct lib_outstream_s *this, int ch)
{
FAR struct lib_memoutstream_s *mthis = (FAR struct lib_memoutstream_s *)this;
+ DEBUGASSERT(this);
+
/* If this will not overrun the buffer, then write the character to the
* buffer. Not that buflen was pre-decremented when the stream was
* created so it is okay to write past the end of the buflen by one.
*/
- if (this && this->nput < mthis->buflen)
+ if (this->nput < mthis->buflen)
{
mthis->buffer[this->nput] = ch;
this->nput++;
diff --git a/nuttx/lib/stdio/lib_nullinstream.c b/nuttx/lib/stdio/lib_nullinstream.c
index 271cba396..0eadb0a8e 100644
--- a/nuttx/lib/stdio/lib_nullinstream.c
+++ b/nuttx/lib/stdio/lib_nullinstream.c
@@ -1,8 +1,8 @@
/****************************************************************************
* lib/stdio/lib_nullinstream.c
*
- * Copyright (C) 2007-2009, 2011 Gregory Nutt. All rights reserved.
- * Author: Gregory Nutt <spudmonkey@racsa.co.cr>
+ * Copyright (C) 2007-2009, 2011-2012 Gregory Nutt. All rights reserved.
+ * Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -39,6 +39,7 @@
#include <stdio.h>
#include <errno.h>
+
#include "lib_internal.h"
/****************************************************************************
diff --git a/nuttx/lib/stdio/lib_nulloutstream.c b/nuttx/lib/stdio/lib_nulloutstream.c
index 520df459e..69878fd57 100644
--- a/nuttx/lib/stdio/lib_nulloutstream.c
+++ b/nuttx/lib/stdio/lib_nulloutstream.c
@@ -38,7 +38,9 @@
****************************************************************************/
#include <stdio.h>
+#include <assert.h>
#include <errno.h>
+
#include "lib_internal.h"
/****************************************************************************
@@ -47,6 +49,7 @@
static void nulloutstream_putc(FAR struct lib_outstream_s *this, int ch)
{
+ DEBUGASSERT(this);
this->nput++;
}
diff --git a/nuttx/lib/stdio/lib_rawinstream.c b/nuttx/lib/stdio/lib_rawinstream.c
index ead3116b4..aacc8f867 100644
--- a/nuttx/lib/stdio/lib_rawinstream.c
+++ b/nuttx/lib/stdio/lib_rawinstream.c
@@ -1,8 +1,8 @@
/****************************************************************************
* lib/stdio/lib_rawinstream.c
*
- * Copyright (C) 2007-2009, 2011 Gregory Nutt. All rights reserved.
- * Author: Gregory Nutt <spudmonkey@racsa.co.cr>
+ * Copyright (C) 2007-2009, 2011-2012 Gregory Nutt. All rights reserved.
+ * Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -38,7 +38,9 @@
****************************************************************************/
#include <unistd.h>
+#include <assert.h>
#include <errno.h>
+
#include "lib_internal.h"
/****************************************************************************
@@ -52,23 +54,27 @@
static int rawinstream_getc(FAR struct lib_instream_s *this)
{
FAR struct lib_rawinstream_s *rthis = (FAR struct lib_rawinstream_s *)this;
+ int nwritten;
char ch;
- if (this && rthis->fd >= 0)
+ DEBUGASSERT(this && rthis->fd >= 0);
+
+ /* Attempt to read one character */
+
+ nwritten = read(rthis->fd, &ch, 1);
+ if (nwritten == 1)
{
- int nwritten;
- do
- {
- nwritten = read(rthis->fd, &ch, 1);
- if (nwritten == 1)
- {
- this->nget++;
- return ch;
- }
- }
- while (nwritten < 0 && get_errno() == EINTR);
+ this->nget++;
+ return ch;
}
+ /* Return EOF on any failure to read from the incoming byte stream. The
+ * only expected error is EINTER meaning that the read was interrupted
+ * by a signal. A Zero return value would indicated an end-of-file
+ * confition.
+ */
+
+ DEBUGASSERT(nwritten == 0 || get_errno() == EINTR);
return EOF;
}
diff --git a/nuttx/lib/stdio/lib_rawoutstream.c b/nuttx/lib/stdio/lib_rawoutstream.c
index ce9d33280..b4a20958b 100644
--- a/nuttx/lib/stdio/lib_rawoutstream.c
+++ b/nuttx/lib/stdio/lib_rawoutstream.c
@@ -38,7 +38,9 @@
****************************************************************************/
#include <unistd.h>
+#include <assert.h>
#include <errno.h>
+
#include "lib_internal.h"
/****************************************************************************
@@ -52,19 +54,28 @@
static void rawoutstream_putc(FAR struct lib_outstream_s *this, int ch)
{
FAR struct lib_rawoutstream_s *rthis = (FAR struct lib_rawoutstream_s *)this;
+ int nwritten;
char buffer = ch;
- if (this && rthis->fd >= 0)
+
+ DEBUGASSERT(this && rthis->fd >= 0);
+
+ /* Loop until the character is successfully transferred */
+
+ for (;;)
{
- int nwritten;
- do
+ nwritten = write(rthis->fd, &buffer, 1);
+ if (nwritten == 1)
{
- nwritten = write(rthis->fd, &buffer, 1);
- if (nwritten == 1)
- {
- this->nput++;
- }
+ this->nput++;
+ return;
}
- while (nwritten < 0 && get_errno() == EINTR);
+
+ /* The only expected error is EINTR, meaning that the write operation
+ * was awakened by a signal. Zero would not be a valid return value
+ * either.
+ */
+
+ DEBUGASSERT(nwritten < 0 && get_errno() == EINTR);
}
}
diff --git a/nuttx/lib/stdio/lib_stdinstream.c b/nuttx/lib/stdio/lib_stdinstream.c
index d89b6b63a..77aab9ec8 100644
--- a/nuttx/lib/stdio/lib_stdinstream.c
+++ b/nuttx/lib/stdio/lib_stdinstream.c
@@ -1,8 +1,8 @@
/****************************************************************************
* lib/stdio/lib_stdinstream.c
*
- * Copyright (C) 2007-2009, 2011 Gregory Nutt. All rights reserved.
- * Author: Gregory Nutt <spudmonkey@racsa.co.cr>
+ * Copyright (C) 2007-2009, 2011-2012 Gregory Nutt. All rights reserved.
+ * Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -37,6 +37,8 @@
* Included Files
****************************************************************************/
+#include <assert.h>
+
#include "lib_internal.h"
/****************************************************************************
@@ -50,16 +52,19 @@
static int stdinstream_getc(FAR struct lib_instream_s *this)
{
FAR struct lib_stdinstream_s *sthis = (FAR struct lib_stdinstream_s *)this;
- if (this)
+ int ret;
+
+ DEBUGASSERT(this);
+
+ /* Get the next character from the incoming stream */
+
+ ret = getc(sthis->stream);
+ if (ret != EOF)
{
- int ret = getc(sthis->stream);
- if (ret != EOF)
- {
- this->nget++;
- }
- return ret;
+ this->nget++;
}
- return EOF;
+
+ return ret;
}
/****************************************************************************
diff --git a/nuttx/lib/stdio/lib_stdoutstream.c b/nuttx/lib/stdio/lib_stdoutstream.c
index 12e78ce53..b8dd0bf63 100644
--- a/nuttx/lib/stdio/lib_stdoutstream.c
+++ b/nuttx/lib/stdio/lib_stdoutstream.c
@@ -1,8 +1,8 @@
/****************************************************************************
* lib/stdio/lib_stdoutstream.c
*
- * Copyright (C) 2007-2009, 2011 Gregory Nutt. All rights reserved.
- * Author: Gregory Nutt <spudmonkey@racsa.co.cr>
+ * Copyright (C) 2007-2009, 2011-2012 Gregory Nutt. All rights reserved.
+ * Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -38,6 +38,8 @@
****************************************************************************/
#include <fcntl.h>
+#include <assert.h>
+#include <errno.h>
#include "lib_internal.h"
@@ -52,12 +54,26 @@
static void stdoutstream_putc(FAR struct lib_outstream_s *this, int ch)
{
FAR struct lib_stdoutstream_s *sthis = (FAR struct lib_stdoutstream_s *)this;
- if (this)
+ int result;
+
+ DEBUGASSERT(this && sthis->stream);
+
+ /* Loop until the character is successfully transferred */
+
+ for (;;)
{
- if (putc(ch, sthis->stream) != EOF)
+ result = fputc(ch, sthis->stream);
+ if (result != EOF)
{
this->nput++;
+ return;
}
+
+ /* EINTR (meaning that fputc was interrupted by a signal) is the only
+ * expected error.
+ */
+
+ DEBUGASSERT(get_errno() == EINTR);
}
}
diff --git a/nuttx/lib/stdio/lib_syslogstream.c b/nuttx/lib/stdio/lib_syslogstream.c
index 20c6165ca..1a47f6abb 100644
--- a/nuttx/lib/stdio/lib_syslogstream.c
+++ b/nuttx/lib/stdio/lib_syslogstream.c
@@ -40,6 +40,7 @@
#include <nuttx/config.h>
#include <unistd.h>
+#include <assert.h>
#include <errno.h>
#include <nuttx/syslog.h>
@@ -62,10 +63,31 @@
static void syslogstream_putc(FAR struct lib_outstream_s *this, int ch)
{
- /* Write the character to the supported logging device */
-
- (void)syslog_putc(ch);
- this->nput++;
+ int ret;
+
+ /* Try writing until the write was successful or until an irrecoverable
+ * error occurs.
+ */
+
+ for (;;)
+ {
+ /* Write the character to the supported logging device */
+
+ ret = syslog_putc(ch);
+ if (ret == OK)
+ {
+ this->nput++;
+ return;
+ }
+
+ /* On failure syslog_putc will return a negated errno value. The
+ * errno variable will not be set. The special value -EINTR means that
+ * syslog_putc() was awakened by a signal. This is not a real error and
+ * must be ignored in this context.
+ */
+
+ DEBUGASSERT(ret == -EINTR);
+ }
}
/****************************************************************************