Skip to content

Commit

Permalink
fix some macos changes
Browse files Browse the repository at this point in the history
  • Loading branch information
ClementTsang committed Feb 21, 2025
1 parent 8ad6d82 commit 80cb80b
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 6 deletions.
5 changes: 3 additions & 2 deletions src/collection/disks/unix/macos/io_kit/bindings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,9 @@ pub const kIOServicePlane: &str = "IOService\0";
#[expect(non_upper_case_globals)]
pub const kIOMediaClass: &str = "IOMedia\0";

// See [here](https://developer.apple.com/documentation/iokit) for more details.
extern "C" {
// SAFETY: Bindings like this are inherently unsafe. See [here](https://developer.apple.com/documentation/iokit) for
// more details.
unsafe extern "C" {

pub fn IOServiceGetMatchingServices(
mainPort: mach_port_t, matching: CFMutableDictionaryRef, existing: *mut io_iterator_t,
Expand Down
3 changes: 2 additions & 1 deletion src/collection/disks/unix/other/bindings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ use std::io::Error;

const MNT_NOWAIT: libc::c_int = 2;

extern "C" {
// SAFETY: Bindings like this are inherently unsafe.
unsafe extern "C" {
fn getfsstat64(buf: *mut libc::statfs, bufsize: libc::c_int, flags: libc::c_int)
-> libc::c_int;
}
Expand Down
2 changes: 1 addition & 1 deletion src/collection/disks/unix/other/partition.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ fn partitions_iter() -> anyhow::Result<impl Iterator<Item = Partition>> {
let mounts = bindings::mounts()?;

unsafe fn ptr_to_cow<'a>(ptr: *const i8) -> std::borrow::Cow<'a, str> {
CStr::from_ptr(ptr).to_string_lossy()
unsafe { CStr::from_ptr(ptr).to_string_lossy() }
}

Ok(mounts.into_iter().map(|stat| {
Expand Down
7 changes: 5 additions & 2 deletions src/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1237,7 +1237,7 @@ mod test {
use super::{DEFAULT_CONFIG_FILE_LOCATION, get_config_path};

// Case three: no previous config, no XDG var.
// SAFETY: this is the only test that does this
// SAFETY: This is fine, this is just a test, and no other test affects env vars.
unsafe {
std::env::remove_var("XDG_CONFIG_HOME");
}
Expand All @@ -1255,7 +1255,10 @@ mod test {
}

// Case two: no previous config, XDG var exists.
std::env::set_var("XDG_CONFIG_HOME", "/tmp");
// SAFETY: This is fine, this is just a test, and no other test affects env vars.
unsafe {
std::env::set_var("XDG_CONFIG_HOME", "/tmp");
}
let mut case_2 = PathBuf::new();
case_2.push("/tmp");
case_2.push(DEFAULT_CONFIG_FILE_LOCATION);
Expand Down

0 comments on commit 80cb80b

Please sign in to comment.