refactor: extract write_to_fd into util crate

Part of #12502
This commit is contained in:
Daniel Rainer
2026-03-01 19:00:31 +01:00
committed by Johannes Altmanninger
parent c5e4fed021
commit c0bb0d6584
6 changed files with 11 additions and 6 deletions

View File

@@ -13,6 +13,7 @@
use crate::signal::SigChecker;
use crate::topic_monitor::Topic;
use errno::errno;
use fish_util::write_to_fd;
use fish_wcstringutil::{join_strings, str2bytes_callback, wcs2bytes, wcs2osstring, wcs2zstring};
use fish_widestring::{IntoCharIter, L, WExt as _, WString, wstr};
use nix::unistd::AccessFlags;
@@ -351,10 +352,6 @@ pub fn wrename(old_name: &wstr, new_name: &wstr) -> io::Result<()> {
fs::rename(old_narrow, new_narrow)
}
pub fn write_to_fd(input: &[u8], fd: RawFd) -> nix::Result<usize> {
nix::unistd::write(unsafe { BorrowedFd::borrow_raw(fd) }, input)
}
/// Write a wide string to a file descriptor. This avoids doing any additional allocation.
/// Returns nothing when interrupted by ctrl-c or HUP.
pub fn unescape_bytes_and_write_to_fd(input: impl IntoCharIter, fd: RawFd) -> Option<usize> {