[−][src]Function fcntl::is_file_locked
pub fn is_file_locked<'a, RF>(
fd: &'a RF,
flock: Option<flock>
) -> Result<bool, FcntlError> where
RF: AsRawFd,
Checks whether the given file is locked.
The caller is responsible that fd
was opened with the appropriate parameters, as stated by
fcntl (2):
In order to place a read lock,
fd
must be open for reading. In order to place a write lock,fd
must be open for writing. To place both types of lock, open a file read-write.
use std::fs::OpenOptions; use fcntl::is_file_locked; let file = OpenOptions::new().read(true).open(file_name).unwrap(); match is_file_locked(&file, None) { Ok(true) => println!("File is currently locked"), Ok(false) => println!("File is not locked"), Err(err) => println!("Error: {:?}", err), }