Skip to content
Snippets Groups Projects
Verified Commit 65bd3ed1 authored by Jeremy Soller's avatar Jeremy Soller
Browse files

Fixes for program_invocation_name and program_invocation_short_name

parent a50d80ee
No related branches found
No related tags found
No related merge requests found
......@@ -15,24 +15,12 @@ pub unsafe extern "C" fn __errno_location() -> *mut c_int {
#[no_mangle]
pub unsafe extern "C" fn __program_invocation_name() -> *mut *mut c_char {
&mut platform::inner_argv[0]
&mut platform::program_invocation_name
}
#[no_mangle]
pub unsafe extern "C" fn __program_invocation_short_name() -> *mut *mut c_char {
let mut ptr = platform::inner_argv[0];
let mut slash_ptr = ptr;
loop {
let b = *ptr as u8;
if b == 0 {
return &mut slash_ptr;
} else {
ptr = ptr.add(1);
if b == b'/' {
slash_ptr = ptr;
}
}
}
&mut platform::program_invocation_short_name
}
pub const EPERM: c_int = 1; /* Operation not permitted */
......
......@@ -46,6 +46,10 @@ pub static mut errno: c_int = 0;
pub static mut argv: *mut *mut c_char = ptr::null_mut();
#[allow(non_upper_case_globals)]
pub static mut inner_argv: Vec<*mut c_char> = Vec::new();
#[allow(non_upper_case_globals)]
pub static mut program_invocation_name: *mut c_char = ptr::null_mut();
#[allow(non_upper_case_globals)]
pub static mut program_invocation_short_name: *mut c_char = ptr::null_mut();
#[allow(non_upper_case_globals)]
#[no_mangle]
......
......@@ -2,7 +2,7 @@ use alloc::vec::Vec;
use core::{intrinsics, ptr};
use crate::{
header::{stdio, stdlib},
header::{libgen, stdio, stdlib},
ld_so,
platform::{self, new_mspace, types::*, Pal, Sys},
ALLOCATOR,
......@@ -141,6 +141,11 @@ pub unsafe extern "C" fn relibc_start(sp: &'static Stack) -> ! {
let argv = sp.argv();
platform::inner_argv = copy_string_array(argv, argc as usize);
platform::argv = platform::inner_argv.as_mut_ptr();
// Special code for program_invocation_name and program_invocation_short_name
if let Some(arg) = platform::inner_argv.get(0) {
platform::program_invocation_name = *arg;
platform::program_invocation_short_name = libgen::basename(*arg);
}
// Set up envp
let envp = sp.envp();
......
......@@ -7,7 +7,9 @@ int main(int argc, char **argv) {
puts(program_invocation_name);
puts(program_invocation_short_name);
program_invocation_name = "yes, you can change this";
argv[0] = "changed to argv[0]";
program_invocation_name = "changed to program_invocation_name";
program_invocation_short_name = "changed to program_invocation_short_name";
puts(argv[0]);
puts(program_invocation_name);
......
bins_static/errno
bins_static/errno
errno
yes, you can change this
yes, you can change this
yes, you can change this
changed to argv[0]
changed to program_invocation_name
changed to program_invocation_short_name
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment