diff options
| author | Vivian Lim <[email protected]> | 2021-02-06 22:11:59 -0800 |
|---|---|---|
| committer | Vivian Lim <[email protected]> | 2021-02-06 22:11:59 -0800 |
| commit | 64423f0e34cc4a7d78c15b345b3b8f58243d8286 (patch) | |
| tree | cc20e2e7f0fc35abf470e20e61d3d48f0d954f3b /ctr-std/src/sys/redox/args.rs | |
| parent | Support libctru 2.0 (diff) | |
| download | archived-ctru-rs-64423f0e34cc4a7d78c15b345b3b8f58243d8286.tar.xz archived-ctru-rs-64423f0e34cc4a7d78c15b345b3b8f58243d8286.zip | |
Delete ctr-std to use my fork of the rust repo instead
Diffstat (limited to 'ctr-std/src/sys/redox/args.rs')
| -rw-r--r-- | ctr-std/src/sys/redox/args.rs | 107 |
1 files changed, 0 insertions, 107 deletions
diff --git a/ctr-std/src/sys/redox/args.rs b/ctr-std/src/sys/redox/args.rs deleted file mode 100644 index 556ed77..0000000 --- a/ctr-std/src/sys/redox/args.rs +++ /dev/null @@ -1,107 +0,0 @@ -// Copyright 2016 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or -// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license -// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -//! Global initialization and retrieval of command line arguments. -//! -//! On some platforms these are stored during runtime startup, -//! and on some they are retrieved from the system on demand. - -#![allow(dead_code)] // runtime init functions not used during testing - -use ffi::OsString; -use marker::PhantomData; -use vec; - -/// One-time global initialization. -pub unsafe fn init(argc: isize, argv: *const *const u8) { imp::init(argc, argv) } - -/// One-time global cleanup. -pub unsafe fn cleanup() { imp::cleanup() } - -/// Returns the command line arguments -pub fn args() -> Args { - imp::args() -} - -pub struct Args { - iter: vec::IntoIter<OsString>, - _dont_send_or_sync_me: PhantomData<*mut ()>, -} - -impl Args { - pub fn inner_debug(&self) -> &[OsString] { - self.iter.as_slice() - } -} - -impl Iterator for Args { - type Item = OsString; - fn next(&mut self) -> Option<OsString> { self.iter.next() } - fn size_hint(&self) -> (usize, Option<usize>) { self.iter.size_hint() } -} - -impl ExactSizeIterator for Args { - fn len(&self) -> usize { self.iter.len() } -} - -impl DoubleEndedIterator for Args { - fn next_back(&mut self) -> Option<OsString> { self.iter.next_back() } -} - -mod imp { - use os::unix::prelude::*; - use mem; - use ffi::{CStr, OsString}; - use marker::PhantomData; - use libc; - use super::Args; - - use sys_common::mutex::Mutex; - - static mut GLOBAL_ARGS_PTR: usize = 0; - static LOCK: Mutex = Mutex::new(); - - pub unsafe fn init(argc: isize, argv: *const *const u8) { - let args = (0..argc).map(|i| { - CStr::from_ptr(*argv.offset(i) as *const libc::c_char).to_bytes().to_vec() - }).collect(); - - let _guard = LOCK.lock(); - let ptr = get_global_ptr(); - assert!((*ptr).is_none()); - (*ptr) = Some(box args); - } - - pub unsafe fn cleanup() { - let _guard = LOCK.lock(); - *get_global_ptr() = None; - } - - pub fn args() -> Args { - let bytes = clone().unwrap_or(Vec::new()); - let v: Vec<OsString> = bytes.into_iter().map(|v| { - OsStringExt::from_vec(v) - }).collect(); - Args { iter: v.into_iter(), _dont_send_or_sync_me: PhantomData } - } - - fn clone() -> Option<Vec<Vec<u8>>> { - unsafe { - let _guard = LOCK.lock(); - let ptr = get_global_ptr(); - (*ptr).as_ref().map(|s| (**s).clone()) - } - } - - unsafe fn get_global_ptr() -> *mut Option<Box<Vec<Vec<u8>>>> { - mem::transmute(&GLOBAL_ARGS_PTR) - } - -} |