mirror of
https://github.com/apache/nuttx.git
synced 2026-05-27 03:05:40 +08:00
libc/stdio: Add stdio file locking functions
Add flockfile(), ftrylockfile() and funlockfile() functions [1].
[1] POSIX.1-2008 / System Interfaces / flockfile
https://pubs.opengroup.org/onlinepubs/9699919799.2008edition/functions/flockfile.html
Signed-off-by: Miguel Herranz <miguel@midokura.com>
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
This commit is contained in:
committed by
Xiang Xiao
parent
19d1e08717
commit
819ebe7356
@@ -73,7 +73,7 @@ ssize_t lib_fflush(FAR FILE *stream, bool bforce)
|
||||
|
||||
/* Make sure that we have exclusive access to the stream */
|
||||
|
||||
lib_take_lock(stream);
|
||||
flockfile(stream);
|
||||
|
||||
/* Check if there is an allocated I/O buffer */
|
||||
|
||||
@@ -156,11 +156,11 @@ ssize_t lib_fflush(FAR FILE *stream, bool bforce)
|
||||
* remaining in the buffer.
|
||||
*/
|
||||
|
||||
lib_give_lock(stream);
|
||||
funlockfile(stream);
|
||||
return stream->fs_bufpos - stream->fs_bufstart;
|
||||
|
||||
errout_with_lock:
|
||||
lib_give_lock(stream);
|
||||
funlockfile(stream);
|
||||
return ret;
|
||||
|
||||
#else
|
||||
|
||||
Reference in New Issue
Block a user