Browse Source

Fix compilation for netbsd-9.2

$ rustc -V
rustc 1.52.1
$ cargo -V
cargo 1.52.0

Pre-requisite steps needed for build:
- Needed to install mozilla certs
- Needed to set OPENSSL_DIR=/usr
master
Manos Pitsidianakis 3 months ago
parent
commit
7533df86e0
Signed by: epilys GPG Key ID: 73627C2F690DF710
  1. 31
      melib/src/datetime.rs
  2. 1
      melib/src/lib.rs
  3. 2
      src/conf.rs

31
melib/src/datetime.rs

@ -73,22 +73,34 @@ extern "C" {
fn gettimeofday(tv: *mut libc::timeval, tz: *mut libc::timezone) -> i32;
}
#[cfg(not(target_os = "netbsd"))]
struct Locale {
new_locale: libc::locale_t,
old_locale: libc::locale_t,
}
#[cfg(target_os = "netbsd")]
struct Locale {
mask: std::os::raw::c_int,
old_locale: *const std::os::raw::c_char,
}
impl Drop for Locale {
fn drop(&mut self) {
#[cfg(not(target_os = "netbsd"))]
unsafe {
let _ = libc::uselocale(self.old_locale);
libc::freelocale(self.new_locale);
}
#[cfg(target_os = "netbsd")]
unsafe {
let _ = libc::setlocale(self.mask, self.old_locale);
}
}
}
// How to unit test this? Test machine is not guaranteed to have non-english locales.
impl Locale {
#[cfg(not(target_os = "netbsd"))]
fn new(
mask: std::os::raw::c_int,
locale: *const std::os::raw::c_char,
@ -108,6 +120,25 @@ impl Locale {
old_locale,
})
}
#[cfg(target_os = "netbsd")]
fn new(
mask: std::os::raw::c_int,
locale: *const std::os::raw::c_char,
_base: libc::locale_t,
) -> Result<Self> {
let old_locale = unsafe { libc::setlocale(mask, std::ptr::null_mut()) };
if old_locale.is_null() {
return Err(nix::Error::last().into());
}
let new_locale = unsafe { libc::setlocale(mask, locale) };
if new_locale.is_null() {
return Err(nix::Error::last().into());
}
Ok(Locale {
mask,
old_locale,
})
}
}
pub fn timestamp_to_string(timestamp: UnixTimestamp, fmt: Option<&str>, posix: bool) -> String {

1
melib/src/lib.rs

@ -181,6 +181,7 @@ pub mod shellexpand {
use smallvec::SmallVec;
use std::ffi::OsStr;
use std::os::unix::ffi::OsStrExt;
#[cfg(not(target_os = "netbsd"))]
use std::os::unix::io::AsRawFd;
use std::path::{Path, PathBuf};

2
src/conf.rs

@ -1154,7 +1154,7 @@ identity="username@hostname.local"
let mut buf = [0u8; 16];
f.read_exact(&mut buf)?;
let mut filename = String::with_capacity(2 * 16);
for byte in buf {
for byte in &buf {
write!(&mut filename, "{:02X}", byte).unwrap();
}
let mut path = std::env::temp_dir();

Loadingโ€ฆ
Cancel
Save