summaryrefslogtreecommitdiff
path: root/nuttx/lib/stdio
diff options
context:
space:
mode:
authorpatacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3>2011-05-15 14:45:13 +0000
committerpatacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3>2011-05-15 14:45:13 +0000
commita68fa997f5b1e7992bd57f33dd1b5473a88ba131 (patch)
treed8dce94f2155a3eadcc545068c44e557deff99e6 /nuttx/lib/stdio
parentb22d2aebfcb239ad078eb9dfff9c069b0ab94217 (diff)
downloadpx4-nuttx-a68fa997f5b1e7992bd57f33dd1b5473a88ba131.tar.gz
px4-nuttx-a68fa997f5b1e7992bd57f33dd1b5473a88ba131.tar.bz2
px4-nuttx-a68fa997f5b1e7992bd57f33dd1b5473a88ba131.zip
More PIC32 header files
git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@3611 42af7a65-404d-4744-a932-0658087f49c3
Diffstat (limited to 'nuttx/lib/stdio')
-rw-r--r--nuttx/lib/stdio/lib_fputs.c60
1 files changed, 38 insertions, 22 deletions
diff --git a/nuttx/lib/stdio/lib_fputs.c b/nuttx/lib/stdio/lib_fputs.c
index ddb548925..57efba5dc 100644
--- a/nuttx/lib/stdio/lib_fputs.c
+++ b/nuttx/lib/stdio/lib_fputs.c
@@ -84,15 +84,15 @@
/****************************************************************************
* Name: fputs
+ *
+ * Description:
+ * fputs() writes the string s to stream, without its trailing '\0'.
+ *
****************************************************************************/
-/* fputs() writes the string s to stream, without its
- * trailing '\0'.
- */
-
+#ifdef CONFIG_STDIO_LINEBUFFER
int fputs(FAR const char *s, FAR FILE *stream)
{
- int ntowrite;
int nput;
int ret;
@@ -106,27 +106,19 @@ int fputs(FAR const char *s, FAR FILE *stream)
}
#endif
- /* Get the length of the string. */
+ /* Write the string. Loop until the null terminator is encountered */
- ntowrite = strlen(s);
- if (ntowrite == 0)
+ for (nput = 0; *s; nput++, s++)
{
- return 0;
- }
-
- /* Write the string */
+ /* Write the next character to the stream buffer */
-#ifdef CONFIG_STDIO_LINEBUFFER
- nput = ntowrite;
- while (ntowrite-- > 0)
- {
ret = lib_fwrite(s, 1, stream);
if (ret <= 0)
{
return EOF;
}
- /* Flush the buffer if a newline was put to the buffer */
+ /* Flush the buffer if a newline was writen to the buffer */
if (*s == '\n')
{
@@ -136,19 +128,43 @@ int fputs(FAR const char *s, FAR FILE *stream)
return EOF;
}
}
-
- /* Set up for the next lib_fwrite() */
-
- s++;
}
return nput;
+}
+
#else
+int fputs(FAR const char *s, FAR FILE *stream)
+{
+ int ntowrite;
+ int nput;
+ int ret;
+
+ /* Make sure that a string was provided. */
+
+#ifdef CONFIG_DEBUG /* Most parameter checking is disabled if DEBUG is off */
+ if (!s)
+ {
+ set_errno(EINVAL);
+ return EOF;
+ }
+#endif
+
+ /* Get the length of the string. */
+
+ ntowrite = strlen(s);
+ if (ntowrite == 0)
+ {
+ return 0;
+ }
+
+ /* Write the string */
+
nput = lib_fwrite(s, ntowrite, stream);
if (nput < 0)
{
return EOF
}
return nput;
-#endif
}
+#endif \ No newline at end of file