diff --git a/src/libc.c b/src/libc.c index d4a983ae1..b3f90cede 100644 --- a/src/libc.c +++ b/src/libc.c @@ -1,3 +1,4 @@ +#include #include #include #include @@ -180,3 +181,9 @@ int C_RLIMIT_NTHR() { return -1; #endif } + +#ifdef LC_GLOBAL_LOCALE +locale_t C_LC_GLOBAL_LOCALE() { + return LC_GLOBAL_LOCALE; +} +#endif diff --git a/src/libc.rs b/src/libc.rs index 8e3af35e5..a2b05463e 100644 --- a/src/libc.rs +++ b/src/libc.rs @@ -102,3 +102,8 @@ extern "C" { fn C_RLIMIT_NPTS() -> i32; // ifndef: -1 fn C_RLIMIT_NTHR() -> i32; // ifndef: -1 } + +#[cfg(target_os = "netbsd")] +extern "C" { + pub fn C_LC_GLOBAL_LOCALE() -> libc::locale_t; +} diff --git a/src/locale.rs b/src/locale.rs index 17236b452..1beff696a 100644 --- a/src/locale.rs +++ b/src/locale.rs @@ -60,12 +60,17 @@ unsafe fn lconv_to_locale(lconv: &libc::lconv) -> Locale { /// Read the numeric locale, or None on any failure. #[cfg(localeconv_l)] +#[allow(non_snake_case)] unsafe fn read_locale() -> Option { extern "C" { fn localeconv_l(loc: libc::locale_t) -> *const libc::lconv; } - /// Rust libc does not provide LC_GLOBAL_LOCALE, but it appears to be -1 everywhere. + /// Rust libc does not provide LC_GLOBAL_LOCALE, but it is usually -1. + #[cfg(not(target_os = "netbsd"))] const LC_GLOBAL_LOCALE: libc::locale_t = (-1_isize) as libc::locale_t; + // On NetBSD it's not. + #[cfg(target_os = "netbsd")] + let LC_GLOBAL_LOCALE: libc::locale_t = unsafe { crate::libc::C_LC_GLOBAL_LOCALE() }; const empty: [libc::c_char; 1] = [0]; let cur = libc::duplocale(LC_GLOBAL_LOCALE); diff --git a/src/path.rs b/src/path.rs index e28bb813b..92ecefd1a 100644 --- a/src/path.rs +++ b/src/path.rs @@ -684,14 +684,14 @@ fn path_remoteness(path: &wstr) -> DirRemoteness { } let mnt_local = MNT_LOCAL(); if mnt_local != 0 { - let mut buf: libc::statfs = unsafe { std::mem::zeroed() }; - if unsafe { libc::statfs(narrow.as_ptr(), &mut buf) } < 0 { + let mut buf: libc::statvfs = unsafe { std::mem::zeroed() }; + if unsafe { libc::statvfs(narrow.as_ptr(), &mut buf) } < 0 { return DirRemoteness::unknown; } // 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)] - return if u64::from(buf.f_flags) & mnt_local != 0 { + return if u64::from(buf.f_flag) & mnt_local != 0 { DirRemoteness::local } else { DirRemoteness::remote diff --git a/src/screen.rs b/src/screen.rs index a0499f930..42cd44abf 100644 --- a/src/screen.rs +++ b/src/screen.rs @@ -601,10 +601,17 @@ impl Screen { unsafe { libc::fstat(STDOUT_FILENO, &mut post_buff_1) }; unsafe { libc::fstat(STDERR_FILENO, &mut post_buff_2) }; + // Yes these differ in one `_`. I hate it. + #[cfg(not(target_os = "netbsd"))] let changed = self.prev_buff_1.st_mtime != post_buff_1.st_mtime || self.prev_buff_1.st_mtime_nsec != post_buff_1.st_mtime_nsec || self.prev_buff_2.st_mtime != post_buff_2.st_mtime || self.prev_buff_2.st_mtime_nsec != post_buff_2.st_mtime_nsec; + #[cfg(target_os = "netbsd")] + let changed = self.prev_buff_1.st_mtime != post_buff_1.st_mtime + || self.prev_buff_1.st_mtimensec != post_buff_1.st_mtimensec + || self.prev_buff_2.st_mtime != post_buff_2.st_mtime + || self.prev_buff_2.st_mtimensec != post_buff_2.st_mtimensec; if changed { // Ok, someone has been messing with our screen. We will want to repaint. However, we do not diff --git a/src/wutil/mod.rs b/src/wutil/mod.rs index 8e4c89424..70331ea9e 100644 --- a/src/wutil/mod.rs +++ b/src/wutil/mod.rs @@ -537,10 +537,16 @@ impl FileId { result.change_seconds = buf.st_ctime; result.mod_seconds = buf.st_mtime; #[allow(clippy::unnecessary_cast)] // platform-dependent + #[cfg(not(target_os = "netbsd"))] { result.change_nanoseconds = buf.st_ctime_nsec as _; result.mod_nanoseconds = buf.st_mtime_nsec as _; } + #[cfg(target_os = "netbsd")] + { + result.change_nanoseconds = buf.st_ctimensec as _; + result.mod_nanoseconds = buf.st_mtimensec as _; + } result }