mirror of
https://github.com/fish-shell/fish-shell.git
synced 2026-05-30 19:41:15 -03:00
Adopt Rust libc::MNT_LOCAL
Note the ST_LOCAL usage on NetBSD is also covered by this.
This commit is contained in:
12
src/libc.c
12
src/libc.c
@@ -4,9 +4,9 @@
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <sys/mount.h> // MNT_LOCAL
|
||||
#include <sys/mount.h>
|
||||
#include <sys/resource.h>
|
||||
#include <sys/statvfs.h> // ST_LOCAL
|
||||
#include <sys/statvfs.h>
|
||||
#include <unistd.h>
|
||||
|
||||
uint64_t C_ST_LOCAL() {
|
||||
@@ -17,14 +17,6 @@ uint64_t C_ST_LOCAL() {
|
||||
#endif
|
||||
}
|
||||
|
||||
uint64_t C_MNT_LOCAL() {
|
||||
#if defined(MNT_LOCAL)
|
||||
return MNT_LOCAL;
|
||||
#else
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
const char* C_PATH_BSHELL() { return _PATH_BSHELL; }
|
||||
|
||||
FILE* stdout_stream() { return stdout; }
|
||||
|
||||
@@ -23,9 +23,6 @@ pub fn $cvar() -> $type {
|
||||
};
|
||||
}
|
||||
|
||||
CVAR!(C_ST_LOCAL, ST_LOCAL, u64);
|
||||
CVAR!(C_MNT_LOCAL, MNT_LOCAL, u64);
|
||||
|
||||
CVAR!(C_RLIMIT_SBSIZE, RLIMIT_SBSIZE, i32);
|
||||
CVAR!(C_RLIMIT_CORE, RLIMIT_CORE, i32);
|
||||
CVAR!(C_RLIMIT_DATA, RLIMIT_DATA, i32);
|
||||
|
||||
55
src/path.rs
55
src/path.rs
@@ -694,49 +694,20 @@ pub fn path_remoteness(path: &wstr) -> DirRemoteness {
|
||||
}
|
||||
#[cfg(not(any(target_os = "linux", cygwin)))]
|
||||
{
|
||||
fn remoteness_via_statfs<StatFS, Flags>(
|
||||
statfn: unsafe extern "C" fn(*const libc::c_char, *mut StatFS) -> libc::c_int,
|
||||
flagsfn: fn(&StatFS) -> Flags,
|
||||
is_local_flag: u64,
|
||||
path: &std::ffi::CStr,
|
||||
) -> DirRemoteness
|
||||
where
|
||||
u64: From<Flags>,
|
||||
{
|
||||
if is_local_flag == 0 {
|
||||
return DirRemoteness::unknown;
|
||||
}
|
||||
let mut buf = MaybeUninit::uninit();
|
||||
if unsafe { (statfn)(path.as_ptr(), buf.as_mut_ptr()) } < 0 {
|
||||
return DirRemoteness::unknown;
|
||||
}
|
||||
let buf = unsafe { buf.assume_init() };
|
||||
// statfs::f_flag is hard-coded as 64-bits on 32/64-bit FreeBSD but it's a (4-byte)
|
||||
// long on 32-bit NetBSD.. and always 4-bytes on macOS (even on 64-bit builds).
|
||||
#[allow(clippy::useless_conversion)]
|
||||
if u64::from((flagsfn)(&buf)) & is_local_flag != 0 {
|
||||
DirRemoteness::local
|
||||
} else {
|
||||
DirRemoteness::remote
|
||||
}
|
||||
let mut buf = MaybeUninit::uninit();
|
||||
if unsafe { libc::statfs(narrow.as_ptr(), buf.as_mut_ptr()) } < 0 {
|
||||
return DirRemoteness::unknown;
|
||||
}
|
||||
let buf = unsafe { buf.assume_init() };
|
||||
// statfs::f_flag is hard-coded as 64-bits on 32/64-bit FreeBSD but it's a (4-byte)
|
||||
// long on 32-bit NetBSD.. and always 4-bytes on macOS (even on 64-bit builds).
|
||||
#[allow(clippy::useless_conversion)]
|
||||
let flags = u64::from(buf.f_flags);
|
||||
if flags & (libc::MNT_LOCAL as u64) != 0 {
|
||||
DirRemoteness::local
|
||||
} else {
|
||||
DirRemoteness::remote
|
||||
}
|
||||
// ST_LOCAL is a flag to statvfs, which is itself standardized.
|
||||
// In practice the only system to define it is NetBSD.
|
||||
#[cfg(target_os = "netbsd")]
|
||||
let remoteness = remoteness_via_statfs(
|
||||
libc::statvfs,
|
||||
|stat: &libc::statvfs| stat.f_flag,
|
||||
crate::libc::ST_LOCAL(),
|
||||
&narrow,
|
||||
);
|
||||
#[cfg(not(target_os = "netbsd"))]
|
||||
let remoteness = remoteness_via_statfs(
|
||||
libc::statfs,
|
||||
|stat: &libc::statfs| stat.f_flags,
|
||||
crate::libc::MNT_LOCAL(),
|
||||
&narrow,
|
||||
);
|
||||
remoteness
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user