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:
Peter Ammon
2025-08-10 18:49:56 -07:00
parent d06f7f01d2
commit 174130fe2f
3 changed files with 3 additions and 13 deletions

View File

@@ -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()) };

View File

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

View File

@@ -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);