relibc/header/sys_file/mod.rs
1//! `sys/file.h` implementation.
2//!
3//! Non-POSIX, see <https://man7.org/linux/man-pages/man2/flock.2.html>.
4
5use crate::{
6 error::ResultExt,
7 platform::{Pal, Sys, types::c_int},
8};
9
10/// Place a shared lock.
11pub const LOCK_SH: c_int = 1;
12/// Place an exclusive lock.
13pub const LOCK_EX: c_int = 2;
14/// To make a nonblocking request, include `LOCK_NB` (by ORing) with any of
15/// `LOCK_SH`, `LOCK_EX` and `LOCK_UN`.
16pub const LOCK_NB: c_int = 4;
17/// Remove an existing lock held by this process.
18pub const LOCK_UN: c_int = 8;
19
20pub const L_SET: c_int = 0;
21pub const L_INCR: c_int = 1;
22pub const L_XTND: c_int = 2;
23
24/// See <https://man7.org/linux/man-pages/man2/flock.2.html>.
25///
26/// Apply or remove an advisory lock on an open file.
27#[unsafe(no_mangle)]
28pub extern "C" fn flock(fd: c_int, operation: c_int) -> c_int {
29 Sys::flock(fd, operation).map(|()| 0).or_minus_one_errno()
30}