summaryrefslogtreecommitdiff
path: root/nuttx/lib/stdio/lib_puts.c
diff options
context:
space:
mode:
Diffstat (limited to 'nuttx/lib/stdio/lib_puts.c')
-rw-r--r--nuttx/lib/stdio/lib_puts.c25
1 files changed, 20 insertions, 5 deletions
diff --git a/nuttx/lib/stdio/lib_puts.c b/nuttx/lib/stdio/lib_puts.c
index 5e651c4de..e8cb186f6 100644
--- a/nuttx/lib/stdio/lib_puts.c
+++ b/nuttx/lib/stdio/lib_puts.c
@@ -84,31 +84,46 @@
* Name: puts
*
* Description:
- * puts() writes the string s and a trailing newline to
- * stdout.
+ * puts() writes the string s and a trailing newline to stdout.
+ *
****************************************************************************/
int puts(FAR const char *s)
{
+ FILE *stream = stdout;
int nwritten;
int nput = EOF;
/* Write the string (the next two steps must be atomic) */
- lib_take_semaphore(stdout);
+ lib_take_semaphore(stream);
/* Write the string without its trailing '\0' */
- nwritten = fputs(s, stdout);
+ nwritten = fputs(s, stream);
if (nwritten > 0)
{
/* Followed by a newline */
+
char newline = '\n';
- if (lib_fwrite(&newline, 1, stdout) > 0)
+ if (lib_fwrite(&newline, 1, stream) > 0)
{
nput = nwritten + 1;
+
+ /* Flush the buffer after the newline is output */
+
+#ifdef CONFIG_STDIO_LINEBUFFER
+ {
+ int ret = lib_fflush(stream, true);
+ if (ret < 0)
+ {
+ nput = EOF;
+ }
+ }
+#endif
}
}
+
lib_give_semaphore(stdout);
return nput;
}