mirror of
https://github.com/fish-shell/fish-shell.git
synced 2026-06-06 17:31:14 -03:00
Adopt Rust libc _CS_PATH
This is now supported directly by the libc crate - no need for fish to expose this via C.
This commit is contained in:
5
src/env/environment.rs
vendored
5
src/env/environment.rs
vendored
@@ -569,13 +569,12 @@ fn setup_user(vars: &EnvStack) {
|
||||
}
|
||||
|
||||
pub(crate) static FALLBACK_PATH: Lazy<&[WString]> = Lazy::new(|| {
|
||||
use crate::libc::_CS_PATH;
|
||||
// _CS_PATH: colon-separated paths to find POSIX utilities
|
||||
let buf_size = unsafe { confstr(_CS_PATH(), std::ptr::null_mut(), 0) };
|
||||
let buf_size = unsafe { confstr(libc::_CS_PATH, std::ptr::null_mut(), 0) };
|
||||
Box::leak(
|
||||
(if buf_size > 0 {
|
||||
let mut buf = vec![b'\0' as libc::c_char; buf_size];
|
||||
unsafe { confstr(_CS_PATH(), buf.as_mut_ptr(), buf_size) };
|
||||
unsafe { confstr(libc::_CS_PATH, buf.as_mut_ptr(), buf_size) };
|
||||
let buf = buf;
|
||||
// safety: buf should contain a null-byte, and is not mutable unless we move ownership
|
||||
let cstr = unsafe { CStr::from_ptr(buf.as_ptr()) };
|
||||
|
||||
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> // _CS_PATH, _PC_CASE_SENSITIVE
|
||||
#include <unistd.h> // _PC_CASE_SENSITIVE
|
||||
|
||||
uint64_t C_ST_LOCAL() {
|
||||
#if defined(ST_LOCAL)
|
||||
@@ -17,14 +17,6 @@ uint64_t C_ST_LOCAL() {
|
||||
#endif
|
||||
}
|
||||
|
||||
int C_CS_PATH() {
|
||||
#if defined(_CS_PATH)
|
||||
return _CS_PATH;
|
||||
#else
|
||||
return -1;
|
||||
#endif
|
||||
}
|
||||
|
||||
uint64_t C_MNT_LOCAL() {
|
||||
#if defined(MNT_LOCAL)
|
||||
return MNT_LOCAL;
|
||||
|
||||
@@ -31,7 +31,6 @@ pub fn $cvar() -> $type {
|
||||
|
||||
CVAR!(C_ST_LOCAL, ST_LOCAL, u64);
|
||||
CVAR!(C_MNT_LOCAL, MNT_LOCAL, u64);
|
||||
CVAR!(C_CS_PATH, _CS_PATH, i32);
|
||||
|
||||
CVAR!(C_RLIMIT_SBSIZE, RLIMIT_SBSIZE, i32);
|
||||
CVAR!(C_RLIMIT_CORE, RLIMIT_CORE, i32);
|
||||
|
||||
Reference in New Issue
Block a user