Skip to content

Commit f86dbf2

Browse files
committed
Auto merge of #2216 - Thomasdezeeuw:macos-gethostuuid, r=Amanieu
Add gethostuuid and uuid_t on macOS This adds the `gethostuuid` function and the `uuid_t` for macOS. I'm not sure the function signature is correct. It's defined as the following in C: ```C int gethostuuid(uuid_t id, const struct timespec *wait); typedef unsigned char __darwin_uuid_t[16]; typedef __darwin_uuid_t uuid_t; ``` Because C doesn't really has arrays, the accept parameter can't be `uuid_t` in Rust, as Rust does have arrays and thus expect an array to be passed by value, where the C function expects a pointer.
2 parents 9bf70c4 + eca2ea6 commit f86dbf2

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

libc-test/build.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -361,6 +361,8 @@ fn test_apple(target: &str) {
361361
cfg.skip_roundtrip(move |s| match s {
362362
// FIXME: this type has the wrong ABI
363363
"max_align_t" if i686 => true,
364+
// Can't return an array from a C function.
365+
"uuid_t" => true,
364366
_ => false,
365367
});
366368
cfg.generate("../src/lib.rs", "main.rs");

src/unix/bsd/apple/mod.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ pub type cpu_subtype_t = integer_t;
2929
pub type natural_t = u32;
3030
pub type mach_msg_type_number_t = natural_t;
3131
pub type kern_return_t = ::c_int;
32+
pub type uuid_t = [u8; 16];
3233

3334
pub type posix_spawnattr_t = *mut ::c_void;
3435
pub type posix_spawn_file_actions_t = *mut ::c_void;
@@ -4098,6 +4099,10 @@ extern "C" {
40984099
buffersize: u32,
40994100
) -> ::c_int;
41004101
pub fn proc_libversion(major: *mut ::c_int, mintor: *mut ::c_int) -> ::c_int;
4102+
/// # Notes
4103+
///
4104+
/// `id` is of type [`uuid_t`].
4105+
pub fn gethostuuid(id: *mut u8, timeout: *const ::timespec) -> ::c_int;
41014106
}
41024107

41034108
cfg_if! {

0 commit comments

Comments
 (0)