Stop trying to repackage C, and instead embrace using C portability tools for managing C portability? Like this:
/// Returns the platform-specific value of errno
pub fn errno() -> i32 {
#[cfg(any(target_os = "macos",
target_os = "ios",
target_os = "freebsd"))]
unsafe fn errno_location() -> *const c_int {
extern { fn __error() -> *const c_int; }
__error()
}
// and a whole bunch more platorm-specific errno variants
seems unnecessary, to me, when you could instead:
pub fn errno() -> i32 {
extern "C" rust_errno() -> i32;
rust_errno();
}
and
#include <errno.h>
sysu32_t rust_errno() {
return errno();
}
lowering the total volume of code, making the libraries more portable, and gaining the ability to use portability constructs that C developers have been developing since forever (while avoiding the gotchas that have crept in interfacing to C code written under the assumption that it would only have C-language clients). I know this won’t work for everything, but this approach could help in a lot of places.