flog: reuse write_to_fd

This commit is contained in:
Johannes Altmanninger 2023-10-08 18:14:04 +02:00
parent 637926a7fd
commit ad75c72621
3 changed files with 4 additions and 8 deletions

View File

@ -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},

View File

@ -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.

View File

@ -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.