Verified Commit 1a0edd8e authored by Jeremy Soller's avatar Jeremy Soller
Browse files

Add program_invocation_short_name

parent 2f3987dd
...@@ -9,6 +9,7 @@ extern "C" { ...@@ -9,6 +9,7 @@ extern "C" {
#define errno (*__errno_location()) #define errno (*__errno_location())
#define program_invocation_name (*__program_invocation_name()) #define program_invocation_name (*__program_invocation_name())
#define program_invocation_short_name (*__program_invocation_short_name())
#ifdef __cplusplus #ifdef __cplusplus
} // extern "C" } // extern "C"
......
...@@ -18,6 +18,23 @@ pub unsafe extern "C" fn __program_invocation_name() -> *mut *mut c_char { ...@@ -18,6 +18,23 @@ pub unsafe extern "C" fn __program_invocation_name() -> *mut *mut c_char {
&mut platform::inner_argv[0] &mut platform::inner_argv[0]
} }
#[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;
}
}
}
}
pub const EPERM: c_int = 1; /* Operation not permitted */ pub const EPERM: c_int = 1; /* Operation not permitted */
pub const ENOENT: c_int = 2; /* No such file or directory */ pub const ENOENT: c_int = 2; /* No such file or directory */
pub const ESRCH: c_int = 3; /* No such process */ pub const ESRCH: c_int = 3; /* No such process */
......
...@@ -5,9 +5,11 @@ ...@@ -5,9 +5,11 @@
int main(int argc, char **argv) { int main(int argc, char **argv) {
puts(argv[0]); puts(argv[0]);
puts(program_invocation_name); puts(program_invocation_name);
puts(program_invocation_short_name);
program_invocation_name = "yes, you can change this"; program_invocation_name = "yes, you can change this";
puts(argv[0]); puts(argv[0]);
puts(program_invocation_name); puts(program_invocation_name);
puts(program_invocation_short_name);
} }
bins_dynamic/errno bins_dynamic/errno
bins_dynamic/errno bins_dynamic/errno
errno
yes, you can change this
yes, you can change this yes, you can change this
yes, you can change this yes, you can change this
bins_static/errno bins_static/errno
bins_static/errno bins_static/errno
errno
yes, you can change this
yes, you can change this yes, you can change this
yes, you can change this yes, you can change this
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment