Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 40 additions & 2 deletions src/bin/yes.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,50 @@
#![allow(unused_attributes)]
#![feature(can_vector)]

use std::{
borrow::Cow,
io::{BufWriter, Write, stdout},
io::{BufWriter, Write},
os::fd::BorrowedFd,
};

use puppyutils::{Result, cli};
use rustix::{
io::{write, writev},
stdio::stdout,
};

#[repr(transparent)]
struct UnbufStdout<'a> {
raw: BorrowedFd<'a>,
}

impl UnbufStdout<'_> {
pub fn new() -> Self {
Self { raw: stdout() }
}
}

impl Write for UnbufStdout<'_> {
fn write(&mut self, buf: &[u8]) -> std::io::Result<usize> {
write(self.raw, buf).map_err(std::io::Error::from)
}

fn write_vectored(&mut self, bufs: &[std::io::IoSlice<'_>]) -> std::io::Result<usize> {
writev(self.raw, bufs).map_err(std::io::Error::from)
}

#[inline]
fn is_write_vectored(&self) -> bool {
true
}

fn flush(&mut self) -> std::io::Result<()> {
Ok(())
}
}

pub fn main() -> Result {
let mut stdout = stdout();
let mut stdout = UnbufStdout::new();

let mut buffer: Option<String> = None;

Expand Down
2 changes: 2 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![feature(can_vector)]

use std::{
borrow::Cow,
fmt::{Debug, Display},
Expand Down
2 changes: 2 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![feature(can_vector)]

use std::{borrow::Cow, env::current_exe, os::unix::ffi::OsStrExt, path::PathBuf};

use puppyutils::{Exit, Result};
Expand Down