mirror of
https://github.com/uutils/coreutils
synced 2024-11-16 17:58:06 +00:00
uucore::pipes: Expand documentation
This commit is contained in:
parent
23647be07a
commit
d6a8485115
1 changed files with 16 additions and 1 deletions
|
@ -10,6 +10,9 @@ use nix::{fcntl::SpliceFFlags, sys::uio::IoVec};
|
|||
pub use nix::{Error, Result};
|
||||
|
||||
/// A wrapper around [`nix::unistd::Pipe`] that ensures the pipe is cleaned up.
|
||||
///
|
||||
/// Returns two `File` objects: everything written to the second can be read
|
||||
/// from the first.
|
||||
pub fn pipe() -> Result<(File, File)> {
|
||||
let (read, write) = nix::unistd::pipe()?;
|
||||
// SAFETY: The file descriptors do not have other owners.
|
||||
|
@ -17,6 +20,14 @@ pub fn pipe() -> Result<(File, File)> {
|
|||
}
|
||||
|
||||
/// Less noisy wrapper around [`nix::fcntl::splice`].
|
||||
///
|
||||
/// Up to `len` bytes are moved from `source` to `target`. Returns the number
|
||||
/// of successfully moved bytes.
|
||||
///
|
||||
/// At least one of `source` and `target` must be some sort of pipe.
|
||||
/// To get around this requirement, consider splicing from your source into
|
||||
/// a [`pipe`] and then from the pipe into your target (with `splice_exact`):
|
||||
/// this is still very efficient.
|
||||
#[cfg(any(target_os = "linux", target_os = "android"))]
|
||||
pub fn splice(source: &impl AsRawFd, target: &impl AsRawFd, len: usize) -> Result<usize> {
|
||||
nix::fcntl::splice(
|
||||
|
@ -31,6 +42,8 @@ pub fn splice(source: &impl AsRawFd, target: &impl AsRawFd, len: usize) -> Resul
|
|||
|
||||
/// Splice wrapper which fully finishes the write.
|
||||
///
|
||||
/// Exactly `len` bytes are moved from `source` into `target`.
|
||||
///
|
||||
/// Panics if `source` runs out of data before `len` bytes have been moved.
|
||||
#[cfg(any(target_os = "linux", target_os = "android"))]
|
||||
pub fn splice_exact(source: &impl AsRawFd, target: &impl AsRawFd, len: usize) -> Result<()> {
|
||||
|
@ -43,7 +56,9 @@ pub fn splice_exact(source: &impl AsRawFd, target: &impl AsRawFd, len: usize) ->
|
|||
Ok(())
|
||||
}
|
||||
|
||||
/// Use vmsplice() to copy data from memory into a pipe.
|
||||
/// Copy data from `bytes` into `target`, which must be a pipe.
|
||||
///
|
||||
/// Returns the number of successfully copied bytes.
|
||||
#[cfg(any(target_os = "linux", target_os = "android"))]
|
||||
pub fn vmsplice(target: &impl AsRawFd, bytes: &[u8]) -> Result<usize> {
|
||||
nix::fcntl::vmsplice(
|
||||
|
|
Loading…
Reference in a new issue