use std::ffi::CStr;
use std::ffi::CString;
use std::os::raw::c_char;

#[no_mangle]
#[allow(non_snake_case)]
pub extern "C" fn DoSomeInterestingWork(count: i32, content: *const c_char) -> *const c_char {
    let content_string = unsafe { CStr::from_ptr(content) }
        .to_string_lossy()
        .to_string();

    let mut all_the_content = Vec::new();

    for i in 0..count {
        all_the_content.push(format!(
            "Let's include {} for the {}th time",
            content_string, i
        ));
    }

    CString::new(all_the_content.join("💣"))
        .unwrap()
        .into_raw()
}

#[no_mangle]
#[allow(non_snake_case)]
pub extern "C" fn FreeString(content: *mut c_char) {
    unsafe {
        if content.is_null() {
            return;
        }
        CString::from_raw(content)
    };
}
