fcntl 0.1.0

Wrapper around fcntl (2) and convenience methods to make interacting with it easier.
Documentation
  • Coverage
  • 95.65%
    22 out of 23 items documented4 out of 12 items with examples
  • Size
  • Source code size: 28.47 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 1.35 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Links
  • BafDyce/fcntl-rs
    0 0 1
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • BafDyce

fcntl-rs

Wrapper around fcntl (2) and convenience methods to make interacting with it easier. Currently only supports commands related to Advisory record locking.

Usage

Cargo.toml

[dependencies]
fcntl = "0.1"
use std::fs::OpenOptions;
use fcntl::{is_file_locked, lock_file, unlock_file};

// Open file
let file = OpenOptions::new().read(true).open("my.lock").unwrap();

// Check whether any process is currently holding a lock
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),
}


// Attempt to acquire a lock
match lock_file(&file, None, Some(FcntlLockType::Write)) {
    Ok(true) => println!("Lock acquired!"),
    Ok(false) => println!("Could not acquire lock!"),
    Err(err) => println!("Error: {:?}", err),
}


// Release lock again
match unlock_file(&file, None) {
    Ok(true) => println!("Lock successfully release"),
    Ok(false) => println!("Failed to release lock"),
    Err(err) => println!("Error: {:?}", err),
}

License

MIT OR Apache-2.0