Resume output of resolution field
[pulga.git] / src / util.rs
bloba27a0493119368744f5535775b865508412c3ddf
1 use libc::{self, c_char};
3 use std::{
4     ffi::{CStr, OsStr},
5     os::unix::ffi::OsStrExt,
6     ptr,
7 };
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());
17     string.into()
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 {
23     unsafe {
24         libc::srand(libc::time(ptr::null_mut()) as u32);
25         libc::rand() % max
26     }