mirror of
https://github.com/fish-shell/fish-shell.git
synced 2026-04-20 07:51:14 -03:00
Adopt rust _PC_CASE_SENSITIVE
fish no longer needs to expose this - the libc crate does the job.
This commit is contained in:
@@ -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<WString, bool>;
|
||||
|
||||
#[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
|
||||
}
|
||||
|
||||
10
src/libc.c
10
src/libc.c
@@ -7,7 +7,7 @@
|
||||
#include <sys/mount.h> // MNT_LOCAL
|
||||
#include <sys/resource.h>
|
||||
#include <sys/statvfs.h> // ST_LOCAL
|
||||
#include <unistd.h> // _PC_CASE_SENSITIVE
|
||||
#include <unistd.h>
|
||||
|
||||
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; }
|
||||
|
||||
@@ -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<c_char> = AtomicPtr::new(std::ptr::null_mut());
|
||||
extern "C" {
|
||||
pub fn C_PATH_BSHELL() -> *const c_char;
|
||||
}
|
||||
|
||||
pub static _PC_CASE_SENSITIVE: Lazy<c_int> = 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);
|
||||
|
||||
Reference in New Issue
Block a user