1 use libc::{self, c_char};
5 os::unix::ffi::OsStrExt,
9 pub(crate) unsafe fn char_ptr_to_string(ptr: *mut c_char) -> String {
10 let cstr = CStr::from_ptr(ptr);
11 let os_str = OsStr::from_bytes(cstr.to_bytes());
12 os_str_to_string(os_str)
15 pub(crate) fn os_str_to_string(os_str: &OsStr) -> String {
16 let string = String::from_utf8_lossy(os_str.as_bytes());
20 /// Simple rand function, wraps over libc::rand
21 /// It isn't super secure, but we don't really need security
22 pub(crate) fn get_rand(max: i32) -> i32 {
24 libc::srand(libc::time(ptr::null_mut()) as u32);
29 // Extracts the last element of a path.
30 // Example: "/foo/bar/" -> "bar"
31 pub(crate) fn get_base(path: &str) -> String {
32 path.rsplit(|a| a == '/')