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
Manos Pitsidianakis 2021-09-06 18:54:40 +03:00
parent 526a246430
commit 7533df86e0
Signed by: Manos Pitsidianakis
GPG Key ID: 73627C2F690DF710
3 changed files with 33 additions and 1 deletions

View File

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

View File

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

View File

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