Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 3 additions & 9 deletions library/std/src/sys/args/unix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,20 +164,14 @@ mod imp {
// of this used `[[NSProcessInfo processInfo] arguments]`.
#[cfg(target_vendor = "apple")]
mod imp {
use crate::ffi::{c_char, c_int};
use crate::ffi::c_char;

pub unsafe fn init(_argc: isize, _argv: *const *const u8) {
// No need to initialize anything in here, `libdyld.dylib` has already
// done the work for us.
}

pub fn argc_argv() -> (isize, *const *const c_char) {
unsafe extern "C" {
// These functions are in crt_externs.h.
fn _NSGetArgc() -> *mut c_int;
fn _NSGetArgv() -> *mut *mut *mut c_char;
}

// SAFETY: The returned pointer points to a static initialized early
// in the program lifetime by `libdyld.dylib`, and as such is always
// valid.
Expand All @@ -187,9 +181,9 @@ mod imp {
// doesn't exist a lock that we can take. Instead, it is generally
// expected that it's only modified in `main` / before other code
// runs, so reading this here should be fine.
let argc = unsafe { _NSGetArgc().read() };
let argc = unsafe { libc::_NSGetArgc().read() };
// SAFETY: Same as above.
let argv = unsafe { _NSGetArgv().read() };
let argv = unsafe { libc::_NSGetArgv().read() };

// Cast from `*mut *mut c_char` to `*const *const c_char`
(argc as isize, argv.cast())
Expand Down
Loading