1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-07-29 12:07:46 +00:00

yes: adapt to API changes of uucore/pipes

This commit is contained in:
Daniel Hofstetter 2024-08-14 17:18:54 +02:00
parent 563e3cefd0
commit 9fcf3ee48b
2 changed files with 11 additions and 3 deletions

View file

@ -20,13 +20,19 @@
//! make any effort to rescue data from the pipe if splice() fails, we can //! make any effort to rescue data from the pipe if splice() fails, we can
//! just fall back and start over from the beginning. //! 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 nix::{errno::Errno, libc::S_IFIFO, sys::stat::fstat};
use uucore::pipes::{pipe, splice_exact, vmsplice}; 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; let is_pipe = fstat(out.as_raw_fd())?.st_mode as nix::libc::mode_t & S_IFIFO != 0;
if is_pipe { if is_pipe {

View file

@ -9,6 +9,8 @@ use clap::{builder::ValueParser, crate_version, Arg, ArgAction, Command};
use std::error::Error; use std::error::Error;
use std::ffi::OsString; use std::ffi::OsString;
use std::io::{self, Write}; use std::io::{self, Write};
#[cfg(any(target_os = "linux", target_os = "android"))]
use std::os::fd::AsFd;
use uucore::error::{UResult, USimpleError}; use uucore::error::{UResult, USimpleError};
#[cfg(unix)] #[cfg(unix)]
use uucore::signals::enable_pipe_errors; 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"))] #[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(()), Ok(_) => return Ok(()),
Err(splice::Error::Io(err)) => return Err(err), Err(splice::Error::Io(err)) => return Err(err),
Err(splice::Error::Unsupported) => (), Err(splice::Error::Unsupported) => (),