diff --git a/fish-rust/src/fish.rs b/fish-rust/src/fish.rs index 5814597fd..b3637f620 100644 --- a/fish-rust/src/fish.rs +++ b/fish-rust/src/fish.rs @@ -26,7 +26,7 @@ }, common::{ escape, exit_without_destructors, get_executable_path, str2wcstring, wcs2string, - EscapeStringStyle, PROFILING_ACTIVE, PROGRAM_NAME, + PROFILING_ACTIVE, PROGRAM_NAME, }, env::{ environment::{env_init, EnvStack, Environment}, diff --git a/fish-rust/src/flog.rs b/fish-rust/src/flog.rs index 072549861..62abbc366 100644 --- a/fish-rust/src/flog.rs +++ b/fish-rust/src/flog.rs @@ -1,9 +1,8 @@ use crate::parse_util::parse_util_unescape_wildcards; use crate::wchar::prelude::*; use crate::wildcard::wildcard_match; +use crate::wutil::write_to_fd; use libc::c_int; -use std::io::Write; -use std::os::unix::prelude::*; use std::sync::atomic::{AtomicI32, Ordering}; #[rustfmt::skip::macros(category)] @@ -165,10 +164,7 @@ pub fn flog_impl(s: &str) { if fd < 0 { return; } - let mut file = unsafe { std::fs::File::from_raw_fd(fd) }; - let _ = file.write(s.as_bytes()); - // Ensure the file is not closed. - file.into_raw_fd(); + let _ = write_to_fd(s.as_bytes(), fd); } /// The entry point for flogging. diff --git a/fish-rust/src/wutil/mod.rs b/fish-rust/src/wutil/mod.rs index 6d4cac66e..f4478a986 100644 --- a/fish-rust/src/wutil/mod.rs +++ b/fish-rust/src/wutil/mod.rs @@ -402,7 +402,7 @@ pub fn wrename(old_name: &wstr, new_name: &wstr) -> libc::c_int { unsafe { libc::rename(old_narrow.as_ptr(), new_narrow.as_ptr()) } } -fn write_to_fd(input: &[u8], fd: RawFd) -> std::io::Result { +pub fn write_to_fd(input: &[u8], fd: RawFd) -> std::io::Result { let mut file = unsafe { std::fs::File::from_raw_fd(fd) }; let amt = file.write(input); // Ensure the file is not closed.