summaryrefslogtreecommitdiff
path: root/lib/libc/stdio/ftrylockfile.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/libc/stdio/ftrylockfile.c')
-rw-r--r--lib/libc/stdio/ftrylockfile.c11
1 files changed, 11 insertions, 0 deletions
diff --git a/lib/libc/stdio/ftrylockfile.c b/lib/libc/stdio/ftrylockfile.c
new file mode 100644
index 00000000..b8f89e4b
--- /dev/null
+++ b/lib/libc/stdio/ftrylockfile.c
@@ -0,0 +1,11 @@
+#include <__stdio.h>
+#include <atomic.h>
+#include <stdio.h>
+
+int ftrylockfile(FILE *file)
+{
+ if (file == NULL)
+ return -1;
+
+ return atomic_flag_test_and_set_explicit(&file->lock, memory_order_acquire) ? 1 : 0;
+}