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:
Miguel Herranz
2022-04-25 18:13:41 +02:00
committed by Xiang Xiao
parent 19d1e08717
commit 819ebe7356
19 changed files with 57 additions and 69 deletions
+3 -3
View File
@@ -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