1 use crate::ffi::OsString;
2 use crate::marker::PhantomData;
5 /// One-time global initialization.
6 pub unsafe fn init(argc: isize, argv: *const *const u8) {
10 /// One-time global cleanup.
11 pub unsafe fn cleanup() {
15 /// Returns the command line arguments
16 pub fn args() -> Args {
21 iter: vec::IntoIter<OsString>,
22 _dont_send_or_sync_me: PhantomData<*mut ()>,
26 pub fn inner_debug(&self) -> &[OsString] {
31 impl Iterator for Args {
33 fn next(&mut self) -> Option<OsString> {
36 fn size_hint(&self) -> (usize, Option<usize>) {
41 impl ExactSizeIterator for Args {
42 fn len(&self) -> usize {
47 impl DoubleEndedIterator for Args {
48 fn next_back(&mut self) -> Option<OsString> {
55 use crate::ffi::{CStr, OsString};
56 use crate::marker::PhantomData;
58 use crate::sys_common::os_str_bytes::*;
60 use crate::sys_common::mutex::Mutex;
62 static mut ARGC: isize = 0;
63 static mut ARGV: *const *const u8 = ptr::null();
64 static LOCK: Mutex = Mutex::new();
66 pub unsafe fn init(argc: isize, argv: *const *const u8) {
67 let _guard = LOCK.lock();
72 pub unsafe fn cleanup() {
73 let _guard = LOCK.lock();
78 pub fn args() -> Args {
79 Args { iter: clone().into_iter(), _dont_send_or_sync_me: PhantomData }
82 fn clone() -> Vec<OsString> {
84 let _guard = LOCK.lock();
87 let cstr = CStr::from_ptr(*ARGV.offset(i) as *const i8);
88 OsStringExt::from_vec(cstr.to_bytes().to_vec())