/// Acquires and releases a file lock.
///
/// # Safety
///
/// When used to unlock, this does not guarantee that an exclusive lock is
/// already held.
Acquires and releases a file lock.
Acquires and releases a file lock .
pub unsafe fn raw_file_lock(
    f: &File,
    lock: Option<Lock>,
    off: usize,
    len: usize,
    wait: bool,
) -> io::Result<()> {
    if len == 0 {
        return Err(ErrorKind::InvalidInput.into());
    }
    let op = match wait {
        true => F_SETLKW,
        false => F_SETLK,
    };
    let lock = libc::flock {
        l_start: off as off_t,
        l_len: len as off_t,
        l_pid: 0,
        l_type: match lock {
            Some(Lock::Shared) => F_RDLCK as c_short,
            Some(Lock::Exclusive) => F_WRLCK as c_short,
            None => F_UNLCK as c_short,
        },
        l_whence: SEEK_SET as c_short,
        #[cfg(any(target_os = "freebsd", target_os = "solaris", target_os = "illumos"))]
        l_sysid: 0,
        #[cfg(any(target_os = "solaris", target_os = "illumos"))]
        l_pad: [0; 4],
    };
    loop {
        let rc = fcntl(f.as_raw_fd(), op, &lock);
        if rc == -1 {
            let err = Error::last_os_error();
            if err.kind() != ErrorKind::Interrupted {
                break Err(err);
            }
        } else {
            break Ok(());
        }
    }
}
pub unsafe fn raw_file_lock ( f : & File , lock : Option < Lock > , off : usize , len : usize , wait : bool , ) -> io :: Result < ( ) > { if len == 0 { return Err ( ErrorKind :: InvalidInput . into ( ) ) ; } let op = match wait { true => F_SETLKW , false => F_SETLK , } ; let lock = libc :: flock { l_start : off as off_t , l_len : len as off_t , l_pid : 0 , l_type : match lock { Some ( Lock :: Shared ) => F_RDLCK as c_short , Some ( Lock :: Exclusive ) => F_WRLCK as c_short , None => F_UNLCK as c_short , } , l_whence : SEEK_SET as c_short , # [ cfg ( any ( target_os " " target_os " " target_os " " ) ) ] l_sysid : 0 , # [ cfg ( any ( target_os " " target_os " " ) ) ] l_pad : [ 0 ; 4 ] , } ; loop { let rc = fcntl ( f . as_raw_fd ( ) , op , & lock ) ; if rc == - 1 { let err = Error :: last_os_error ( ) ; if err . kind ( ) != ErrorKind :: Interrupted { break Err ( err ) ; } } else { break Ok ( ( ) ) ; } } }
Acquires and releases a file lock.
Acquires and releases a file lock .
f
&File
lock
Option<Lock>
off
usize
len
usize
wait
bool
safety
When used to unlock, this does not guarantee that an exclusive lock is
already held.
When used to unlock this does not guarantee that an exclusive lock is already held .