rust: remove unused function

rust_string_to_c was used when a buffer should be used as it could
contain nul-byte
pull/15287/head
Philippe Antoine 3 months ago committed by Victor Julien
parent 9b12fd9f09
commit 7d66eb5f04

@ -18,8 +18,6 @@
//! Utility library module for commonly used strings, hexadecimals and other elements.
use crate::jsonbuilder::HEX;
use std::ffi::CString;
use std::os::raw::c_char;
pub mod nom7 {
use nom7::bytes::streaming::{tag, take_until};
@ -101,32 +99,6 @@ pub mod nom8 {
}
}
/// Convert a String to C-compatible string
///
/// This function will consume the provided data and use the underlying bytes to construct a new
/// string, ensuring that there is a trailing 0 byte. This trailing 0 byte will be appended by this
/// function; the provided data should *not* contain any 0 bytes in it.
///
/// Returns a valid pointer, or NULL
pub fn rust_string_to_c(s: String) -> *mut c_char {
CString::new(s)
.map(|c_str| c_str.into_raw())
.unwrap_or(std::ptr::null_mut())
}
/// Free a CString allocated by Rust (for ex. using `rust_string_to_c`)
///
/// # Safety
///
/// s must be allocated by rust, using `CString::new`
#[no_mangle]
pub unsafe extern "C" fn SCRustCStringFree(s: *mut c_char) {
if s.is_null() {
return;
}
drop(CString::from_raw(s));
}
/// Convert an u8-array of data into a hexadecimal representation
pub fn to_hex(input: &[u8]) -> String {
return input

Loading…
Cancel
Save