diff options
author | patacongo <patacongo@7fd9a85b-ad96-42d3-883c-3090e2eb8679> | 2012-08-31 16:03:17 +0000 |
---|---|---|
committer | patacongo <patacongo@7fd9a85b-ad96-42d3-883c-3090e2eb8679> | 2012-08-31 16:03:17 +0000 |
commit | 035e89e554edf6d06736b1734b128e47164a4487 (patch) | |
tree | 537932021fc6c676eda7c25f66198886eab9de5b /nuttx/lib/stdio/lib_fflush.c | |
parent | b121fbbb00aa877caef26e5ffb14b3687d36827f (diff) | |
download | px4-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_fflush.c')
-rw-r--r-- | nuttx/lib/stdio/lib_fflush.c | 24 |
1 files changed, 19 insertions, 5 deletions
diff --git a/nuttx/lib/stdio/lib_fflush.c b/nuttx/lib/stdio/lib_fflush.c index e0278d0d2..d0b5e0185 100644 --- a/nuttx/lib/stdio/lib_fflush.c +++ b/nuttx/lib/stdio/lib_fflush.c @@ -2,7 +2,7 @@ * lib/stdio/lib_fflush.c * * Copyright (C) 2007-2009, 2011 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt <spudmonkey@racsa.co.cr> + * Author: Gregory Nutt <gnutt@nuttx.org> * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -97,22 +97,36 @@ int fflush(FAR FILE *stream) { + int ret; + /* Is the stream argument NULL? */ if (!stream) { /* Yes... then this is a request to flush all streams */ - return lib_flushall(sched_getstreams()); + ret = lib_flushall(sched_getstreams()); + } + else + { + ret = lib_fflush(stream, true); } - else if (lib_fflush(stream, true) != 0) + + /* Check the return value */ + + if (ret < 0) { - /* An error occurred during the flush AND/OR we were unable to flush all - * of the buffered write data. Return EOF on failure. + /* An error occurred during the flush AND/OR we were unable to flush + * all of the buffered write data. Set the errno value. */ + set_errno(-ret); + + /* And return EOF on failure. */ + return EOF; } + return OK; } |