Returns the current lock state using [`fcntl`] with respect to the given parameters. # Parameters - `file`: The file for which to get the lock state. - `granularity`: The [`LockGranularity`].
(
file: &Fd,
granularity: LockGranularity,
)
| 234 | /// - `file`: The file for which to get the lock state. |
| 235 | /// - `granularity`: The [`LockGranularity`]. |
| 236 | pub fn get_lock_state<Fd: AsRawFd>( |
| 237 | file: &Fd, |
| 238 | granularity: LockGranularity, |
| 239 | ) -> Result<LockState, LockError> { |
| 240 | let mut flock = get_flock(LockType::Write, granularity); |
| 241 | let res = fcntl(file.as_raw_fd(), FcntlArg::F_OFD_GETLK(&mut flock)); |
| 242 | match res { |
| 243 | 0 => { |
| 244 | let state = flock.l_type as libc::c_int; |
| 245 | let state = LockState::new(state); |
| 246 | Ok(state) |
| 247 | } |
| 248 | -1 => { |
| 249 | let io_error = io::Error::last_os_error(); |
| 250 | Err(LockError::Io(io_error)) |
| 251 | } |
| 252 | val => panic!("Unexpected return value from fcntl(): {val}"), |
| 253 | } |
| 254 | } |
no test coverage detected