Skip to content

Commit

Permalink
linux fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
cre4ture committed Mar 17, 2024
1 parent 112f76b commit 563226a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
12 changes: 6 additions & 6 deletions src/uu/dd/src/dd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,13 @@ use nix::fcntl::FcntlArg::F_SETFL;
use nix::fcntl::OFlag;
use parseargs::Parser;
use progress::{gen_prog_updater, ProgUpdate, ReadStat, StatusLevel, WriteStat};
use uucore::io::OwnedFileDescriptorOrHandle;

use std::cmp;
use std::env;
use std::ffi::OsString;
use std::fs::{File, OpenOptions};
use std::io::{self, Read, Seek, SeekFrom, Stdout, Write};
#[cfg(unix)]
use std::os::fd::{AsFd, OwnedFd};
#[cfg(any(target_os = "linux", target_os = "android"))]
use std::os::unix::fs::OpenOptionsExt;
#[cfg(unix)]
Expand Down Expand Up @@ -746,12 +745,13 @@ impl<'a> Output<'a> {
/// already opened by the system (stdout) and has a state
/// (current position) that shall be used.
fn new_file_from_stdout(settings: &'a Settings) -> UResult<Self> {
use uucore::io::OwnedFileDescriptorOrHandle;

let fx = OwnedFileDescriptorOrHandle::from(io::stdout())?;
#[cfg(any(target_os = "linux", target_os = "android"))]
if let Some(libc_flags) = make_linux_oflags(_oflags) {
nix::fcntl::fcntl(fx.as_raw(), F_SETFL(OFlag::from_bits_retain(libc_flags)))?;
if let Some(libc_flags) = make_linux_oflags(&settings.oflags) {
nix::fcntl::fcntl(
fx.as_raw().as_raw_fd(),
F_SETFL(OFlag::from_bits_retain(libc_flags)),
)?;

Check warning on line 754 in src/uu/dd/src/dd.rs

View check run for this annotation

Codecov / codecov/patch

src/uu/dd/src/dd.rs#L754

Added line #L754 was not covered by tests
}

Self::prepare_file(fx.into_file(), settings)
Expand Down
9 changes: 6 additions & 3 deletions src/uucore/src/lib/mods/io.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,21 @@
// For the full copyright and license information, please view the LICENSE
// file that was distributed with this source code.

#[cfg(not(windows))]
use std::os::fd::{AsFd, OwnedFd};
#[cfg(windows)]
use std::os::windows::io::{AsHandle, OwnedHandle};
use std::{
fs::{File, OpenOptions},
io::{self, Stdout},
os::windows::io::{AsHandle, OwnedHandle},
path::Path,
process::Stdio,
};

#[cfg(windows)]
type XType = OwnedHandle;
#[cfg(not(windows))]
type XType = OwnedFileDescriptor;
type XType = OwnedFd;

pub struct OwnedFileDescriptorOrHandle {
fx: XType,
Expand All @@ -40,7 +43,7 @@ impl OwnedFileDescriptorOrHandle {
#[cfg(not(windows))]
pub fn from<T: AsFd>(t: T) -> io::Result<Self> {
Ok(Self {
x: t.as_fd().try_clone_to_owned()?,
fx: t.as_fd().try_clone_to_owned()?,
})
}

Expand Down

0 comments on commit 563226a

Please sign in to comment.