Disable line buffering if the file is opened in binary mode; Also fix a couple of fopen/fdopen bugs

git-svn-id: https://nuttx.svn.sourceforge.net/svnroot/nuttx/trunk@4630 7fd9a85b-ad96-42d3-883c-3090e2eb8679
This commit is contained in:
patacongo
2012-04-18 15:57:45 +00:00
parent 2e53a5cf45
commit 6aa752b338
16 changed files with 261 additions and 102 deletions
+23 -3
View File
@@ -37,6 +37,8 @@
* Included Files
****************************************************************************/
#include <fcntl.h>
#include "lib_internal.h"
/****************************************************************************
@@ -95,14 +97,32 @@ int stdoutstream_flush(FAR struct lib_outstream_s *this)
void lib_stdoutstream(FAR struct lib_stdoutstream_s *stdoutstream,
FAR FILE *stream)
{
/* Select the put operation */
stdoutstream->public.put = stdoutstream_putc;
/* Select the correct flush operation. This flush is only called when
* a newline is encountered in the output stream. However, we do not
* want to support this line buffering behavior if the stream was
* opened in binary mode. In binary mode, the newline has no special
* meaning.
*/
#ifdef CONFIG_STDIO_LINEBUFFER
#if CONFIG_STDIO_BUFFER_SIZE > 0
stdoutstream->public.flush = stdoutstream_flush;
#else
stdoutstream->public.flush = lib_noflush;
if ((stream->fs_oflags & O_BINARY) == 0)
{
stdoutstream->public.flush = stdoutstream_flush;
}
else
#endif
{
stdoutstream->public.flush = lib_noflush;
}
#endif
/* Set the number of bytes put to zero and remember the stream */
stdoutstream->public.nput = 0;
stdoutstream->stream = stream;
}