bindgen strip nix_ prefix

(cherry picked from commit d07ec1990015f5d12b39da40ad0cb1ef0e798642)
This commit is contained in:
Taeer Bar-Yam 2024-05-09 12:29:32 -04:00 committed by Robert Hensing
parent 1edaffcc09
commit c2159c8834
6 changed files with 32 additions and 23 deletions

View file

@ -4,12 +4,12 @@ use std::ptr::null_mut;
use std::ptr::NonNull;
pub struct Context {
inner: NonNull<raw::nix_c_context>,
inner: NonNull<raw::c_context>,
}
impl Context {
pub fn new() -> Self {
let ctx = unsafe { raw::nix_c_context_create() };
let ctx = unsafe { raw::c_context_create() };
if ctx.is_null() {
panic!("nix_c_context_create returned a null pointer");
}
@ -18,14 +18,14 @@ impl Context {
};
ctx
}
pub fn ptr(&self) -> *mut raw::nix_c_context {
pub fn ptr(&self) -> *mut raw::c_context {
self.inner.as_ptr()
}
pub fn check_err(&self) -> Result<()> {
let err = unsafe { raw::nix_err_code(self.inner.as_ptr()) };
let err = unsafe { raw::err_code(self.inner.as_ptr()) };
if err != raw::NIX_OK.try_into().unwrap() {
// msgp is a borrowed pointer, so we don't need to free it
let msgp = unsafe { raw::nix_err_msg(null_mut(), self.inner.as_ptr(), null_mut()) };
let msgp = unsafe { raw::err_msg(null_mut(), self.inner.as_ptr(), null_mut()) };
// Turn the i8 pointer into a Rust string by copying
let msg: &str = unsafe { core::ffi::CStr::from_ptr(msgp).to_str()? };
bail!("{}", msg);
@ -37,7 +37,7 @@ impl Context {
impl Drop for Context {
fn drop(&mut self) {
unsafe {
raw::nix_c_context_free(self.inner.as_ptr());
raw::c_context_free(self.inner.as_ptr());
}
}
}

View file

@ -20,7 +20,7 @@ mod tests {
use nix_c_raw as raw;
/// Typecheck the function signature against the generated bindings in nix_c_raw.
static _CALLBACK_GET_VEC_U8: raw::nix_get_string_callback = Some(callback_get_vec_u8);
static _CALLBACK_GET_VEC_U8: raw::get_string_callback = Some(callback_get_vec_u8);
#[test]
fn test_callback_get_vec_u8_empty() {