aboutsummaryrefslogtreecommitdiff
path: root/nuttx/lib/stdio/lib_libfflush.c
diff options
context:
space:
mode:
authorpatacongo <patacongo@7fd9a85b-ad96-42d3-883c-3090e2eb8679>2012-08-31 16:03:17 +0000
committerpatacongo <patacongo@7fd9a85b-ad96-42d3-883c-3090e2eb8679>2012-08-31 16:03:17 +0000
commit035e89e554edf6d06736b1734b128e47164a4487 (patch)
tree537932021fc6c676eda7c25f66198886eab9de5b /nuttx/lib/stdio/lib_libfflush.c
parentb121fbbb00aa877caef26e5ffb14b3687d36827f (diff)
downloadpx4-firmware-035e89e554edf6d06736b1734b128e47164a4487.tar.gz
px4-firmware-035e89e554edf6d06736b1734b128e47164a4487.tar.bz2
px4-firmware-035e89e554edf6d06736b1734b128e47164a4487.zip
Fix some places in library where semaphore is not released on error conditions
git-svn-id: https://nuttx.svn.sourceforge.net/svnroot/nuttx/trunk@5071 7fd9a85b-ad96-42d3-883c-3090e2eb8679
Diffstat (limited to 'nuttx/lib/stdio/lib_libfflush.c')
-rw-r--r--nuttx/lib/stdio/lib_libfflush.c19
1 files changed, 13 insertions, 6 deletions
diff --git a/nuttx/lib/stdio/lib_libfflush.c b/nuttx/lib/stdio/lib_libfflush.c
index fb5a8768e..c2b887b2e 100644
--- a/nuttx/lib/stdio/lib_libfflush.c
+++ b/nuttx/lib/stdio/lib_libfflush.c
@@ -98,8 +98,8 @@
* bforce - flush must be complete.
*
* Return:
- * ERROR on failure, otherwise the number of bytes remaining in the buffer.
- * If bforce is set, then only the values ERROR and 0 will be returned.
+ * A negated errno value on failure, otherwise the number of bytes remaining
+ * in the buffer.
*
****************************************************************************/
@@ -109,13 +109,13 @@ ssize_t lib_fflush(FAR FILE *stream, bool bforce)
FAR const unsigned char *src;
ssize_t bytes_written;
ssize_t nbuffer;
+ int ret;
/* Return EBADF if the file is not opened for writing */
if (stream->fs_filedes < 0 || (stream->fs_oflags & O_WROK) == 0)
{
- set_errno(EBADF);
- return ERROR;
+ return -EBADF;
}
/* Make sure that we have exclusive access to the stream */
@@ -132,8 +132,11 @@ ssize_t lib_fflush(FAR FILE *stream, bool bforce)
if (stream->fs_bufread != stream->fs_bufstart)
{
- /* The buffer holds read data... just return zero */
+ /* The buffer holds read data... just return zero meaning "no bytes
+ * remaining in the buffer."
+ */
+ lib_give_semaphore(stream);
return 0;
}
@@ -151,8 +154,12 @@ ssize_t lib_fflush(FAR FILE *stream, bool bforce)
bytes_written = write(stream->fs_filedes, src, nbuffer);
if (bytes_written < 0)
{
+ /* Write failed. The cause of the failure is in 'errno'.
+ * returned the negated errno value.
+ */
+
lib_give_semaphore(stream);
- return ERROR;
+ return -get_errno();
}
/* Handle partial writes. fflush() must either return with