1 use crate::ffi::OsString;
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>,
24 impl fmt::Debug for Args {
25 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
26 self.iter.as_slice().fmt(f)
30 impl !Send for Args {}
31 impl !Sync for Args {}
33 impl Iterator for Args {
35 fn next(&mut self) -> Option<OsString> {
38 fn size_hint(&self) -> (usize, Option<usize>) {
43 impl ExactSizeIterator for Args {
44 fn len(&self) -> usize {
49 impl DoubleEndedIterator for Args {
50 fn next_back(&mut self) -> Option<OsString> {
57 use crate::ffi::{CStr, OsString};
58 use crate::os::unix::ffi::OsStringExt;
61 use crate::sys_common::mutex::StaticMutex;
63 static mut ARGC: isize = 0;
64 static mut ARGV: *const *const u8 = ptr::null();
65 static LOCK: StaticMutex = StaticMutex::new();
67 pub unsafe fn init(argc: isize, argv: *const *const u8) {
68 let _guard = LOCK.lock();
73 pub unsafe fn cleanup() {
74 let _guard = LOCK.lock();
79 pub fn args() -> Args {
80 Args { iter: clone().into_iter() }
83 fn clone() -> Vec<OsString> {
85 let _guard = LOCK.lock();
88 let cstr = CStr::from_ptr(*ARGV.offset(i) as *const i8);
89 OsStringExt::from_vec(cstr.to_bytes().to_vec())