diff options
| author | bors <bors@rust-lang.org> | 2018-01-06 02:36:41 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2018-01-06 02:36:41 +0000 |
| commit | 8d370ec908bf210266f1d9028a7c7a500cea45f0 (patch) | |
| tree | d72a92a8f31cfc7081a6883267647fc612fa1284 /src/libstd | |
| parent | b98fd524eca6dca5c4788f0d20becb10e099b876 (diff) | |
| parent | 35d15554bd5d10655ae9f7602721781ab2d78fea (diff) | |
| download | rust-8d370ec908bf210266f1d9028a7c7a500cea45f0.tar.gz rust-8d370ec908bf210266f1d9028a7c7a500cea45f0.zip | |
Auto merge of #47225 - GuillaumeGomez:rollup, r=GuillaumeGomez
Rollup of 5 pull requests - Successful merges: #46987, #47165, #47173, #47202, #47216 - Failed merges:
Diffstat (limited to 'src/libstd')
| -rw-r--r-- | src/libstd/env.rs | 19 | ||||
| -rw-r--r-- | src/libstd/io/mod.rs | 2 | ||||
| -rw-r--r-- | src/libstd/sys/unix/args.rs | 39 |
3 files changed, 28 insertions, 32 deletions
diff --git a/src/libstd/env.rs b/src/libstd/env.rs index 457c6e1409d..ed34c1204b3 100644 --- a/src/libstd/env.rs +++ b/src/libstd/env.rs @@ -571,8 +571,11 @@ pub fn temp_dir() -> PathBuf { /// Returns the full filesystem path of the current running executable. /// -/// The path returned is not necessarily a "real path" of the executable as -/// there may be intermediate symlinks. +/// # Platform-specific behavior +/// +/// If the executable was invoked through a symbolic link, some platforms will +/// return the path of the symbolic link and other platforms will return the +/// path of the symbolic link’s target. /// /// # Errors /// @@ -599,14 +602,14 @@ pub fn temp_dir() -> PathBuf { /// Ok("/home/alex/foo") /// ``` /// -/// And you make a symbolic link of the program: +/// And you make a hard link of the program: /// /// ```bash /// $ ln foo bar /// ``` /// -/// When you run it, you won't get the original executable, you'll get the -/// symlink: +/// When you run it, you won’t get the path of the original executable, you’ll +/// get the path of the hard link: /// /// ```bash /// $ ./bar @@ -614,9 +617,9 @@ pub fn temp_dir() -> PathBuf { /// ``` /// /// This sort of behavior has been known to [lead to privilege escalation] when -/// used incorrectly, for example. +/// used incorrectly. /// -/// [lead to privilege escalation]: http://securityvulns.com/Wdocument183.html +/// [lead to privilege escalation]: https://securityvulns.com/Wdocument183.html /// /// # Examples /// @@ -625,7 +628,7 @@ pub fn temp_dir() -> PathBuf { /// /// match env::current_exe() { /// Ok(exe_path) => println!("Path of this executable is: {}", -/// exe_path.display()), +/// exe_path.display()), /// Err(e) => println!("failed to get current exe path: {}", e), /// }; /// ``` diff --git a/src/libstd/io/mod.rs b/src/libstd/io/mod.rs index e9b707c57eb..ad9cf1eed70 100644 --- a/src/libstd/io/mod.rs +++ b/src/libstd/io/mod.rs @@ -601,7 +601,7 @@ pub trait Read { read_to_end(self, buf) } - /// Read all bytes until EOF in this source, placing them into `buf`. + /// Read all bytes until EOF in this source, appending them to `buf`. /// /// If successful, this function returns the number of bytes which were read /// and appended to `buf`. diff --git a/src/libstd/sys/unix/args.rs b/src/libstd/sys/unix/args.rs index 72169773df5..e1c7ffc19e5 100644 --- a/src/libstd/sys/unix/args.rs +++ b/src/libstd/sys/unix/args.rs @@ -69,7 +69,7 @@ impl DoubleEndedIterator for Args { target_os = "fuchsia"))] mod imp { use os::unix::prelude::*; - use mem; + use ptr; use ffi::{CStr, OsString}; use marker::PhantomData; use libc; @@ -77,49 +77,42 @@ mod imp { use sys_common::mutex::Mutex; - static mut GLOBAL_ARGS_PTR: usize = 0; + static mut ARGC: isize = 0; + static mut ARGV: *const *const u8 = ptr::null(); 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(); - LOCK.lock(); - let ptr = get_global_ptr(); - assert!((*ptr).is_none()); - (*ptr) = Some(box args); + ARGC = argc; + ARGV = argv; LOCK.unlock(); } pub unsafe fn cleanup() { LOCK.lock(); - *get_global_ptr() = None; + ARGC = 0; + ARGV = ptr::null(); LOCK.unlock(); } 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 } + Args { + iter: clone().into_iter(), + _dont_send_or_sync_me: PhantomData + } } - fn clone() -> Option<Vec<Vec<u8>>> { + fn clone() -> Vec<OsString> { unsafe { LOCK.lock(); - let ptr = get_global_ptr(); - let ret = (*ptr).as_ref().map(|s| (**s).clone()); + let ret = (0..ARGC).map(|i| { + let cstr = CStr::from_ptr(*ARGV.offset(i) as *const libc::c_char); + OsStringExt::from_vec(cstr.to_bytes().to_vec()) + }).collect(); LOCK.unlock(); return ret } } - - fn get_global_ptr() -> *mut Option<Box<Vec<Vec<u8>>>> { - unsafe { mem::transmute(&GLOBAL_ARGS_PTR) } - } - } #[cfg(any(target_os = "macos", |
