diff --git a/services/backup/blob_client/src/tools.rs b/services/backup/blob_client/src/tools.rs --- a/services/backup/blob_client/src/tools.rs +++ b/services/backup/blob_client/src/tools.rs @@ -1,3 +1,6 @@ +use libc; +use libc::c_char; +use std::ffi::{CStr, CString}; use std::sync::{Arc, Mutex}; use tracing::error; @@ -17,7 +20,9 @@ error!("could not access error messages"); } -pub fn check_error(error_messages: &Arc>>) -> Result<(), String> { +pub fn check_error( + error_messages: &Arc>>, +) -> Result<(), String> { if let Ok(errors) = error_messages.lock() { return match errors.is_empty() { true => Ok(()), @@ -26,3 +31,13 @@ } Err("could not access error messages".to_string()) } + +pub fn c_char_pointer_to_string(c_char_pointer: *const c_char) -> String { + let holder_cstr: &CStr = unsafe { CStr::from_ptr(c_char_pointer) }; + return holder_cstr.to_str().unwrap().to_owned(); +} + +pub fn string_to_c_char_pointer(signs: &String) -> *const c_char { + let result = CString::new((&signs).as_bytes()).unwrap(); + result.as_ptr() +}