Skip to content

Instantly share code, notes, and snippets.

@mkomitee
Created April 29, 2015 17:23
Show Gist options
  • Save mkomitee/a381600727cc5b395b3f to your computer and use it in GitHub Desktop.
Save mkomitee/a381600727cc5b395b3f to your computer and use it in GitHub Desktop.
how do 2?
extern crate libc;
use libc::*;
use std::ptr;
#[allow(non_camel_case_types)]
#[repr(C)]
type krb5_error_code = c_uint;
#[allow(non_camel_case_types)]
#[repr(C)]
struct krb5_context;
impl krb5_context {
fn new<'a>() -> &'a krb5_context {
unsafe {
&*ptr::null()
}
}
}
impl Drop for krb5_context {
fn drop(&mut self) {
unsafe{
krb5_free_context(self)
}
}
}
#[link(name = "krb5")]
extern "C" {
fn krb5_init_context(context: *mut krb5_context) -> krb5_error_code;
fn krb5_free_context(context: *mut krb5_context);
}
fn main() {
let res = unsafe {
let mut ctx = krb5_context::new();
if krb5_init_context(ctx) == 0 {
Ok(())
} else {
Err(())
}
};
// match res {
// Ok(_) => println!("SUCCESS!"),
// Err(_) => println!("ERROR!"),
// }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment