Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/coreyja/fcntl-rs
Fork of https://gitlab.com/BafDyce/fcntl-rs
https://github.com/coreyja/fcntl-rs
Last synced: 16 days ago
JSON representation
Fork of https://gitlab.com/BafDyce/fcntl-rs
- Host: GitHub
- URL: https://github.com/coreyja/fcntl-rs
- Owner: coreyja
- License: apache-2.0
- Created: 2023-09-24T00:11:23.000Z (about 1 year ago)
- Default Branch: ca/main/work-on-macos
- Last Pushed: 2023-10-01T16:27:35.000Z (about 1 year ago)
- Last Synced: 2024-10-19T11:52:49.407Z (2 months ago)
- Language: Rust
- Homepage:
- Size: 15.6 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE-APACHE
Awesome Lists containing this project
README
# Fork of https://gitlab.com/BafDyce/fcntl-rs
# fcntl-rs
> Wrapper around [fcntl (2)](https://www.man7.org/linux/man-pages/man2/fcntl.2.html) and convenience methods to make
> interacting with it easier. Currently only supports commands related to Advisory record locking.- [Documentation](https://docs.rs/fcntl)
- [Crates.io](https://crates.io/crates/fcntl)
- [Source Code](https://gitlab.com/BafDyce/fcntl-rs)## Usage
`Cargo.toml`
```toml
[dependencies]
fcntl = "0.1"
``````rust
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](./LICENSE-MIT) OR [Apache-2.0](./LICENSE-APACHE)