fxkit 0.1.0

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

use crate::{
    core::os::unix::linux::os_info::{find_os_release, get_os, get_os_version},
    utils::convert::cstr::str_to_cstr,
};

/// Looks for the ``os-release`` file and returns it
/// # Safety
/// If the function fails to find the ``os-release`` file, it returns null
#[unsafe(no_mangle)]
pub extern "C" fn fxkit_find_os_release() -> *const c_char {
    let os_release = match find_os_release() {
        Ok(os) => unsafe { str_to_cstr(&os)},
        Err(_) => null()
    };

    os_release
}

/// Checks the os version from the ``os-release`` file, and returns it
/// # Safety
/// If the function fails to get the os version, it returns null
#[unsafe(no_mangle)]
pub extern "C" fn fxkit_get_os_version() -> *const c_char {
    match get_os_version() {
        Ok(version) => unsafe { str_to_cstr(&version) },
        Err(_) => null(),
    }
}

/// Checks the os id from the ``os-release`` file, and returns it
/// # Safety
/// If the function fails to get the os id, it returns null
#[unsafe(no_mangle)]
pub extern "C" fn fxkit_get_os() -> *const c_char {
    match get_os() {
        Ok(name) => unsafe { str_to_cstr(&name) },
        Err(_) => null(),
    }
}