filedesc

Crates.iofiledesc
lib.rsfiledesc
version0.6.3
sourcesrc
created_at2020-06-27 13:58:58.476986
updated_at2023-09-20 17:35:41.481959
descriptionthin wrapper around raw file descriptors
homepage
repositoryhttps://github.com/de-vri-es/filedesc-rs
max_upload_size
id258791
size17,531
Maarten de Vries (de-vri-es)

documentation

https://docs.rs/filedesc

README

filedesc docs tests

This crate exposes a single type: FileDesc, which acts as a thin wrapper around open file descriptors. The wrapped file descriptor is closed when the wrapper is dropped.

You can call FileDesc::new() with any type that implements IntoRawFd, or duplicate the file descriptor of a type that implements AsRawFd with duplicate_from, or directly from a raw file descriptor with from_raw_fd() and duplicate_raw_fd(). Wrapped file descriptors can also be duplicated with the duplicate() function.

Close-on-exec

Whenever the library duplicates a file descriptor, it tries to set the close-on-exec flag atomically. On platforms where this is not supported, the library falls back to setting the flag non-atomically. When an existing file descriptor is wrapped, the close-on-exec flag is left as it was.

You can also check or set the close-on-exec flag with the get_close_on_exec() and set_close_on_exec functions.

Example

use filedesc::FileDesc;
let fd = unsafe { FileDesc::from_raw_fd(raw_fd) };
let duplicated = unsafe { fd.duplicate()? };
assert_eq!(duplicated.get_close_on_exec()?, true);

duplicated.set_close_on_exec(false)?;
assert_eq!(duplicated.get_close_on_exec()?, false);
Commit count: 28

cargo fmt