From a68fa997f5b1e7992bd57f33dd1b5473a88ba131 Mon Sep 17 00:00:00 2001 From: patacongo Date: Sun, 15 May 2011 14:45:13 +0000 Subject: More PIC32 header files git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@3611 42af7a65-404d-4744-a932-0658087f49c3 --- nuttx/lib/stdio/lib_fputs.c | 60 ++++++++++++++++++++++++++++----------------- 1 file changed, 38 insertions(+), 22 deletions(-) (limited to 'nuttx/lib/stdio') 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 -- cgit v1.2.3