diff options
author | patacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3> | 2011-05-14 17:37:47 +0000 |
---|---|---|
committer | patacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3> | 2011-05-14 17:37:47 +0000 |
commit | 18615da8957c23faa4924b2d1b3d222a28db9db8 (patch) | |
tree | fdd388cc6fa54c5a3cc7702b5128b7ca3cf5325a /nuttx/lib/stdio/lib_puts.c | |
parent | f62084035feaf8b9a22804821b22e2a3c15e6eda (diff) | |
download | px4-nuttx-18615da8957c23faa4924b2d1b3d222a28db9db8.tar.gz px4-nuttx-18615da8957c23faa4924b2d1b3d222a28db9db8.tar.bz2 px4-nuttx-18615da8957c23faa4924b2d1b3d222a28db9db8.zip |
Flush buffer after newline in putc, fputc, and puts (but not fputs)
git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@3607 42af7a65-404d-4744-a932-0658087f49c3
Diffstat (limited to 'nuttx/lib/stdio/lib_puts.c')
-rw-r--r-- | nuttx/lib/stdio/lib_puts.c | 25 |
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; } |