1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
extern crate libc;
use libc::c_int;
use std::ffi::CStr;
use std::str;
#[allow(
dead_code,
non_snake_case,
non_camel_case_types,
non_upper_case_globals
)]
mod ffi;
pub use ffi::*;
pub fn error_string(sigar: *mut ffi::sigar_t, code: c_int) -> String {
unsafe {
let ptr = ffi::sigar_strerror(sigar, code);
let bytes = CStr::from_ptr(ptr).to_bytes();
str::from_utf8(bytes)
.ok()
.expect("Invalid UTF8 string")
.to_string()
}
}
pub const SIGAR_CODE_OK: i32 = ffi::SIGAR_OK as i32;