1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
//!
//! Interface functions to be called from other languages
//!

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

unsafe fn convert_args(args: *const *const c_char) -> Vec<String> {
    let mut rc = Vec::new();

    let mut ptr = args;
    while !ptr.is_null() && !(*ptr).is_null() {
        let opt = CStr::from_ptr(*ptr).to_string_lossy().to_string();
        rc.push(opt);
        ptr = ptr.offset(1);
    }

    rc
}
/// Entry point to main utility function for externally linking applications
///
/// * `args` - zero-terminated char* argv[] array matching the ipputil entry point arguments, including application name
#[no_mangle]
pub unsafe extern "C" fn ipp_main(args: *const *const c_char) -> i32 {
    let args = convert_args(args);
    match util::util_main(args) {
        Ok(_) => 0,
        Err(e) => e.as_exit_code(),
    }
}