diff --git a/src/header/stdlib/mod.rs b/src/header/stdlib/mod.rs index a873109daf..94d9b43736 100644 --- a/src/header/stdlib/mod.rs +++ b/src/header/stdlib/mod.rs @@ -457,6 +457,23 @@ pub unsafe extern "C" fn getenv(name: *const c_char) -> *mut c_char { .unwrap_or(ptr::null_mut()) } +#[unsafe(no_mangle)] +pub unsafe extern "C" fn getprogname() -> *const c_char { + let full = crate::platform::program_invocation_name; + if full.is_null() { + return c"".as_ptr() as *const c_char; + } + let mut base = full; + let mut i = full; + while unsafe { *i } != 0 { + if unsafe { *i } == b'/' as c_char { + base = unsafe { i.add(1) }; + } + i = unsafe { i.add(1) }; + } + base +} + /// See . #[unsafe(no_mangle)] pub unsafe extern "C" fn getsubopt(