Skip to content

Commit

Permalink
Merge pull request #267 from orecham/iox2-266-fix-bindgen-failure-for…
Browse files Browse the repository at this point in the history
…-dirent-on-macos

[#266] Configure bindgen to bind dirfd C macro on macOS
  • Loading branch information
elfenpiff committed Jul 8, 2024
2 parents a83c2ec + 18d6c8b commit 9bb5c84
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
5 changes: 5 additions & 0 deletions iceoryx2-pal/posix/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,4 +74,9 @@ fn main() {
cc::Build::new()
.file("src/c/socket_macros.c")
.compile("libsocket_macros.a");

println!("cargo:rerun-if-changed=src/c/dirent.c");
cc::Build::new()
.file("src/c/dirent.c")
.compile("libdirent.a");
}
19 changes: 19 additions & 0 deletions iceoryx2-pal/posix/src/c/dirent.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// Copyright (c) 2024 Contributors to the Eclipse Foundation
//
// See the NOTICE file(s) distributed with this work for additional
// information regarding copyright ownership.
//
// This program and the accompanying materials are made available under the
// terms of the Apache Software License 2.0 which is available at
// https://www.apache.org/licenses/LICENSE-2.0, or the MIT license
// which is available at https://opensource.org/licenses/MIT.
//
// SPDX-License-Identifier: Apache-2.0 OR MIT

#ifdef __APPLE__

#include <dirent.h>

int iox2_dirfd(DIR *dirp) { return dirfd(dirp); };

#endif
3 changes: 2 additions & 1 deletion iceoryx2-pal/posix/src/macos/dirent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,14 @@ pub unsafe fn closedir(dirp: *mut DIR) -> int {
}

pub unsafe fn dirfd(dirp: *mut DIR) -> int {
crate::internal::dirfd(dirp)
internal::iox2_dirfd(dirp)
}

mod internal {
use super::*;

extern "C" {
pub(super) fn scandir_ext(path: *const c_char, namelist: *mut *mut *mut dirent) -> int;
pub(super) fn iox2_dirfd(dir: *mut DIR) -> int;
}
}

0 comments on commit 9bb5c84

Please sign in to comment.