Skip to main content

rust_profanos/
lib.rs

1#![no_std]
2
3use core::ffi::CStr;
4
5use alloc::{borrow::ToOwned, vec::Vec};
6use libs::std::process::exit;
7
8use libs::std::env::{Args, ARGS};
9
10extern crate alloc;
11
12pub mod libs;
13pub mod utilities;
14
15#[unsafe(no_mangle)]
16pub extern "C" fn _start(argc: i32, argv: *const *const i8) -> ! {
17    let mut args = Vec::new();
18
19    for i in 0..argc {
20        let cstr_ptr = unsafe { *argv.add(i as usize) };
21        let cstr = unsafe { CStr::from_ptr(cstr_ptr) };
22        let str = cstr.to_str().unwrap_or("<invalid UTF-8>").to_owned();
23        args.push(str);  // Push the argument into the vector
24    }
25
26    unsafe { 
27        ARGS = Some( Args::new(
28            argc as usize,
29            args,
30        )) 
31    }
32
33    unsafe extern "C" {
34        fn main();
35    }
36    
37    unsafe {
38        main();
39    }
40
41    exit(0);
42}