3 use crate::ffi::OsString;
4 use crate::marker::PhantomData;
5 use crate::os::wasi::ffi::OsStringExt;
9 static mut ARGC: isize = 0;
10 static mut ARGV: *const *const u8 = ptr::null();
12 #[cfg(not(target_feature = "atomics"))]
13 pub unsafe fn args_lock() -> impl Any {
14 // No need for a lock if we're single-threaded, but this function will need
15 // to get implemented for multi-threaded scenarios
18 pub unsafe fn init(argc: isize, argv: *const *const u8) {
19 let _guard = args_lock();
24 pub unsafe fn cleanup() {
25 let _guard = args_lock();
31 iter: vec::IntoIter<OsString>,
32 _dont_send_or_sync_me: PhantomData<*mut ()>,
35 /// Returns the command line arguments
36 pub fn args() -> Args {
38 let _guard = args_lock();
41 let cstr = CStr::from_ptr(*ARGV.offset(i) as *const libc::c_char);
42 OsStringExt::from_vec(cstr.to_bytes().to_vec())
46 iter: args.into_iter(),
47 _dont_send_or_sync_me: PhantomData,
53 pub fn inner_debug(&self) -> &[OsString] {
58 impl Iterator for Args {
60 fn next(&mut self) -> Option<OsString> {
63 fn size_hint(&self) -> (usize, Option<usize>) {
68 impl ExactSizeIterator for Args {
69 fn len(&self) -> usize {
74 impl DoubleEndedIterator for Args {
75 fn next_back(&mut self) -> Option<OsString> {