mirror of
https://github.com/fish-shell/fish-shell.git
synced 2025-01-19 17:02:45 +08:00
flog: reuse write_to_fd
This commit is contained in:
parent
637926a7fd
commit
ad75c72621
|
@ -26,7 +26,7 @@ use crate::{
|
|||
},
|
||||
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},
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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<usize> {
|
||||
pub fn write_to_fd(input: &[u8], fd: RawFd) -> std::io::Result<usize> {
|
||||
let mut file = unsafe { std::fs::File::from_raw_fd(fd) };
|
||||
let amt = file.write(input);
|
||||
// Ensure the file is not closed.
|
||||
|
|
Loading…
Reference in New Issue
Block a user