///
/// Invalid UTF-8 bytes are replaced with \uFFFD. See `str::from_utf8_lossy()`
/// for details.
-pub fn env() -> ~[(~str,~str)] {
+pub fn env() -> Vec<(~str,~str)> {
env_as_bytes().move_iter().map(|(k,v)| {
let k = str::from_utf8_lossy(k).into_owned();
let v = str::from_utf8_lossy(v).into_owned();
/// Returns a vector of (variable, value) byte-vector pairs for all the
/// environment variables of the current process.
-pub fn env_as_bytes() -> ~[(~[u8],~[u8])] {
+pub fn env_as_bytes() -> Vec<(~[u8],~[u8])> {
unsafe {
#[cfg(windows)]
unsafe fn get_env_pairs() -> Vec<~[u8]> {
fn env_convert(input: Vec<~[u8]>) -> Vec<(~[u8], ~[u8])> {
let mut pairs = Vec::new();
for p in input.iter() {
- let vs: ~[&[u8]] = p.splitn(1, |b| *b == '=' as u8).collect();
- let key = vs[0].to_owned();
- let val = if vs.len() < 2 { box [] } else { vs[1].to_owned() };
+ let mut it = p.splitn(1, |b| *b == '=' as u8);
+ let key = it.next().unwrap().to_owned();
+ let val = it.next().unwrap_or(&[]).to_owned();
pairs.push((key, val));
}
pairs
}
with_env_lock(|| {
let unparsed_environ = get_env_pairs();
- env_convert(unparsed_environ).move_iter().collect()
+ env_convert(unparsed_environ)
})
}
}
pub fn self_exe_name() -> Option<Path> {
#[cfg(target_os = "freebsd")]
- fn load_self() -> Option<~[u8]> {
+ fn load_self() -> Option<Vec<u8>> {
unsafe {
use libc::funcs::bsd44::*;
use libc::consts::os::extra::*;
if err != 0 { return None; }
if sz == 0 { return None; }
v.set_len(sz as uint - 1); // chop off trailing NUL
- Some(v.move_iter().collect())
+ Some(v)
}
}
#[cfg(target_os = "linux")]
#[cfg(target_os = "android")]
- fn load_self() -> Option<~[u8]> {
+ fn load_self() -> Option<Vec<u8>> {
use std::io;
match io::fs::readlink(&Path::new("/proc/self/exe")) {
- Ok(path) => Some(path.as_vec().to_owned()),
+ Ok(path) => Some(path.into_vec()),
Err(..) => None
}
}
#[cfg(target_os = "macos")]
- fn load_self() -> Option<~[u8]> {
+ fn load_self() -> Option<Vec<u8>> {
unsafe {
use libc::funcs::extra::_NSGetExecutablePath;
let mut sz: u32 = 0;
let err = _NSGetExecutablePath(v.as_mut_ptr() as *mut i8, &mut sz);
if err != 0 { return None; }
v.set_len(sz as uint - 1); // chop off trailing NUL
- Some(v.move_iter().collect())
+ Some(v)
}
}
#[cfg(windows)]
- fn load_self() -> Option<~[u8]> {
+ fn load_self() -> Option<Vec<u8>> {
use str::OwnedStr;
unsafe {
use os::win32::fill_utf16_buf_and_decode;
fill_utf16_buf_and_decode(|buf, sz| {
libc::GetModuleFileNameW(0u as libc::DWORD, buf, sz)
- }).map(|s| s.into_bytes())
+ }).map(|s| s.into_strbuf().into_bytes())
}
}
}
#[cfg(target_os = "macos")]
-unsafe fn load_argc_and_argv(argc: int, argv: **c_char) -> ~[~[u8]] {
+unsafe fn load_argc_and_argv(argc: int, argv: **c_char) -> Vec<~[u8]> {
use c_str::CString;
Vec::from_fn(argc as uint, |i| {
CString::new(*argv.offset(i as int), false).as_bytes_no_nul().to_owned()
- }).move_iter().collect()
+ })
}
/**
* Returns a list of the command line arguments.
*/
#[cfg(target_os = "macos")]
-fn real_args_as_bytes() -> ~[~[u8]] {
+fn real_args_as_bytes() -> Vec<~[u8]> {
unsafe {
let (argc, argv) = (*_NSGetArgc() as int,
*_NSGetArgv() as **c_char);
#[cfg(target_os = "linux")]
#[cfg(target_os = "android")]
#[cfg(target_os = "freebsd")]
-fn real_args_as_bytes() -> ~[~[u8]] {
+fn real_args_as_bytes() -> Vec<~[u8]> {
use rt;
match rt::args::clone() {
}
#[cfg(not(windows))]
-fn real_args() -> ~[~str] {
+fn real_args() -> Vec<~str> {
real_args_as_bytes().move_iter().map(|v| str::from_utf8_lossy(v).into_owned()).collect()
}
#[cfg(windows)]
-fn real_args() -> ~[~str] {
+fn real_args() -> Vec<~str> {
use slice;
use option::Expect;
LocalFree(szArgList as *c_void);
}
- return args.move_iter().collect();
+ return args
}
#[cfg(windows)]
-fn real_args_as_bytes() -> ~[~[u8]] {
+fn real_args_as_bytes() -> Vec<~[u8]> {
real_args().move_iter().map(|s| s.into_bytes()).collect()
}
///
/// The arguments are interpreted as utf-8, with invalid bytes replaced with \uFFFD.
/// See `str::from_utf8_lossy` for details.
-pub fn args() -> ~[~str] {
+pub fn args() -> Vec<~str> {
real_args()
}
/// Returns the arguments which this program was started with (normally passed
/// via the command line) as byte vectors.
-pub fn args_as_bytes() -> ~[~[u8]] {
+pub fn args_as_bytes() -> Vec<~[u8]> {
real_args_as_bytes()
}