mirror of
https://github.com/uutils/coreutils
synced 2024-11-10 07:04:16 +00:00
yes: adapt to API changes of uucore/pipes
This commit is contained in:
parent
563e3cefd0
commit
9fcf3ee48b
2 changed files with 11 additions and 3 deletions
|
@ -20,13 +20,19 @@
|
|||
//! make any effort to rescue data from the pipe if splice() fails, we can
|
||||
//! just fall back and start over from the beginning.
|
||||
|
||||
use std::{io, os::unix::io::AsRawFd};
|
||||
use std::{
|
||||
io,
|
||||
os::fd::{AsFd, AsRawFd},
|
||||
};
|
||||
|
||||
use nix::{errno::Errno, libc::S_IFIFO, sys::stat::fstat};
|
||||
|
||||
use uucore::pipes::{pipe, splice_exact, vmsplice};
|
||||
|
||||
pub(crate) fn splice_data(bytes: &[u8], out: &impl AsRawFd) -> Result<()> {
|
||||
pub(crate) fn splice_data<T>(bytes: &[u8], out: &T) -> Result<()>
|
||||
where
|
||||
T: AsRawFd + AsFd,
|
||||
{
|
||||
let is_pipe = fstat(out.as_raw_fd())?.st_mode as nix::libc::mode_t & S_IFIFO != 0;
|
||||
|
||||
if is_pipe {
|
||||
|
|
|
@ -9,6 +9,8 @@ use clap::{builder::ValueParser, crate_version, Arg, ArgAction, Command};
|
|||
use std::error::Error;
|
||||
use std::ffi::OsString;
|
||||
use std::io::{self, Write};
|
||||
#[cfg(any(target_os = "linux", target_os = "android"))]
|
||||
use std::os::fd::AsFd;
|
||||
use uucore::error::{UResult, USimpleError};
|
||||
#[cfg(unix)]
|
||||
use uucore::signals::enable_pipe_errors;
|
||||
|
@ -118,7 +120,7 @@ pub fn exec(bytes: &[u8]) -> io::Result<()> {
|
|||
|
||||
#[cfg(any(target_os = "linux", target_os = "android"))]
|
||||
{
|
||||
match splice::splice_data(bytes, &stdout) {
|
||||
match splice::splice_data(bytes, &stdout.as_fd()) {
|
||||
Ok(_) => return Ok(()),
|
||||
Err(splice::Error::Io(err)) => return Err(err),
|
||||
Err(splice::Error::Unsupported) => (),
|
||||
|
|
Loading…
Reference in a new issue