diff --git a/src/highlight/file_tester.rs b/src/highlight/file_tester.rs index 8149f0fe5..803f8dcfd 100644 --- a/src/highlight/file_tester.rs +++ b/src/highlight/file_tester.rs @@ -8,7 +8,6 @@ VARIABLE_EXPAND, VARIABLE_EXPAND_SINGLE, }; use crate::expand::{expand_tilde, ExpandFlags, HOME_DIRECTORY}; -use crate::libc::_PC_CASE_SENSITIVE; use crate::operation_context::OperationContext; use crate::path::path_apply_working_directory; use crate::redirection::RedirectionMode; @@ -23,7 +22,6 @@ dir_iter::DirIter, fish_wcstoi, normalize_path, waccess, wbasename, wdirname, wstat, }; use libc::PATH_MAX; -use std::collections::hash_map::Entry; use std::collections::{HashMap, HashSet}; use std::os::fd::RawFd; @@ -391,27 +389,30 @@ pub fn is_potential_cd_path( /// false: the filesystem is not case insensitive /// true: the file system is case insensitive pub type CaseSensitivityCache = HashMap; + +#[cfg(any(target_os = "macos", target_os = "ios"))] fn fs_is_case_insensitive( path: &wstr, fd: RawFd, case_sensitivity_cache: &mut CaseSensitivityCache, ) -> bool { - let mut result = false; - if *_PC_CASE_SENSITIVE != 0 { - // Try the cache first. - match case_sensitivity_cache.entry(path.to_owned()) { - Entry::Occupied(e) => { - /* Use the cached value */ - result = *e.get(); - } - Entry::Vacant(e) => { - // Ask the system. A -1 value means error (so assume case sensitive), a 1 value means case - // sensitive, and a 0 value means case insensitive. - let ret = unsafe { libc::fpathconf(fd, *_PC_CASE_SENSITIVE) }; - result = ret == 0; - e.insert(result); - } - } - } - result + if let Some(cached) = case_sensitivity_cache.get(path) { + return *cached; + }; + // Ask the system. A -1 value means error (so assume case sensitive), a 1 value means case + // sensitive, and a 0 value means case insensitive. + let ret = unsafe { libc::fpathconf(fd, libc::_PC_CASE_SENSITIVE) }; + let icase = ret == 0; + case_sensitivity_cache.insert(path.to_owned(), icase); + icase +} + +#[cfg(not(any(target_os = "macos", target_os = "ios")))] +pub fn fs_is_case_insensitive( + _path: &wstr, + _fd: RawFd, + _case_sensitivity_cache: &mut CaseSensitivityCache, +) -> bool { + // Other platforms don’t have _PC_CASE_SENSITIVE. + false } diff --git a/src/libc.c b/src/libc.c index 072609ef5..dc327c9fd 100644 --- a/src/libc.c +++ b/src/libc.c @@ -7,7 +7,7 @@ #include // MNT_LOCAL #include #include // ST_LOCAL -#include // _PC_CASE_SENSITIVE +#include uint64_t C_ST_LOCAL() { #if defined(ST_LOCAL) @@ -27,14 +27,6 @@ uint64_t C_MNT_LOCAL() { const char* C_PATH_BSHELL() { return _PATH_BSHELL; } -int C_PC_CASE_SENSITIVE() { -#ifdef _PC_CASE_SENSITIVE - return _PC_CASE_SENSITIVE; -#else - return 0; -#endif -} - FILE* stdout_stream() { return stdout; } int C_RLIMIT_CORE() { return RLIMIT_CORE; } diff --git a/src/libc.rs b/src/libc.rs index ba1791fea..bb26edb0d 100644 --- a/src/libc.rs +++ b/src/libc.rs @@ -1,18 +1,12 @@ use std::sync::atomic::AtomicPtr; -use libc::{c_char, c_int}; -use once_cell::sync::Lazy; +use libc::c_char; pub static _PATH_BSHELL: AtomicPtr = AtomicPtr::new(std::ptr::null_mut()); extern "C" { pub fn C_PATH_BSHELL() -> *const c_char; } -pub static _PC_CASE_SENSITIVE: Lazy = Lazy::new(|| unsafe { C_PC_CASE_SENSITIVE() }); -extern "C" { - fn C_PC_CASE_SENSITIVE() -> c_int; -} - extern "C" { pub fn stdout_stream() -> *mut libc::FILE; pub fn setlinebuf(stream: *mut libc::FILE);