diff options
Diffstat (limited to 'src/libstd/sys')
37 files changed, 172 insertions, 196 deletions
diff --git a/src/libstd/sys/cloudabi/abi/bitflags.rs b/src/libstd/sys/cloudabi/abi/bitflags.rs index 306936213ed..2383277ad72 100644 --- a/src/libstd/sys/cloudabi/abi/bitflags.rs +++ b/src/libstd/sys/cloudabi/abi/bitflags.rs @@ -21,9 +21,6 @@ // OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF // SUCH DAMAGE. -// Appease Rust's tidy. -// ignore-license - #[cfg(feature = "bitflags")] use bitflags::bitflags; diff --git a/src/libstd/sys/cloudabi/abi/cloudabi.rs b/src/libstd/sys/cloudabi/abi/cloudabi.rs index d113a7b3d60..b02faf1830c 100644 --- a/src/libstd/sys/cloudabi/abi/cloudabi.rs +++ b/src/libstd/sys/cloudabi/abi/cloudabi.rs @@ -26,7 +26,6 @@ // Source: https://github.com/NuxiNL/cloudabi // Appease Rust's tidy. -// ignore-license // ignore-tidy-linelength //! **PLEASE NOTE: This entire crate including this diff --git a/src/libstd/sys/hermit/os.rs b/src/libstd/sys/hermit/os.rs index 5999fdd4f8d..78eabf8f81e 100644 --- a/src/libstd/sys/hermit/os.rs +++ b/src/libstd/sys/hermit/os.rs @@ -6,7 +6,6 @@ use crate::io; use crate::marker::PhantomData; use crate::memchr; use crate::path::{self, PathBuf}; -use crate::ptr; use crate::str; use crate::sync::Mutex; use crate::sys::hermit::abi; @@ -77,13 +76,17 @@ pub fn init_environment(env: *const *const i8) { unsafe { ENV = Some(Mutex::new(HashMap::new())); + if env.is_null() { + return; + } + let mut guard = ENV.as_ref().unwrap().lock().unwrap(); let mut environ = env; - while environ != ptr::null() && *environ != ptr::null() { + while !(*environ).is_null() { if let Some((key, value)) = parse(CStr::from_ptr(*environ).to_bytes()) { guard.insert(key, value); } - environ = environ.offset(1); + environ = environ.add(1); } } diff --git a/src/libstd/sys/hermit/thread_local.rs b/src/libstd/sys/hermit/thread_local.rs index ba967c7676c..c6f8adb2162 100644 --- a/src/libstd/sys/hermit/thread_local.rs +++ b/src/libstd/sys/hermit/thread_local.rs @@ -18,14 +18,14 @@ static KEYS_LOCK: Mutex = Mutex::new(); static mut LOCALS: *mut BTreeMap<Key, *mut u8> = ptr::null_mut(); unsafe fn keys() -> &'static mut BTreeMap<Key, Option<Dtor>> { - if KEYS == ptr::null_mut() { + if KEYS.is_null() { KEYS = Box::into_raw(Box::new(BTreeMap::new())); } &mut *KEYS } unsafe fn locals() -> &'static mut BTreeMap<Key, *mut u8> { - if LOCALS == ptr::null_mut() { + if LOCALS.is_null() { LOCALS = Box::into_raw(Box::new(BTreeMap::new())); } &mut *LOCALS diff --git a/src/libstd/sys/sgx/abi/entry.S b/src/libstd/sys/sgx/abi/entry.S index a3e059e8131..ed4db287229 100644 --- a/src/libstd/sys/sgx/abi/entry.S +++ b/src/libstd/sys/sgx/abi/entry.S @@ -30,6 +30,14 @@ IMAGE_BASE: /* We can store a bunch of data in the gap between MXCSR and the XSAVE header */ +/* MXCSR initialization value for ABI */ +.Lmxcsr_init: + .int 0x1f80 + +/* x87 FPU control word initialization value for ABI */ +.Lfpucw_init: + .int 0x037f + /* The following symbols point at read-only data that will be filled in by the */ /* post-linker. */ @@ -134,6 +142,19 @@ elf_entry: ud2 /* should not be reached */ /* end elf_entry */ +/* This code needs to be called *after* the enclave stack has been setup. */ +/* There are 3 places where this needs to happen, so this is put in a macro. */ +.macro entry_sanitize_final +/* Sanitize rflags received from user */ +/* - DF flag: x86-64 ABI requires DF to be unset at function entry/exit */ +/* - AC flag: AEX on misaligned memory accesses leaks side channel info */ + pushfq + andq $~0x40400, (%rsp) + popfq + bt $0,.Laborted(%rip) + jc .Lreentry_panic +.endm + .text .global sgx_entry .type sgx_entry,function @@ -150,25 +171,18 @@ sgx_entry: stmxcsr %gs:tcsls_user_mxcsr fnstcw %gs:tcsls_user_fcw -/* reset user state */ -/* - DF flag: x86-64 ABI requires DF to be unset at function entry/exit */ -/* - AC flag: AEX on misaligned memory accesses leaks side channel info */ - pushfq - andq $~0x40400, (%rsp) - popfq - /* check for debug buffer pointer */ testb $0xff,DEBUG(%rip) jz .Lskip_debug_init mov %r10,%gs:tcsls_debug_panic_buf_ptr .Lskip_debug_init: -/* check for abort */ - bt $0,.Laborted(%rip) - jc .Lreentry_panic /* check if returning from usercall */ mov %gs:tcsls_last_rsp,%r11 test %r11,%r11 jnz .Lusercall_ret +/* reset user state */ + ldmxcsr .Lmxcsr_init(%rip) + fldcw .Lfpucw_init(%rip) /* setup stack */ mov %gs:tcsls_tos,%rsp /* initially, RSP is not set to the correct value */ /* here. This is fixed below under "adjust stack". */ @@ -179,6 +193,7 @@ sgx_entry: lea IMAGE_BASE(%rip),%rax add %rax,%rsp mov %rsp,%gs:tcsls_tos + entry_sanitize_final /* call tcs_init */ /* store caller-saved registers in callee-saved registers */ mov %rdi,%rbx @@ -194,7 +209,10 @@ sgx_entry: mov %r13,%rdx mov %r14,%r8 mov %r15,%r9 + jmp .Lafter_init .Lskip_init: + entry_sanitize_final +.Lafter_init: /* call into main entry point */ load_tcsls_flag_secondary_bool cx /* RCX = entry() argument: secondary: bool */ call entry /* RDI, RSI, RDX, R8, R9 passed in from userspace */ @@ -295,6 +313,7 @@ usercall: ldmxcsr (%rsp) fldcw 4(%rsp) add $8, %rsp + entry_sanitize_final pop %rbx pop %rbp pop %r12 diff --git a/src/libstd/sys/sgx/abi/tls.rs b/src/libstd/sys/sgx/abi/tls.rs index 81a766e367d..2b0485c4f03 100644 --- a/src/libstd/sys/sgx/abi/tls.rs +++ b/src/libstd/sys/sgx/abi/tls.rs @@ -70,7 +70,7 @@ impl<'a> Drop for ActiveTls<'a> { any_non_null_dtor = false; for (value, dtor) in TLS_KEY_IN_USE.iter().filter_map(&value_with_destructor) { let value = value.replace(ptr::null_mut()); - if value != ptr::null_mut() { + if !value.is_null() { any_non_null_dtor = true; unsafe { dtor(value) } } diff --git a/src/libstd/sys/sgx/os.rs b/src/libstd/sys/sgx/os.rs index 6ed7a2f2044..56fc84b4a3f 100644 --- a/src/libstd/sys/sgx/os.rs +++ b/src/libstd/sys/sgx/os.rs @@ -19,7 +19,7 @@ pub fn errno() -> i32 { pub fn error_string(errno: i32) -> String { if errno == RESULT_SUCCESS { - "operation succesful".into() + "operation successful".into() } else if ((Error::UserRangeStart as _)..=(Error::UserRangeEnd as _)).contains(&errno) { format!("user-specified error {:08x}", errno) } else { diff --git a/src/libstd/sys/sgx/rwlock.rs b/src/libstd/sys/sgx/rwlock.rs index fda2bb504d4..722b4f5e0ba 100644 --- a/src/libstd/sys/sgx/rwlock.rs +++ b/src/libstd/sys/sgx/rwlock.rs @@ -10,10 +10,10 @@ pub struct RWLock { writer: SpinMutex<WaitVariable<bool>>, } -// Below is to check at compile time, that RWLock has size of 128 bytes. +// Check at compile time that RWLock size matches C definition (see test_c_rwlock_initializer below) #[allow(dead_code)] unsafe fn rw_lock_size_assert(r: RWLock) { - mem::transmute::<RWLock, [u8; 128]>(r); + mem::transmute::<RWLock, [u8; 144]>(r); } impl RWLock { @@ -210,15 +210,17 @@ mod tests { // be changed too. #[test] fn test_c_rwlock_initializer() { + #[rustfmt::skip] const RWLOCK_INIT: &[u8] = &[ - 0x1, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, - 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x3, 0x0, - 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, - 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x1, 0x0, 0x0, 0x0, - 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, - 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x3, 0x0, 0x0, 0x0, 0x0, 0x0, - 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, - 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, + /* 0x00 */ 0x1, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, + /* 0x10 */ 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x2, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, + /* 0x20 */ 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, + /* 0x30 */ 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, + /* 0x40 */ 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x1, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, + /* 0x50 */ 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, + /* 0x60 */ 0x2, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, + /* 0x70 */ 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, + /* 0x80 */ 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, ]; #[inline(never)] @@ -239,7 +241,7 @@ mod tests { zero_stack(); let mut init = MaybeUninit::<RWLock>::zeroed(); rwlock_new(&mut init); - assert_eq!(mem::transmute::<_, [u8; 128]>(init.assume_init()).as_slice(), RWLOCK_INIT) + assert_eq!(mem::transmute::<_, [u8; 144]>(init.assume_init()).as_slice(), RWLOCK_INIT) }; } } diff --git a/src/libstd/sys/unix/android.rs b/src/libstd/sys/unix/android.rs index c5e9d66e85e..8fc2599f0d7 100644 --- a/src/libstd/sys/unix/android.rs +++ b/src/libstd/sys/unix/android.rs @@ -93,12 +93,12 @@ pub fn ftruncate64(fd: c_int, size: u64) -> io::Result<()> { unsafe { match ftruncate64.get() { - Some(f) => cvt_r(|| f(fd, size as i64)).map(|_| ()), + Some(f) => cvt_r(|| f(fd, size as i64)).map(drop), None => { if size > i32::max_value() as u64 { Err(io::Error::new(io::ErrorKind::InvalidInput, "cannot truncate >2GB")) } else { - cvt_r(|| ftruncate(fd, size as i32)).map(|_| ()) + cvt_r(|| ftruncate(fd, size as i32)).map(drop) } } } @@ -107,7 +107,7 @@ pub fn ftruncate64(fd: c_int, size: u64) -> io::Result<()> { #[cfg(target_pointer_width = "64")] pub fn ftruncate64(fd: c_int, size: u64) -> io::Result<()> { - unsafe { cvt_r(|| ftruncate(fd, size as i64)).map(|_| ()) } + unsafe { cvt_r(|| ftruncate(fd, size as i64)).map(drop) } } #[cfg(target_pointer_width = "32")] diff --git a/src/libstd/sys/unix/cmath.rs b/src/libstd/sys/unix/cmath.rs index 2916ebe4440..f327b69fc75 100644 --- a/src/libstd/sys/unix/cmath.rs +++ b/src/libstd/sys/unix/cmath.rs @@ -2,7 +2,6 @@ use libc::{c_double, c_float}; -#[link_name = "m"] extern "C" { pub fn acos(n: c_double) -> c_double; pub fn acosf(n: c_float) -> c_float; diff --git a/src/libstd/sys/unix/ext/net.rs b/src/libstd/sys/unix/ext/net.rs index e0e6e02a443..4c3cb67c9ee 100644 --- a/src/libstd/sys/unix/ext/net.rs +++ b/src/libstd/sys/unix/ext/net.rs @@ -902,6 +902,12 @@ impl UnixListener { /// Moves the socket into or out of nonblocking mode. /// + /// This will result in the `accept` operation becoming nonblocking, + /// i.e., immediately returning from their calls. If the IO operation is + /// successful, `Ok` is returned and no further action is required. If the + /// IO operation could not be completed and needs to be retried, an error + /// with kind [`io::ErrorKind::WouldBlock`] is returned. + /// /// # Examples /// /// ```no_run @@ -913,6 +919,8 @@ impl UnixListener { /// Ok(()) /// } /// ``` + /// + /// [`io::ErrorKind::WouldBlock`]: ../../../io/enum.ErrorKind.html#variant.WouldBlock #[stable(feature = "unix_socket", since = "1.10.0")] pub fn set_nonblocking(&self, nonblocking: bool) -> io::Result<()> { self.0.set_nonblocking(nonblocking) diff --git a/src/libstd/sys/unix/fs.rs b/src/libstd/sys/unix/fs.rs index 26fb0bf10fe..ab2a871b92d 100644 --- a/src/libstd/sys/unix/fs.rs +++ b/src/libstd/sys/unix/fs.rs @@ -51,23 +51,14 @@ pub use crate::sys_common::fs::remove_dir_all; pub struct File(FileDesc); -// FIXME: This should be available on Linux with all `target_arch` and `target_env`. -// https://github.com/rust-lang/libc/issues/1545 +// FIXME: This should be available on Linux with all `target_env`. +// But currently only glibc exposes `statx` fn and structs. +// We don't want to import unverified raw C structs here directly. +// https://github.com/rust-lang/rust/pull/67774 macro_rules! cfg_has_statx { ({ $($then_tt:tt)* } else { $($else_tt:tt)* }) => { cfg_if::cfg_if! { - if #[cfg(all(target_os = "linux", target_env = "gnu", any( - target_arch = "x86", - target_arch = "arm", - // target_arch = "mips", - target_arch = "powerpc", - target_arch = "x86_64", - // target_arch = "aarch64", - target_arch = "powerpc64", - // target_arch = "mips64", - // target_arch = "s390x", - target_arch = "sparc64", - )))] { + if #[cfg(all(target_os = "linux", target_env = "gnu"))] { $($then_tt)* } else { $($else_tt)* @@ -75,18 +66,7 @@ macro_rules! cfg_has_statx { } }; ($($block_inner:tt)*) => { - #[cfg(all(target_os = "linux", target_env = "gnu", any( - target_arch = "x86", - target_arch = "arm", - // target_arch = "mips", - target_arch = "powerpc", - target_arch = "x86_64", - // target_arch = "aarch64", - target_arch = "powerpc64", - // target_arch = "mips64", - // target_arch = "s390x", - target_arch = "sparc64", - )))] + #[cfg(all(target_os = "linux", target_env = "gnu"))] { $($block_inner)* } @@ -814,7 +794,7 @@ impl File { use crate::convert::TryInto; let size: off64_t = size.try_into().map_err(|e| io::Error::new(io::ErrorKind::InvalidInput, e))?; - cvt_r(|| unsafe { ftruncate64(self.0.raw(), size) }).map(|_| ()) + cvt_r(|| unsafe { ftruncate64(self.0.raw(), size) }).map(drop) } } diff --git a/src/libstd/sys/unix/net.rs b/src/libstd/sys/unix/net.rs index 4c23aabf497..79b0dc02978 100644 --- a/src/libstd/sys/unix/net.rs +++ b/src/libstd/sys/unix/net.rs @@ -324,7 +324,7 @@ impl Socket { pub fn set_nonblocking(&self, nonblocking: bool) -> io::Result<()> { let mut nonblocking = nonblocking as libc::c_int; - cvt(unsafe { libc::ioctl(*self.as_inner(), libc::FIONBIO, &mut nonblocking) }).map(|_| ()) + cvt(unsafe { libc::ioctl(*self.as_inner(), libc::FIONBIO, &mut nonblocking) }).map(drop) } pub fn take_error(&self) -> io::Result<Option<io::Error>> { diff --git a/src/libstd/sys/unix/os.rs b/src/libstd/sys/unix/os.rs index b0b14725344..91f7d1524cc 100644 --- a/src/libstd/sys/unix/os.rs +++ b/src/libstd/sys/unix/os.rs @@ -480,11 +480,13 @@ pub fn env() -> Env { let _guard = env_lock(); let mut environ = *environ(); let mut result = Vec::new(); - while environ != ptr::null() && *environ != ptr::null() { - if let Some(key_value) = parse(CStr::from_ptr(*environ).to_bytes()) { - result.push(key_value); + if !environ.is_null() { + while !(*environ).is_null() { + if let Some(key_value) = parse(CStr::from_ptr(*environ).to_bytes()) { + result.push(key_value); + } + environ = environ.add(1); } - environ = environ.offset(1); } return Env { iter: result.into_iter(), _dont_send_or_sync_me: PhantomData }; } @@ -529,7 +531,7 @@ pub fn setenv(k: &OsStr, v: &OsStr) -> io::Result<()> { unsafe { let _guard = env_lock(); - cvt(libc::setenv(k.as_ptr(), v.as_ptr(), 1)).map(|_| ()) + cvt(libc::setenv(k.as_ptr(), v.as_ptr(), 1)).map(drop) } } @@ -538,7 +540,7 @@ pub fn unsetenv(n: &OsStr) -> io::Result<()> { unsafe { let _guard = env_lock(); - cvt(libc::unsetenv(nbuf.as_ptr())).map(|_| ()) + cvt(libc::unsetenv(nbuf.as_ptr())).map(drop) } } diff --git a/src/libstd/sys/unix/pipe.rs b/src/libstd/sys/unix/pipe.rs index 77fefef8a18..2a861c87801 100644 --- a/src/libstd/sys/unix/pipe.rs +++ b/src/libstd/sys/unix/pipe.rs @@ -99,11 +99,11 @@ pub fn read2(p1: AnonPipe, v1: &mut Vec<u8>, p2: AnonPipe, v2: &mut Vec<u8>) -> if fds[0].revents != 0 && read(&p1, v1)? { p2.set_nonblocking(false)?; - return p2.read_to_end(v2).map(|_| ()); + return p2.read_to_end(v2).map(drop); } if fds[1].revents != 0 && read(&p2, v2)? { p1.set_nonblocking(false)?; - return p1.read_to_end(v1).map(|_| ()); + return p1.read_to_end(v1).map(drop); } } diff --git a/src/libstd/sys/unix/process/process_unix.rs b/src/libstd/sys/unix/process/process_unix.rs index 85c30abe452..07d0fbf61fe 100644 --- a/src/libstd/sys/unix/process/process_unix.rs +++ b/src/libstd/sys/unix/process/process_unix.rs @@ -425,7 +425,7 @@ impl Process { "invalid argument: can't kill an exited process", )) } else { - cvt(unsafe { libc::kill(self.pid, libc::SIGKILL) }).map(|_| ()) + cvt(unsafe { libc::kill(self.pid, libc::SIGKILL) }).map(drop) } } diff --git a/src/libstd/sys/unix/thread.rs b/src/libstd/sys/unix/thread.rs index a5b34eeec28..3ca778354e4 100644 --- a/src/libstd/sys/unix/thread.rs +++ b/src/libstd/sys/unix/thread.rs @@ -426,8 +426,8 @@ pub mod guard { } // glibc >= 2.15 has a __pthread_get_minstack() function that returns -// PTHREAD_STACK_MIN plus however many bytes are needed for thread-local -// storage. We need that information to avoid blowing up when a small stack +// PTHREAD_STACK_MIN plus bytes needed for thread-local storage. +// We need that information to avoid blowing up when a small stack // is created in an application with big thread-local storage requirements. // See #6233 for rationale and details. #[cfg(target_os = "linux")] diff --git a/src/libstd/sys/unix/time.rs b/src/libstd/sys/unix/time.rs index 23104419978..6707f790cab 100644 --- a/src/libstd/sys/unix/time.rs +++ b/src/libstd/sys/unix/time.rs @@ -282,7 +282,6 @@ mod inner { (cfg!(target_os = "linux") && cfg!(target_arch = "x86_64")) || (cfg!(target_os = "linux") && cfg!(target_arch = "x86")) || cfg!(target_os = "fuchsia") - || false // last clause, used so `||` is always trailing above } pub fn checked_sub_instant(&self, other: &Instant) -> Option<Duration> { diff --git a/src/libstd/sys/vxworks/cmath.rs b/src/libstd/sys/vxworks/cmath.rs index 2916ebe4440..f327b69fc75 100644 --- a/src/libstd/sys/vxworks/cmath.rs +++ b/src/libstd/sys/vxworks/cmath.rs @@ -2,7 +2,6 @@ use libc::{c_double, c_float}; -#[link_name = "m"] extern "C" { pub fn acos(n: c_double) -> c_double; pub fn acosf(n: c_float) -> c_float; diff --git a/src/libstd/sys/vxworks/ext/process.rs b/src/libstd/sys/vxworks/ext/process.rs index e535c4aa122..31e691dd136 100644 --- a/src/libstd/sys/vxworks/ext/process.rs +++ b/src/libstd/sys/vxworks/ext/process.rs @@ -2,6 +2,7 @@ #![stable(feature = "rust1", since = "1.0.0")] +use crate::ffi::OsStr; use crate::io; use crate::process; use crate::sys; @@ -105,6 +106,15 @@ pub trait CommandExt { /// cross-platform `spawn` instead. #[stable(feature = "process_exec2", since = "1.9.0")] fn exec(&mut self) -> io::Error; + + /// Set executable argument + /// + /// Set the first process argument, `argv[0]`, to something other than the + /// default executable path. + #[unstable(feature = "process_set_argv0", issue = "66510")] + fn arg0<S>(&mut self, arg: S) -> &mut process::Command + where + S: AsRef<OsStr>; } #[stable(feature = "rust1", since = "1.0.0")] @@ -130,6 +140,14 @@ impl CommandExt for process::Command { fn exec(&mut self) -> io::Error { self.as_inner_mut().exec(sys::process::Stdio::Inherit) } + + fn arg0<S>(&mut self, arg: S) -> &mut process::Command + where + S: AsRef<OsStr>, + { + self.as_inner_mut().set_arg_0(arg.as_ref()); + self + } } /// Unix-specific extensions to [`process::ExitStatus`]. diff --git a/src/libstd/sys/vxworks/fs.rs b/src/libstd/sys/vxworks/fs.rs index 6c2dfb79d6f..68f2c133170 100644 --- a/src/libstd/sys/vxworks/fs.rs +++ b/src/libstd/sys/vxworks/fs.rs @@ -340,7 +340,7 @@ impl File { } pub fn truncate(&self, size: u64) -> io::Result<()> { - return cvt_r(|| unsafe { ftruncate(self.0.raw(), size as off_t) }).map(|_| ()); + return cvt_r(|| unsafe { ftruncate(self.0.raw(), size as off_t) }).map(drop); } pub fn read(&self, buf: &mut [u8]) -> io::Result<usize> { diff --git a/src/libstd/sys/vxworks/mod.rs b/src/libstd/sys/vxworks/mod.rs index f102e4d6adf..12bbfa1d4e1 100644 --- a/src/libstd/sys/vxworks/mod.rs +++ b/src/libstd/sys/vxworks/mod.rs @@ -36,18 +36,10 @@ pub use crate::sys_common::os_str_bytes as os_str; #[cfg(not(test))] pub fn init() { - // By default, some platforms will send a *signal* when an EPIPE error - // would otherwise be delivered. This runtime doesn't install a SIGPIPE - // handler, causing it to kill the program, which isn't exactly what we - // want! - // - // Hence, we set SIGPIPE to ignore when the program starts up in order - // to prevent this problem. + // ignore SIGPIPE unsafe { - reset_sigpipe(); + assert!(signal(libc::SIGPIPE, libc::SIG_IGN) != libc::SIG_ERR); } - - unsafe fn reset_sigpipe() {} } pub use libc::signal; diff --git a/src/libstd/sys/vxworks/net.rs b/src/libstd/sys/vxworks/net.rs index 74cbd246fe8..7d4e5624f7e 100644 --- a/src/libstd/sys/vxworks/net.rs +++ b/src/libstd/sys/vxworks/net.rs @@ -261,7 +261,7 @@ impl Socket { pub fn set_nonblocking(&self, nonblocking: bool) -> io::Result<()> { let mut nonblocking = nonblocking as libc::c_int; - cvt(unsafe { libc::ioctl(*self.as_inner(), libc::FIONBIO, &mut nonblocking) }).map(|_| ()) + cvt(unsafe { libc::ioctl(*self.as_inner(), libc::FIONBIO, &mut nonblocking) }).map(drop) } pub fn take_error(&self) -> io::Result<Option<io::Error>> { diff --git a/src/libstd/sys/vxworks/os.rs b/src/libstd/sys/vxworks/os.rs index 3f207cabf97..1fadf716135 100644 --- a/src/libstd/sys/vxworks/os.rs +++ b/src/libstd/sys/vxworks/os.rs @@ -7,7 +7,6 @@ use crate::marker::PhantomData; use crate::mem; use crate::memchr; use crate::path::{self, Path, PathBuf}; -use crate::ptr; use crate::slice; use crate::str; use crate::sys::cvt; @@ -226,15 +225,15 @@ pub fn env() -> Env { unsafe { let _guard = env_lock(); let mut environ = *environ(); - if environ == ptr::null() { + if environ.is_null() { panic!("os::env() failure getting env string from OS: {}", io::Error::last_os_error()); } let mut result = Vec::new(); - while *environ != ptr::null() { + while !(*environ).is_null() { if let Some(key_value) = parse(CStr::from_ptr(*environ).to_bytes()) { result.push(key_value); } - environ = environ.offset(1); + environ = environ.add(1); } return Env { iter: result.into_iter(), _dont_send_or_sync_me: PhantomData }; } @@ -279,7 +278,7 @@ pub fn setenv(k: &OsStr, v: &OsStr) -> io::Result<()> { unsafe { let _guard = env_lock(); - cvt(libc::setenv(k.as_ptr(), v.as_ptr(), 1)).map(|_| ()) + cvt(libc::setenv(k.as_ptr(), v.as_ptr(), 1)).map(drop) } } @@ -288,7 +287,7 @@ pub fn unsetenv(n: &OsStr) -> io::Result<()> { unsafe { let _guard = env_lock(); - cvt(libc::unsetenv(nbuf.as_ptr())).map(|_| ()) + cvt(libc::unsetenv(nbuf.as_ptr())).map(drop) } } diff --git a/src/libstd/sys/vxworks/pipe.rs b/src/libstd/sys/vxworks/pipe.rs index b72a6554551..0990cb8e83c 100644 --- a/src/libstd/sys/vxworks/pipe.rs +++ b/src/libstd/sys/vxworks/pipe.rs @@ -66,11 +66,11 @@ pub fn read2(p1: AnonPipe, v1: &mut Vec<u8>, p2: AnonPipe, v2: &mut Vec<u8>) -> if fds[0].revents != 0 && read(&p1, v1)? { p2.set_nonblocking_pipe(false)?; - return p2.read_to_end(v2).map(|_| ()); + return p2.read_to_end(v2).map(drop); } if fds[1].revents != 0 && read(&p2, v2)? { p1.set_nonblocking_pipe(false)?; - return p1.read_to_end(v1).map(|_| ()); + return p1.read_to_end(v1).map(drop); } } diff --git a/src/libstd/sys/vxworks/process/process_common.rs b/src/libstd/sys/vxworks/process/process_common.rs index a8139a27537..6d5506bec5f 100644 --- a/src/libstd/sys/vxworks/process/process_common.rs +++ b/src/libstd/sys/vxworks/process/process_common.rs @@ -90,8 +90,8 @@ impl Command { let program = os2c(program, &mut saw_nul); Command { argv: Argv(vec![program.as_ptr(), ptr::null()]), + args: vec![program.clone()], program, - args: Vec::new(), env: Default::default(), cwd: None, uid: None, @@ -104,11 +104,19 @@ impl Command { } } + pub fn set_arg_0(&mut self, arg: &OsStr) { + // Set a new arg0 + let arg = os2c(arg, &mut self.saw_nul); + debug_assert!(self.argv.0.len() > 1); + self.argv.0[0] = arg.as_ptr(); + self.args[0] = arg; + } + pub fn arg(&mut self, arg: &OsStr) { // Overwrite the trailing NULL pointer in `argv` and then add a new null // pointer. let arg = os2c(arg, &mut self.saw_nul); - self.argv.0[self.args.len() + 1] = arg.as_ptr(); + self.argv.0[self.args.len()] = arg.as_ptr(); self.argv.0.push(ptr::null()); // Also make sure we keep track of the owned value to schedule a @@ -133,6 +141,10 @@ impl Command { &self.argv.0 } + pub fn get_program(&self) -> &CStr { + &*self.program + } + #[allow(dead_code)] pub fn get_cwd(&self) -> &Option<CString> { &self.cwd @@ -315,8 +327,12 @@ impl ChildStdio { impl fmt::Debug for Command { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - write!(f, "{:?}", self.program)?; - for arg in &self.args { + if self.program != self.args[0] { + write!(f, "[{:?}] ", self.program)?; + } + write!(f, "{:?}", self.args[0])?; + + for arg in &self.args[1..] { write!(f, " {:?}", arg)?; } Ok(()) diff --git a/src/libstd/sys/vxworks/process/process_vxworks.rs b/src/libstd/sys/vxworks/process/process_vxworks.rs index f926dfeb6d4..f7e84ae3de9 100644 --- a/src/libstd/sys/vxworks/process/process_vxworks.rs +++ b/src/libstd/sys/vxworks/process/process_vxworks.rs @@ -67,7 +67,7 @@ impl Command { let _lock = sys::os::env_lock(); let ret = libc::rtpSpawn( - self.get_argv()[0], // executing program + self.get_program().as_ptr(), self.get_argv().as_ptr() as *mut *const c_char, // argv c_envp as *mut *const c_char, 100 as c_int, // initial priority @@ -138,7 +138,7 @@ impl Process { "invalid argument: can't kill an exited process", )) } else { - cvt(unsafe { libc::kill(self.pid, libc::SIGKILL) }).map(|_| ()) + cvt(unsafe { libc::kill(self.pid, libc::SIGKILL) }).map(drop) } } diff --git a/src/libstd/sys/vxworks/weak.rs b/src/libstd/sys/vxworks/weak.rs deleted file mode 100644 index 4c6fddefd3f..00000000000 --- a/src/libstd/sys/vxworks/weak.rs +++ /dev/null @@ -1,56 +0,0 @@ -//! Support for "weak linkage" to symbols on Unix -//! -//! Some I/O operations we do in libstd require newer versions of OSes but we -//! need to maintain binary compatibility with older releases for now. In order -//! to use the new functionality when available we use this module for -//! detection. -//! -//! One option to use here is weak linkage, but that is unfortunately only -//! really workable on Linux. Hence, use dlsym to get the symbol value at -//! runtime. This is also done for compatibility with older versions of glibc, -//! and to avoid creating dependencies on GLIBC_PRIVATE symbols. It assumes that -//! we've been dynamically linked to the library the symbol comes from, but that -//! is currently always the case for things like libpthread/libc. -//! -//! A long time ago this used weak linkage for the __pthread_get_minstack -//! symbol, but that caused Debian to detect an unnecessarily strict versioned -//! dependency on libc6 (#23628). - -use crate::ffi::CStr; -use crate::marker; -use crate::mem; -use crate::sync::atomic::{AtomicUsize, Ordering}; - -pub struct Weak<F> { - name: &'static str, - addr: AtomicUsize, - _marker: marker::PhantomData<F>, -} - -impl<F> Weak<F> { - pub const fn new(name: &'static str) -> Weak<F> { - Weak { name, addr: AtomicUsize::new(1), _marker: marker::PhantomData } - } - - pub fn get(&self) -> Option<F> { - assert_eq!(mem::size_of::<F>(), mem::size_of::<usize>()); - unsafe { - if self.addr.load(Ordering::SeqCst) == 1 { - self.addr.store(fetch(self.name), Ordering::SeqCst); - } - match self.addr.load(Ordering::SeqCst) { - 0 => None, - addr => Some(mem::transmute_copy::<usize, F>(&addr)), - } - } - } -} - -unsafe fn fetch(name: &str) -> usize { - let name = match CStr::from_bytes_with_nul(name.as_bytes()) { - Ok(cstr) => cstr, - Err(..) => return 0, - }; - assert!(false, "FIXME: fetch"); - libc::dlsym(libc::RTLD_DEFAULT, name.as_ptr()) as usize -} diff --git a/src/libstd/sys/wasi/os.rs b/src/libstd/sys/wasi/os.rs index 44a08a2f058..8052c0aa8a8 100644 --- a/src/libstd/sys/wasi/os.rs +++ b/src/libstd/sys/wasi/os.rs @@ -6,7 +6,6 @@ use crate::io; use crate::marker::PhantomData; use crate::os::wasi::prelude::*; use crate::path::{self, PathBuf}; -use crate::ptr; use crate::str; use crate::sys::memchr; use crate::sys::{unsupported, Void}; @@ -107,11 +106,13 @@ pub fn env() -> Env { let _guard = env_lock(); let mut environ = libc::environ; let mut result = Vec::new(); - while environ != ptr::null_mut() && *environ != ptr::null_mut() { - if let Some(key_value) = parse(CStr::from_ptr(*environ).to_bytes()) { - result.push(key_value); + if !environ.is_null() { + while !(*environ).is_null() { + if let Some(key_value) = parse(CStr::from_ptr(*environ).to_bytes()) { + result.push(key_value); + } + environ = environ.add(1); } - environ = environ.offset(1); } return Env { iter: result.into_iter(), _dont_send_or_sync_me: PhantomData }; } @@ -151,7 +152,7 @@ pub fn setenv(k: &OsStr, v: &OsStr) -> io::Result<()> { unsafe { let _guard = env_lock(); - cvt(libc::setenv(k.as_ptr(), v.as_ptr(), 1)).map(|_| ()) + cvt(libc::setenv(k.as_ptr(), v.as_ptr(), 1)).map(drop) } } @@ -160,7 +161,7 @@ pub fn unsetenv(n: &OsStr) -> io::Result<()> { unsafe { let _guard = env_lock(); - cvt(libc::unsetenv(nbuf.as_ptr())).map(|_| ()) + cvt(libc::unsetenv(nbuf.as_ptr())).map(drop) } } diff --git a/src/libstd/sys/windows/cmath.rs b/src/libstd/sys/windows/cmath.rs index 7c5bfa1bd06..1a5421facd0 100644 --- a/src/libstd/sys/windows/cmath.rs +++ b/src/libstd/sys/windows/cmath.rs @@ -2,7 +2,6 @@ use libc::{c_double, c_float}; -#[link_name = "m"] extern "C" { pub fn acos(n: c_double) -> c_double; pub fn asin(n: c_double) -> c_double; @@ -28,7 +27,7 @@ extern "C" { pub use self::shims::*; -#[cfg(not(target_env = "msvc"))] +#[cfg(not(all(target_env = "msvc", target_arch = "x86")))] mod shims { use libc::c_float; @@ -44,10 +43,10 @@ mod shims { } } -// On MSVC these functions aren't defined, so we just define shims which promote -// everything fo f64, perform the calculation, and then demote back to f32. -// While not precisely correct should be "correct enough" for now. -#[cfg(target_env = "msvc")] +// On 32-bit x86 MSVC these functions aren't defined, so we just define shims +// which promote everything fo f64, perform the calculation, and then demote +// back to f32. While not precisely correct should be "correct enough" for now. +#[cfg(all(target_env = "msvc", target_arch = "x86"))] mod shims { use libc::c_float; diff --git a/src/libstd/sys/windows/ext/fs.rs b/src/libstd/sys/windows/ext/fs.rs index 0462f889a8e..d508a333484 100644 --- a/src/libstd/sys/windows/ext/fs.rs +++ b/src/libstd/sys/windows/ext/fs.rs @@ -117,7 +117,7 @@ pub trait OpenOptionsExt { /// let file = OpenOptions::new().access_mode(0).open("foo.txt"); /// ``` /// - /// [`CreateFile`]: https://msdn.microsoft.com/en-us/library/windows/desktop/aa363858.aspx + /// [`CreateFile`]: https://docs.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-createfilea #[stable(feature = "open_options_ext", since = "1.10.0")] fn access_mode(&mut self, access: u32) -> &mut Self; @@ -145,7 +145,7 @@ pub trait OpenOptionsExt { /// .open("foo.txt"); /// ``` /// - /// [`CreateFile`]: https://msdn.microsoft.com/en-us/library/windows/desktop/aa363858.aspx + /// [`CreateFile`]: https://docs.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-createfilea #[stable(feature = "open_options_ext", since = "1.10.0")] fn share_mode(&mut self, val: u32) -> &mut Self; @@ -174,8 +174,8 @@ pub trait OpenOptionsExt { /// .open("foo.txt"); /// ``` /// - /// [`CreateFile`]: https://msdn.microsoft.com/en-us/library/windows/desktop/aa363858.aspx - /// [`CreateFile2`]: https://msdn.microsoft.com/en-us/library/windows/desktop/hh449422.aspx + /// [`CreateFile`]: https://docs.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-createfilea + /// [`CreateFile2`]: https://docs.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-createfile2 #[stable(feature = "open_options_ext", since = "1.10.0")] fn custom_flags(&mut self, flags: u32) -> &mut Self; @@ -211,8 +211,8 @@ pub trait OpenOptionsExt { /// .open("foo.txt"); /// ``` /// - /// [`CreateFile`]: https://msdn.microsoft.com/en-us/library/windows/desktop/aa363858.aspx - /// [`CreateFile2`]: https://msdn.microsoft.com/en-us/library/windows/desktop/hh449422.aspx + /// [`CreateFile`]: https://docs.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-createfilea + /// [`CreateFile2`]: https://docs.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-createfile2 #[stable(feature = "open_options_ext", since = "1.10.0")] fn attributes(&mut self, val: u32) -> &mut Self; @@ -254,10 +254,10 @@ pub trait OpenOptionsExt { /// .open(r"\\.\pipe\MyPipe"); /// ``` /// - /// [`CreateFile`]: https://msdn.microsoft.com/en-us/library/windows/desktop/aa363858.aspx - /// [`CreateFile2`]: https://msdn.microsoft.com/en-us/library/windows/desktop/hh449422.aspx + /// [`CreateFile`]: https://docs.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-createfilea + /// [`CreateFile2`]: https://docs.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-createfile2 /// [Impersonation Levels]: - /// https://msdn.microsoft.com/en-us/library/windows/desktop/aa379572.aspx + /// https://docs.microsoft.com/en-us/windows/win32/api/winnt/ne-winnt-security_impersonation_level #[stable(feature = "open_options_ext", since = "1.10.0")] fn security_qos_flags(&mut self, flags: u32) -> &mut OpenOptions; } @@ -297,7 +297,7 @@ impl OpenOptionsExt for OpenOptions { /// /// [`fs::Metadata`]: ../../../../std/fs/struct.Metadata.html /// [`BY_HANDLE_FILE_INFORMATION`]: -/// https://msdn.microsoft.com/en-us/library/windows/desktop/aa363788.aspx +/// https://docs.microsoft.com/en-us/windows/win32/api/fileapi/ns-fileapi-by_handle_file_information #[stable(feature = "metadata_ext", since = "1.1.0")] pub trait MetadataExt { /// Returns the value of the `dwFileAttributes` field of this metadata. @@ -321,7 +321,7 @@ pub trait MetadataExt { /// ``` /// /// [File Attribute Constants]: - /// https://msdn.microsoft.com/en-us/library/windows/desktop/gg258117.aspx + /// https://docs.microsoft.com/en-us/windows/win32/fileio/file-attribute-constants #[stable(feature = "metadata_ext", since = "1.1.0")] fn file_attributes(&self) -> u32; @@ -350,7 +350,7 @@ pub trait MetadataExt { /// } /// ``` /// - /// [`FILETIME`]: https://msdn.microsoft.com/en-us/library/windows/desktop/ms724284.aspx + /// [`FILETIME`]: https://docs.microsoft.com/en-us/windows/win32/api/minwinbase/ns-minwinbase-filetime #[stable(feature = "metadata_ext", since = "1.1.0")] fn creation_time(&self) -> u64; @@ -385,7 +385,7 @@ pub trait MetadataExt { /// } /// ``` /// - /// [`FILETIME`]: https://msdn.microsoft.com/en-us/library/windows/desktop/ms724284.aspx + /// [`FILETIME`]: https://docs.microsoft.com/en-us/windows/win32/api/minwinbase/ns-minwinbase-filetime #[stable(feature = "metadata_ext", since = "1.1.0")] fn last_access_time(&self) -> u64; @@ -418,7 +418,7 @@ pub trait MetadataExt { /// } /// ``` /// - /// [`FILETIME`]: https://msdn.microsoft.com/en-us/library/windows/desktop/ms724284.aspx + /// [`FILETIME`]: https://docs.microsoft.com/en-us/windows/win32/api/minwinbase/ns-minwinbase-filetime #[stable(feature = "metadata_ext", since = "1.1.0")] fn last_write_time(&self) -> u64; diff --git a/src/libstd/sys/windows/ext/process.rs b/src/libstd/sys/windows/ext/process.rs index ed35c5ff194..8c34a9faf1d 100644 --- a/src/libstd/sys/windows/ext/process.rs +++ b/src/libstd/sys/windows/ext/process.rs @@ -99,7 +99,7 @@ pub trait CommandExt { /// /// These will always be ORed with `CREATE_UNICODE_ENVIRONMENT`. /// - /// [1]: https://msdn.microsoft.com/en-us/library/windows/desktop/ms684863(v=vs.85).aspx + /// [1]: https://docs.microsoft.com/en-us/windows/win32/procthread/process-creation-flags #[stable(feature = "windows_process_extensions", since = "1.16.0")] fn creation_flags(&mut self, flags: u32) -> &mut process::Command; } diff --git a/src/libstd/sys/windows/fs.rs b/src/libstd/sys/windows/fs.rs index e9c84c4e7c9..427f4b684e1 100644 --- a/src/libstd/sys/windows/fs.rs +++ b/src/libstd/sys/windows/fs.rs @@ -923,6 +923,6 @@ fn symlink_junction_inner(target: &Path, junction: &Path) -> io::Result<()> { &mut ret, ptr::null_mut(), )) - .map(|_| ()) + .map(drop) } } diff --git a/src/libstd/sys/windows/handle.rs b/src/libstd/sys/windows/handle.rs index fd0c2350cb3..f2ad057b6b6 100644 --- a/src/libstd/sys/windows/handle.rs +++ b/src/libstd/sys/windows/handle.rs @@ -156,7 +156,7 @@ impl RawHandle { } pub fn cancel_io(&self) -> io::Result<()> { - unsafe { cvt(c::CancelIo(self.raw())).map(|_| ()) } + unsafe { cvt(c::CancelIo(self.raw())).map(drop) } } pub fn write(&self, buf: &[u8]) -> io::Result<usize> { diff --git a/src/libstd/sys/windows/mod.rs b/src/libstd/sys/windows/mod.rs index a515b382ab0..b004cd19020 100644 --- a/src/libstd/sys/windows/mod.rs +++ b/src/libstd/sys/windows/mod.rs @@ -262,7 +262,7 @@ pub fn dur2timeout(dur: Duration) -> c::DWORD { // terminating the process but without necessarily bypassing all exception // handlers. // -// https://msdn.microsoft.com/en-us/library/dn774154.aspx +// https://docs.microsoft.com/en-us/cpp/intrinsics/fastfail #[allow(unreachable_code)] pub unsafe fn abort_internal() -> ! { #[cfg(any(target_arch = "x86", target_arch = "x86_64"))] diff --git a/src/libstd/sys/windows/net.rs b/src/libstd/sys/windows/net.rs index 58574f5723b..d8d4fdfce2f 100644 --- a/src/libstd/sys/windows/net.rs +++ b/src/libstd/sys/windows/net.rs @@ -355,7 +355,7 @@ impl Socket { #[cfg(not(target_vendor = "uwp"))] fn set_no_inherit(&self) -> io::Result<()> { sys::cvt(unsafe { c::SetHandleInformation(self.0 as c::HANDLE, c::HANDLE_FLAG_INHERIT, 0) }) - .map(|_| ()) + .map(drop) } #[cfg(target_vendor = "uwp")] diff --git a/src/libstd/sys/windows/os.rs b/src/libstd/sys/windows/os.rs index e0a1d2f4c0e..cc4ae405906 100644 --- a/src/libstd/sys/windows/os.rs +++ b/src/libstd/sys/windows/os.rs @@ -34,7 +34,7 @@ pub fn error_string(mut errnum: i32) -> String { // NTSTATUS errors may be encoded as HRESULT, which may returned from // GetLastError. For more information about Windows error codes, see - // `[MS-ERREF]`: https://msdn.microsoft.com/en-us/library/cc231198.aspx + // `[MS-ERREF]`: https://docs.microsoft.com/en-us/openspecs/windows_protocols/ms-erref/0642cb2f-2075-4469-918c-4441e69c548a if (errnum & c::FACILITY_NT_BIT as i32) != 0 { // format according to https://support.microsoft.com/en-us/help/259693 const NTDLL_DLL: &[u16] = &[ @@ -43,7 +43,7 @@ pub fn error_string(mut errnum: i32) -> String { ]; module = c::GetModuleHandleW(NTDLL_DLL.as_ptr()); - if module != ptr::null_mut() { + if !module.is_null() { errnum ^= c::FACILITY_NT_BIT as i32; flags = c::FORMAT_MESSAGE_FROM_HMODULE; } @@ -247,7 +247,7 @@ pub fn chdir(p: &path::Path) -> io::Result<()> { let mut p = p.encode_wide().collect::<Vec<_>>(); p.push(0); - cvt(unsafe { c::SetCurrentDirectoryW(p.as_ptr()) }).map(|_| ()) + cvt(unsafe { c::SetCurrentDirectoryW(p.as_ptr()) }).map(drop) } pub fn getenv(k: &OsStr) -> io::Result<Option<OsString>> { @@ -272,12 +272,12 @@ pub fn setenv(k: &OsStr, v: &OsStr) -> io::Result<()> { let k = to_u16s(k)?; let v = to_u16s(v)?; - cvt(unsafe { c::SetEnvironmentVariableW(k.as_ptr(), v.as_ptr()) }).map(|_| ()) + cvt(unsafe { c::SetEnvironmentVariableW(k.as_ptr(), v.as_ptr()) }).map(drop) } pub fn unsetenv(n: &OsStr) -> io::Result<()> { let v = to_u16s(n)?; - cvt(unsafe { c::SetEnvironmentVariableW(v.as_ptr(), ptr::null()) }).map(|_| ()) + cvt(unsafe { c::SetEnvironmentVariableW(v.as_ptr(), ptr::null()) }).map(drop) } pub fn temp_dir() -> PathBuf { |
