summaryrefslogtreecommitdiff
path: root/nuttx/lib/lib_wrflush.c
diff options
context:
space:
mode:
authorpatacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3>2008-02-06 01:29:23 +0000
committerpatacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3>2008-02-06 01:29:23 +0000
commita26dad80f4d004a4a0f6effedc803b3902389b39 (patch)
tree419248121e228b55362eb1b9b2b98a85e3d96c4c /nuttx/lib/lib_wrflush.c
parentc58518aeb7694de1e53d17f228cb84c401e82bb4 (diff)
downloadpx4-nuttx-a26dad80f4d004a4a0f6effedc803b3902389b39.tar.gz
px4-nuttx-a26dad80f4d004a4a0f6effedc803b3902389b39.tar.bz2
px4-nuttx-a26dad80f4d004a4a0f6effedc803b3902389b39.zip
fflush(NULL) returns error
git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@636 42af7a65-404d-4744-a932-0658087f49c3
Diffstat (limited to 'nuttx/lib/lib_wrflush.c')
-rw-r--r--nuttx/lib/lib_wrflush.c35
1 files changed, 22 insertions, 13 deletions
diff --git a/nuttx/lib/lib_wrflush.c b/nuttx/lib/lib_wrflush.c
index cc2f65543..73e24afec 100644
--- a/nuttx/lib/lib_wrflush.c
+++ b/nuttx/lib/lib_wrflush.c
@@ -1,5 +1,5 @@
/****************************************************************************
- * lib/lib_wrlush.c
+ * lib/lib_wrflush.c
*
* Copyright (C) 2008 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
@@ -90,22 +90,31 @@
*
****************************************************************************/
-/****************************************************************************
- * Name: lib_wrflush
- ****************************************************************************/
-
int lib_wrflush(FILE *stream)
{
-#if CONFIG_STDIO_BUFFER_SIZE > 0
- /* Verify that the stream is opened for writing... flush will return an
- * error if it is called for a stream that is not opened for writing.
- */
+ /* Verify that we were passed a valid (i.e., non-NULL) stream */
- if (stream && (stream->fs_oflags & O_WROK) != 0)
+#if CONFIG_STDIO_BUFFER_SIZE > 0
+ if (stream)
{
- return fflush(stream);
+ /* Verify that the stream is opened for writing... lib_fflush will
+ * return an error if it is called for a stream that is not opened for
+ * writing.
+ */
+
+ if ((stream->fs_oflags & O_WROK) == 0 ||
+ lib_fflush(stream, TRUE) == 0)
+ {
+ /* Return success if there is no buffered write data -- i.e., that
+ * the stream is not opened for writing or, if it is, that all of
+ * the buffered write data was successfully flushed.
+ */
+
+ return OK;
+ }
}
+ return ERROR;
+#else
+ return stream ? OK : ERROR;
#endif
- return OK;
}
-