Remove useless osttr->cstr->osstr roundtrip

This commit is contained in:
Fabian Boehm 2024-08-16 11:00:08 +02:00
parent 980ef6f2f1
commit 8612d34996
2 changed files with 5 additions and 23 deletions

View File

@ -441,21 +441,6 @@ fn fish_parse_opt(args: &mut [WString], opts: &mut FishCmdOpts) -> ControlFlow<i
ControlFlow::Continue(optind)
}
fn cstr_from_osstr(s: &OsStr) -> CString {
// is there no better way to do this?
// this is
// CStr::from_bytes_until_nul(s.as_bytes()).unwrap()
// except we need to add the nul if it is not present
CString::new(
s.as_bytes()
.iter()
.cloned()
.take_while(|&c| c != b'\0')
.collect::<Vec<_>>(),
)
.unwrap()
}
fn main() {
PROGRAM_NAME.set(L!("fish")).unwrap();
if !cfg!(small_main_stack) {
@ -617,8 +602,7 @@ fn throwing_main() -> i32 {
// TODO: if-let-chains
if opts.profile_startup_output.is_some() && opts.profile_startup_output != opts.profile_output {
let s = cstr_from_osstr(&opts.profile_startup_output.unwrap());
parser.emit_profiling(s.as_bytes());
parser.emit_profiling(&opts.profile_startup_output.unwrap());
// If we are profiling both, ensure the startup data only
// ends up in the startup file.
@ -720,8 +704,7 @@ fn throwing_main() -> i32 {
);
if let Some(profile_output) = opts.profile_output {
let s = cstr_from_osstr(&profile_output);
parser.emit_profiling(s.as_bytes());
parser.emit_profiling(&profile_output);
}
history::save_all();

View File

@ -39,7 +39,6 @@ use std::cell::{Ref, RefCell, RefMut};
use std::ffi::{CStr, OsStr};
use std::num::NonZeroU32;
use std::os::fd::{AsRawFd, OwnedFd, RawFd};
use std::os::unix::prelude::OsStrExt;
use std::rc::Rc;
#[cfg(target_has_atomic = "64")]
use std::sync::atomic::AtomicU64;
@ -976,17 +975,17 @@ impl Parser {
}
/// Output profiling data to the given filename.
pub fn emit_profiling(&self, path: &[u8]) {
pub fn emit_profiling(&self, path: &OsStr) {
// Save profiling information. OK to not use CLO_EXEC here because this is called while fish is
// exiting (and hence will not fork).
let f = match std::fs::File::create(OsStr::from_bytes(path)) {
let f = match std::fs::File::create(path) {
Ok(f) => f,
Err(err) => {
FLOG!(
warning,
wgettext_fmt!(
"Could not write profiling information to file '%s': %s",
&String::from_utf8_lossy(path),
path.to_string_lossy(),
err.to_string()
)
);