fxkit 0.1.0

Useful utilities for writting Rust CLI tools
Documentation
use std::{ffi::{c_char, c_int}, ptr::null};

use crate::{
    core::os::unix::linux::bedrock::{
        check_bedrock, detect_pmm_interface, detect_stratum_init, list_strata, running_in_strat,
    },
    utils::convert::cstr::str_to_cstr,
};

/// Returns true if running on a Bedrock system, otherwise false
/// # Safety
/// This function is completely safe
#[unsafe(no_mangle)]
pub extern "C" fn fxkit_check_bedrock() -> bool {
    check_bedrock()
}

/// Returns the amount of installed strata's on a Bedrock system
/// # Safety
/// This function is completely safe
#[unsafe(no_mangle)]
pub extern "C" fn fxkit_list_strata() -> c_int {
    match list_strata() {
        Ok(value) => return value as c_int,
        Err(_) => return 0,
    };
}

/// Checks if the process is running ``strat`` if yes it the function returns true, else false
/// # Safety
/// This function is completely safe
#[unsafe(no_mangle)]
pub extern "C" fn fxkit_running_in_strat() -> bool {
    match running_in_strat() {
        Ok(running) => return running,
        Err(_) => return false
    }
}

/// Detects the ``pmm`` interface and returns it
/// # Safety
/// If the function fails to detect the interface, it returns null
#[unsafe(no_mangle)]
pub extern "C" fn fxkit_pmm_detect_interface() -> *const c_char {
    match detect_pmm_interface() {
        Ok(pmm_interface) => unsafe { str_to_cstr(&pmm_interface) },
        Err(_) => null(),
    }
}

/// Detects the ``init`` stratum and returns the name of it
/// # Safety
/// If the function fails to detect the stratum, it returns null
#[unsafe(no_mangle)]
pub extern "C" fn fxkit_detect_init_stratum() -> *const c_char {
   match detect_stratum_init() {
    Ok(strata) => unsafe { str_to_cstr(&strata) },
    Err(_) => null()
   }
}