diff options
| author | David Tolnay <dtolnay@gmail.com> | 2019-11-27 10:28:39 -0800 |
|---|---|---|
| committer | David Tolnay <dtolnay@gmail.com> | 2019-11-29 18:37:58 -0800 |
| commit | c34fbfaad38cf5829ef5cfe780dc9d58480adeaa (patch) | |
| tree | e57b66ed06aec18dc13ff7f14a243ca3dc3c27d1 /src/libstd/sys/vxworks | |
| parent | 9081929d45f12d3f56d43b1d6db7519981580fc9 (diff) | |
| download | rust-c34fbfaad38cf5829ef5cfe780dc9d58480adeaa.tar.gz rust-c34fbfaad38cf5829ef5cfe780dc9d58480adeaa.zip | |
Format libstd/sys with rustfmt
This commit applies rustfmt with rust-lang/rust's default settings to
files in src/libstd/sys *that are not involved in any currently open PR*
to minimize merge conflicts. THe list of files involved in open PRs was
determined by querying GitHub's GraphQL API with this script:
https://gist.github.com/dtolnay/aa9c34993dc051a4f344d1b10e4487e8
With the list of files from the script in outstanding_files, the
relevant commands were:
$ find src/libstd/sys -name '*.rs' \
| xargs rustfmt --edition=2018 --unstable-features --skip-children
$ rg libstd/sys outstanding_files | xargs git checkout --
Repeating this process several months apart should get us coverage of
most of the rest of the files.
To confirm no funny business:
$ git checkout $THIS_COMMIT^
$ git show --pretty= --name-only $THIS_COMMIT \
| xargs rustfmt --edition=2018 --unstable-features --skip-children
$ git diff $THIS_COMMIT # there should be no difference
Diffstat (limited to 'src/libstd/sys/vxworks')
28 files changed, 524 insertions, 480 deletions
diff --git a/src/libstd/sys/vxworks/alloc.rs b/src/libstd/sys/vxworks/alloc.rs index e0c560b9214..97a191d7232 100644 --- a/src/libstd/sys/vxworks/alloc.rs +++ b/src/libstd/sys/vxworks/alloc.rs @@ -1,6 +1,6 @@ -use crate::ptr; -use crate::sys_common::alloc::{MIN_ALIGN, realloc_fallback}; use crate::alloc::{GlobalAlloc, Layout, System}; +use crate::ptr; +use crate::sys_common::alloc::{realloc_fallback, MIN_ALIGN}; #[stable(feature = "alloc_system_type", since = "1.28.0")] unsafe impl GlobalAlloc for System { @@ -45,9 +45,5 @@ unsafe impl GlobalAlloc for System { unsafe fn aligned_malloc(layout: &Layout) -> *mut u8 { let mut out = ptr::null_mut(); let ret = libc::posix_memalign(&mut out, layout.align(), layout.size()); - if ret != 0 { - ptr::null_mut() - } else { - out as *mut u8 - } + if ret != 0 { ptr::null_mut() } else { out as *mut u8 } } diff --git a/src/libstd/sys/vxworks/args.rs b/src/libstd/sys/vxworks/args.rs index 11c3cb78819..efd615f404d 100644 --- a/src/libstd/sys/vxworks/args.rs +++ b/src/libstd/sys/vxworks/args.rs @@ -4,10 +4,14 @@ use crate::marker::PhantomData; use crate::vec; /// One-time global initialization. -pub unsafe fn init(argc: isize, argv: *const *const u8) { imp::init(argc, argv) } +pub unsafe fn init(argc: isize, argv: *const *const u8) { + imp::init(argc, argv) +} /// One-time global cleanup. -pub unsafe fn cleanup() { imp::cleanup() } +pub unsafe fn cleanup() { + imp::cleanup() +} /// Returns the command line arguments pub fn args() -> Args { @@ -27,24 +31,32 @@ impl Args { 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() } + 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() } + fn len(&self) -> usize { + self.iter.len() + } } impl DoubleEndedIterator for Args { - fn next_back(&mut self) -> Option<OsString> { self.iter.next_back() } + fn next_back(&mut self) -> Option<OsString> { + self.iter.next_back() + } } mod imp { - use crate::ptr; + use super::Args; use crate::ffi::{CStr, OsString}; use crate::marker::PhantomData; + use crate::ptr; use libc; - use super::Args; use crate::sys_common::mutex::Mutex; @@ -65,21 +77,20 @@ mod imp { } pub fn args() -> Args { - Args { - iter: clone().into_iter(), - _dont_send_or_sync_me: PhantomData - } + Args { iter: clone().into_iter(), _dont_send_or_sync_me: PhantomData } } fn clone() -> Vec<OsString> { unsafe { let _guard = LOCK.lock(); - let ret = (0..ARGC).map(|i| { - let cstr = CStr::from_ptr(*ARGV.offset(i) as *const libc::c_char); - use crate::sys::vxworks::ext::ffi::OsStringExt; - OsStringExt::from_vec(cstr.to_bytes().to_vec()) - }).collect(); - return ret + let ret = (0..ARGC) + .map(|i| { + let cstr = CStr::from_ptr(*ARGV.offset(i) as *const libc::c_char); + use crate::sys::vxworks::ext::ffi::OsStringExt; + OsStringExt::from_vec(cstr.to_bytes().to_vec()) + }) + .collect(); + return ret; } } } diff --git a/src/libstd/sys/vxworks/cmath.rs b/src/libstd/sys/vxworks/cmath.rs index f6bb58934fc..2916ebe4440 100644 --- a/src/libstd/sys/vxworks/cmath.rs +++ b/src/libstd/sys/vxworks/cmath.rs @@ -1,9 +1,9 @@ #![cfg(not(test))] -use libc::{c_float, c_double}; +use libc::{c_double, c_float}; #[link_name = "m"] -extern { +extern "C" { pub fn acos(n: c_double) -> c_double; pub fn acosf(n: c_float) -> c_float; pub fn asin(n: c_double) -> c_double; diff --git a/src/libstd/sys/vxworks/condvar.rs b/src/libstd/sys/vxworks/condvar.rs index 783c3eb7c76..f2a1d681529 100644 --- a/src/libstd/sys/vxworks/condvar.rs +++ b/src/libstd/sys/vxworks/condvar.rs @@ -2,15 +2,15 @@ use crate::cell::UnsafeCell; use crate::sys::mutex::{self, Mutex}; use crate::time::Duration; -pub struct Condvar { inner: UnsafeCell<libc::pthread_cond_t> } +pub struct Condvar { + inner: UnsafeCell<libc::pthread_cond_t>, +} unsafe impl Send for Condvar {} unsafe impl Sync for Condvar {} -const TIMESPEC_MAX: libc::timespec = libc::timespec { - tv_sec: <libc::time_t>::max_value(), - tv_nsec: 1_000_000_000 - 1, -}; +const TIMESPEC_MAX: libc::timespec = + libc::timespec { tv_sec: <libc::time_t>::max_value(), tv_nsec: 1_000_000_000 - 1 }; fn saturating_cast_to_time_t(value: u64) -> libc::time_t { if value > <libc::time_t>::max_value() as u64 { @@ -77,17 +77,14 @@ impl Condvar { .and_then(|s| s.checked_add(now.tv_sec)); let nsec = nsec % 1_000_000_000; - let timeout = sec.map(|s| { - libc::timespec { tv_sec: s, tv_nsec: nsec as _} - }).unwrap_or(TIMESPEC_MAX); + let timeout = + sec.map(|s| libc::timespec { tv_sec: s, tv_nsec: nsec as _ }).unwrap_or(TIMESPEC_MAX); - let r = libc::pthread_cond_timedwait(self.inner.get(), mutex::raw(mutex), - &timeout); + let r = libc::pthread_cond_timedwait(self.inner.get(), mutex::raw(mutex), &timeout); assert!(r == libc::ETIMEDOUT || r == 0); r == 0 } - #[inline] pub unsafe fn destroy(&self) { let r = libc::pthread_cond_destroy(self.inner.get()); diff --git a/src/libstd/sys/vxworks/ext/fs.rs b/src/libstd/sys/vxworks/ext/fs.rs index 4a9cc3bd069..9864a855df7 100644 --- a/src/libstd/sys/vxworks/ext/fs.rs +++ b/src/libstd/sys/vxworks/ext/fs.rs @@ -2,11 +2,11 @@ use crate::fs::{self, Permissions}; use crate::io; -use libc; use crate::path::Path; use crate::sys; -use crate::sys_common::{FromInner, AsInner, AsInnerMut}; use crate::sys::platform::fs::MetadataExt as UnixMetadataExt; +use crate::sys_common::{AsInner, AsInnerMut, FromInner}; +use libc; /// Unix-specific extensions to [`File`]. /// @@ -112,8 +112,7 @@ pub trait FileExt { } } if !buf.is_empty() { - Err(io::Error::new(io::ErrorKind::UnexpectedEof, - "failed to fill whole buffer")) + Err(io::Error::new(io::ErrorKind::UnexpectedEof, "failed to fill whole buffer")) } else { Ok(()) } @@ -196,8 +195,12 @@ pub trait FileExt { fn write_all_at(&self, mut buf: &[u8], mut offset: u64) -> io::Result<()> { while !buf.is_empty() { match self.write_at(buf, offset) { - Ok(0) => return Err(io::Error::new(io::ErrorKind::WriteZero, - "failed to write whole buffer")), + Ok(0) => { + return Err(io::Error::new( + io::ErrorKind::WriteZero, + "failed to write whole buffer", + )); + } Ok(n) => { buf = &buf[n..]; offset += n as u64 @@ -604,20 +607,48 @@ pub trait MetadataExt { #[stable(feature = "metadata_ext", since = "1.1.0")] impl MetadataExt for fs::Metadata { - fn dev(&self) -> u64 { self.st_dev() } - fn ino(&self) -> u64 { self.st_ino() } - fn mode(&self) -> u32 { self.st_mode() } - fn nlink(&self) -> u64 { self.st_nlink() } - fn uid(&self) -> u32 { self.st_uid() } - fn gid(&self) -> u32 { self.st_gid() } - fn rdev(&self) -> u64 { self.st_rdev() } - fn size(&self) -> u64 { self.st_size() } - fn atime(&self) -> i64 { self.st_atime() } - fn mtime(&self) -> i64 { self.st_mtime() } - fn ctime(&self) -> i64 { self.st_ctime() } - fn blksize(&self) -> u64 { self.st_blksize() } - fn blocks(&self) -> u64 { self.st_blocks() } - fn attrib(&self) -> u8 {self.st_attrib() } + fn dev(&self) -> u64 { + self.st_dev() + } + fn ino(&self) -> u64 { + self.st_ino() + } + fn mode(&self) -> u32 { + self.st_mode() + } + fn nlink(&self) -> u64 { + self.st_nlink() + } + fn uid(&self) -> u32 { + self.st_uid() + } + fn gid(&self) -> u32 { + self.st_gid() + } + fn rdev(&self) -> u64 { + self.st_rdev() + } + fn size(&self) -> u64 { + self.st_size() + } + fn atime(&self) -> i64 { + self.st_atime() + } + fn mtime(&self) -> i64 { + self.st_mtime() + } + fn ctime(&self) -> i64 { + self.st_ctime() + } + fn blksize(&self) -> u64 { + self.st_blksize() + } + fn blocks(&self) -> u64 { + self.st_blocks() + } + fn attrib(&self) -> u8 { + self.st_attrib() + } } /// Unix-specific extensions for [`FileType`]. @@ -704,10 +735,18 @@ pub trait FileTypeExt { #[stable(feature = "file_type_ext", since = "1.5.0")] impl FileTypeExt for fs::FileType { - fn is_block_device(&self) -> bool { self.as_inner().is(libc::S_IFBLK) } - fn is_char_device(&self) -> bool { self.as_inner().is(libc::S_IFCHR) } - fn is_fifo(&self) -> bool { self.as_inner().is(libc::S_IFIFO) } - fn is_socket(&self) -> bool { self.as_inner().is(libc::S_IFSOCK) } + fn is_block_device(&self) -> bool { + self.as_inner().is(libc::S_IFBLK) + } + fn is_char_device(&self) -> bool { + self.as_inner().is(libc::S_IFCHR) + } + fn is_fifo(&self) -> bool { + self.as_inner().is(libc::S_IFIFO) + } + fn is_socket(&self) -> bool { + self.as_inner().is(libc::S_IFSOCK) + } } /// Unix-specific extension methods for [`fs::DirEntry`]. @@ -739,7 +778,9 @@ pub trait DirEntryExt { #[stable(feature = "dir_entry_ext", since = "1.1.0")] impl DirEntryExt for fs::DirEntry { - fn ino(&self) -> u64 { self.as_inner().ino() } + fn ino(&self) -> u64 { + self.as_inner().ino() + } } /// Creates a new symbolic link on the filesystem. @@ -766,8 +807,7 @@ impl DirEntryExt for fs::DirEntry { /// } /// ``` #[stable(feature = "symlink", since = "1.1.0")] -pub fn symlink<P: AsRef<Path>, Q: AsRef<Path>>(src: P, dst: Q) -> io::Result<()> -{ +pub fn symlink<P: AsRef<Path>, Q: AsRef<Path>>(src: P, dst: Q) -> io::Result<()> { sys::fs::symlink(src.as_ref(), dst.as_ref()) } diff --git a/src/libstd/sys/vxworks/ext/io.rs b/src/libstd/sys/vxworks/ext/io.rs index df6255a3e9e..25c6e26d96e 100644 --- a/src/libstd/sys/vxworks/ext/io.rs +++ b/src/libstd/sys/vxworks/ext/io.rs @@ -3,11 +3,11 @@ #![stable(feature = "rust1", since = "1.0.0")] use crate::fs; +use crate::io; +use crate::net; use crate::os::raw; use crate::sys; -use crate::io; use crate::sys_common::{self, AsInner, FromInner, IntoInner}; -use crate::net; /// Raw file descriptors. #[stable(feature = "rust1", since = "1.0.0")] @@ -84,47 +84,65 @@ impl IntoRawFd for fs::File { #[stable(feature = "asraw_stdio", since = "1.21.0")] impl AsRawFd for io::Stdin { - fn as_raw_fd(&self) -> RawFd { libc::STDIN_FILENO } + fn as_raw_fd(&self) -> RawFd { + libc::STDIN_FILENO + } } #[stable(feature = "asraw_stdio", since = "1.21.0")] impl AsRawFd for io::Stdout { - fn as_raw_fd(&self) -> RawFd { libc::STDOUT_FILENO } + fn as_raw_fd(&self) -> RawFd { + libc::STDOUT_FILENO + } } #[stable(feature = "asraw_stdio", since = "1.21.0")] impl AsRawFd for io::Stderr { - fn as_raw_fd(&self) -> RawFd { libc::STDERR_FILENO } + fn as_raw_fd(&self) -> RawFd { + libc::STDERR_FILENO + } } #[stable(feature = "asraw_stdio_locks", since = "1.35.0")] impl<'a> AsRawFd for io::StdinLock<'a> { - fn as_raw_fd(&self) -> RawFd { libc::STDIN_FILENO } + fn as_raw_fd(&self) -> RawFd { + libc::STDIN_FILENO + } } #[stable(feature = "asraw_stdio_locks", since = "1.35.0")] impl<'a> AsRawFd for io::StdoutLock<'a> { - fn as_raw_fd(&self) -> RawFd { libc::STDOUT_FILENO } + fn as_raw_fd(&self) -> RawFd { + libc::STDOUT_FILENO + } } #[stable(feature = "asraw_stdio_locks", since = "1.35.0")] impl<'a> AsRawFd for io::StderrLock<'a> { - fn as_raw_fd(&self) -> RawFd { libc::STDERR_FILENO } + fn as_raw_fd(&self) -> RawFd { + libc::STDERR_FILENO + } } #[stable(feature = "rust1", since = "1.0.0")] impl AsRawFd for net::TcpStream { - fn as_raw_fd(&self) -> RawFd { *self.as_inner().socket().as_inner() } + fn as_raw_fd(&self) -> RawFd { + *self.as_inner().socket().as_inner() + } } #[stable(feature = "rust1", since = "1.0.0")] impl AsRawFd for net::TcpListener { - fn as_raw_fd(&self) -> RawFd { *self.as_inner().socket().as_inner() } + fn as_raw_fd(&self) -> RawFd { + *self.as_inner().socket().as_inner() + } } #[stable(feature = "rust1", since = "1.0.0")] impl AsRawFd for net::UdpSocket { - fn as_raw_fd(&self) -> RawFd { *self.as_inner().socket().as_inner() } + fn as_raw_fd(&self) -> RawFd { + *self.as_inner().socket().as_inner() + } } #[stable(feature = "from_raw_os", since = "1.1.0")] diff --git a/src/libstd/sys/vxworks/ext/mod.rs b/src/libstd/sys/vxworks/ext/mod.rs index d0f467b303f..251a198f821 100644 --- a/src/libstd/sys/vxworks/ext/mod.rs +++ b/src/libstd/sys/vxworks/ext/mod.rs @@ -1,18 +1,21 @@ #![stable(feature = "rust1", since = "1.0.0")] #![allow(missing_docs)] -pub mod io; pub mod ffi; pub mod fs; -pub mod raw; +pub mod io; pub mod process; +pub mod raw; #[stable(feature = "rust1", since = "1.0.0")] pub mod prelude { - #[doc(no_inline)] #[stable(feature = "rust1", since = "1.0.0")] - pub use super::io::{RawFd, AsRawFd, FromRawFd, IntoRawFd}; - #[doc(no_inline)] #[stable(feature = "rust1", since = "1.0.0")] + #[doc(no_inline)] + #[stable(feature = "rust1", since = "1.0.0")] pub use super::ffi::{OsStrExt, OsStringExt}; - #[doc(no_inline)] #[stable(feature = "rust1", since = "1.0.0")] - pub use super::fs::{PermissionsExt, OpenOptionsExt, MetadataExt, FileTypeExt}; + #[doc(no_inline)] + #[stable(feature = "rust1", since = "1.0.0")] + pub use super::fs::{FileTypeExt, MetadataExt, OpenOptionsExt, PermissionsExt}; + #[doc(no_inline)] + #[stable(feature = "rust1", since = "1.0.0")] + pub use super::io::{AsRawFd, FromRawFd, IntoRawFd, RawFd}; } diff --git a/src/libstd/sys/vxworks/ext/process.rs b/src/libstd/sys/vxworks/ext/process.rs index 4de72fa1816..e535c4aa122 100644 --- a/src/libstd/sys/vxworks/ext/process.rs +++ b/src/libstd/sys/vxworks/ext/process.rs @@ -3,10 +3,10 @@ #![stable(feature = "rust1", since = "1.0.0")] use crate::io; -use crate::sys::vxworks::ext::io::{FromRawFd, RawFd, AsRawFd, IntoRawFd}; use crate::process; use crate::sys; -use crate::sys_common::{AsInnerMut, AsInner, FromInner, IntoInner}; +use crate::sys::vxworks::ext::io::{AsRawFd, FromRawFd, IntoRawFd, RawFd}; +use crate::sys_common::{AsInner, AsInnerMut, FromInner, IntoInner}; /// Unix-specific extensions to the [`process::Command`] builder. /// @@ -55,7 +55,8 @@ pub trait CommandExt { /// locations may not appear where intended. #[stable(feature = "process_pre_exec", since = "1.34.0")] unsafe fn pre_exec<F>(&mut self, f: F) -> &mut process::Command - where F: FnMut() -> io::Result<()> + Send + Sync + 'static; + where + F: FnMut() -> io::Result<()> + Send + Sync + 'static; /// Schedules a closure to be run just before the `exec` function is /// invoked. @@ -67,7 +68,8 @@ pub trait CommandExt { #[stable(feature = "process_exec", since = "1.15.0")] #[rustc_deprecated(since = "1.37.0", reason = "should be unsafe, use `pre_exec` instead")] fn before_exec<F>(&mut self, f: F) -> &mut process::Command - where F: FnMut() -> io::Result<()> + Send + Sync + 'static + where + F: FnMut() -> io::Result<()> + Send + Sync + 'static, { unsafe { self.pre_exec(f) } } @@ -118,7 +120,8 @@ impl CommandExt for process::Command { } unsafe fn pre_exec<F>(&mut self, f: F) -> &mut process::Command - where F: FnMut() -> io::Result<()> + Send + Sync + 'static + where + F: FnMut() -> io::Result<()> + Send + Sync + 'static, { self.as_inner_mut().pre_exec(Box::new(f)); self diff --git a/src/libstd/sys/vxworks/fast_thread_local.rs b/src/libstd/sys/vxworks/fast_thread_local.rs index 8b55939b8e5..387ebd0520a 100644 --- a/src/libstd/sys/vxworks/fast_thread_local.rs +++ b/src/libstd/sys/vxworks/fast_thread_local.rs @@ -1,7 +1,7 @@ #![cfg(target_thread_local)] #![unstable(feature = "thread_local_internals", issue = "0")] -pub unsafe fn register_dtor(t: *mut u8, dtor: unsafe extern fn(*mut u8)) { +pub unsafe fn register_dtor(t: *mut u8, dtor: unsafe extern "C" fn(*mut u8)) { use crate::sys_common::thread_local::register_dtor_fallback; register_dtor_fallback(t, dtor); } diff --git a/src/libstd/sys/vxworks/fd.rs b/src/libstd/sys/vxworks/fd.rs index db2865d2529..9b649aa7ef4 100644 --- a/src/libstd/sys/vxworks/fd.rs +++ b/src/libstd/sys/vxworks/fd.rs @@ -1,7 +1,7 @@ #![unstable(reason = "not public", issue = "0", feature = "fd")] use crate::cmp; -use crate::io::{self, Read, Initializer, IoSlice, IoSliceMut}; +use crate::io::{self, Initializer, IoSlice, IoSliceMut, Read}; use crate::mem; use crate::sys::cvt; use crate::sys_common::AsInner; @@ -25,7 +25,9 @@ impl FileDesc { FileDesc { fd: fd } } - pub fn raw(&self) -> c_int { self.fd } + pub fn raw(&self) -> c_int { + self.fd + } /// Extracts the actual filedescriptor without closing it. pub fn into_raw(self) -> c_int { @@ -36,18 +38,18 @@ impl FileDesc { pub fn read(&self, buf: &mut [u8]) -> io::Result<usize> { let ret = cvt(unsafe { - libc::read(self.fd, - buf.as_mut_ptr() as *mut c_void, - cmp::min(buf.len(), max_len())) + libc::read(self.fd, buf.as_mut_ptr() as *mut c_void, cmp::min(buf.len(), max_len())) })?; Ok(ret as usize) } pub fn read_vectored(&self, bufs: &mut [IoSliceMut<'_>]) -> io::Result<usize> { let ret = cvt(unsafe { - libc::readv(self.fd, - bufs.as_ptr() as *const libc::iovec, - cmp::min(bufs.len(), c_int::max_value() as usize) as c_int) + libc::readv( + self.fd, + bufs.as_ptr() as *const libc::iovec, + cmp::min(bufs.len(), c_int::max_value() as usize) as c_int, + ) })?; Ok(ret as usize) } @@ -58,61 +60,69 @@ impl FileDesc { } pub fn read_at(&self, buf: &mut [u8], offset: u64) -> io::Result<usize> { - unsafe fn cvt_pread(fd: c_int, buf: *mut c_void, count: usize, offset: i64) - -> io::Result<isize> - { + unsafe fn cvt_pread( + fd: c_int, + buf: *mut c_void, + count: usize, + offset: i64, + ) -> io::Result<isize> { use libc::pread; cvt(pread(fd, buf, count, offset)) } unsafe { - cvt_pread(self.fd, + cvt_pread( + self.fd, buf.as_mut_ptr() as *mut c_void, cmp::min(buf.len(), max_len()), - offset as i64) + offset as i64, + ) .map(|n| n as usize) } } pub fn write(&self, buf: &[u8]) -> io::Result<usize> { let ret = cvt(unsafe { - libc::write(self.fd, - buf.as_ptr() as *const c_void, - cmp::min(buf.len(), max_len())) + libc::write(self.fd, buf.as_ptr() as *const c_void, cmp::min(buf.len(), max_len())) })?; Ok(ret as usize) } pub fn write_vectored(&self, bufs: &[IoSlice<'_>]) -> io::Result<usize> { let ret = cvt(unsafe { - libc::writev(self.fd, - bufs.as_ptr() as *const libc::iovec, - cmp::min(bufs.len(), c_int::max_value() as usize) as c_int) + libc::writev( + self.fd, + bufs.as_ptr() as *const libc::iovec, + cmp::min(bufs.len(), c_int::max_value() as usize) as c_int, + ) })?; Ok(ret as usize) } pub fn write_at(&self, buf: &[u8], offset: u64) -> io::Result<usize> { - unsafe fn cvt_pwrite(fd: c_int, buf: *const c_void, count: usize, offset: i64) - -> io::Result<isize> - { + unsafe fn cvt_pwrite( + fd: c_int, + buf: *const c_void, + count: usize, + offset: i64, + ) -> io::Result<isize> { use libc::pwrite; cvt(pwrite(fd, buf, count, offset)) } unsafe { - cvt_pwrite(self.fd, + cvt_pwrite( + self.fd, buf.as_ptr() as *const c_void, cmp::min(buf.len(), max_len()), - offset as i64) - .map(|n| n as usize) + offset as i64, + ) + .map(|n| n as usize) } } pub fn get_cloexec(&self) -> io::Result<bool> { - unsafe { - Ok((cvt(libc::fcntl(self.fd, libc::F_GETFD))? & libc::FD_CLOEXEC) != 0) - } + unsafe { Ok((cvt(libc::fcntl(self.fd, libc::F_GETFD))? & libc::FD_CLOEXEC) != 0) } } pub fn set_cloexec(&self) -> io::Result<()> { @@ -139,23 +149,16 @@ impl FileDesc { pub fn set_nonblocking_pipe(&self, nonblocking: bool) -> io::Result<()> { unsafe { let mut flags = cvt(libc::fcntl(self.fd, libc::F_GETFL, 0))?; - flags = if nonblocking { - flags | libc::O_NONBLOCK - } else { - flags & !libc::O_NONBLOCK - }; + flags = if nonblocking { flags | libc::O_NONBLOCK } else { flags & !libc::O_NONBLOCK }; cvt(libc::fcntl(self.fd, libc::F_SETFL, flags))?; Ok(()) } } - pub fn duplicate(&self) -> io::Result<FileDesc> { let fd = self.raw(); match cvt(unsafe { libc::fcntl(fd, libc::F_DUPFD_CLOEXEC, 0) }) { - Ok(newfd) => { - Ok(FileDesc::new(newfd)) - } + Ok(newfd) => Ok(FileDesc::new(newfd)), Err(e) => return Err(e), } } @@ -173,7 +176,9 @@ impl<'a> Read for &'a FileDesc { } impl AsInner<c_int> for FileDesc { - fn as_inner(&self) -> &c_int { &self.fd } + fn as_inner(&self) -> &c_int { + &self.fd + } } impl Drop for FileDesc { diff --git a/src/libstd/sys/vxworks/fs.rs b/src/libstd/sys/vxworks/fs.rs index adb08d8005a..6c2dfb79d6f 100644 --- a/src/libstd/sys/vxworks/fs.rs +++ b/src/libstd/sys/vxworks/fs.rs @@ -1,19 +1,19 @@ // copies from linuxx -use crate::ffi::{CString, CStr, OsString, OsStr}; -use crate::sys::vxworks::ext::ffi::OsStrExt; +use crate::ffi::{CStr, CString, OsStr, OsString}; use crate::fmt; -use crate::io::{self, Error, ErrorKind, SeekFrom, IoSlice, IoSliceMut}; +use crate::io::{self, Error, ErrorKind, IoSlice, IoSliceMut, SeekFrom}; use crate::mem; use crate::path::{Path, PathBuf}; use crate::ptr; use crate::sync::Arc; use crate::sys::fd::FileDesc; use crate::sys::time::SystemTime; +use crate::sys::vxworks::ext::ffi::OsStrExt; +use crate::sys::vxworks::ext::ffi::OsStringExt; use crate::sys::{cvt, cvt_r}; use crate::sys_common::{AsInner, FromInner}; -use libc::{self, c_int, mode_t, stat64, off_t}; -use libc::{ftruncate, lseek, dirent, readdir_r as readdir64_r, open}; -use crate::sys::vxworks::ext::ffi::OsStringExt; +use libc::{self, c_int, mode_t, off_t, stat64}; +use libc::{dirent, ftruncate, lseek, open, readdir_r as readdir64_r}; pub struct File(FileDesc); #[derive(Clone)] @@ -58,16 +58,24 @@ pub struct OpenOptions { } #[derive(Clone, PartialEq, Eq, Debug)] -pub struct FilePermissions { mode: mode_t } +pub struct FilePermissions { + mode: mode_t, +} #[derive(Copy, Clone, PartialEq, Eq, Hash, Debug)] -pub struct FileType { mode: mode_t } +pub struct FileType { + mode: mode_t, +} #[derive(Debug)] -pub struct DirBuilder { mode: mode_t } +pub struct DirBuilder { + mode: mode_t, +} impl FileAttr { - pub fn size(&self) -> u64 { self.stat.st_size as u64 } + pub fn size(&self) -> u64 { + self.stat.st_size as u64 + } pub fn perm(&self) -> FilePermissions { FilePermissions { mode: (self.stat.st_mode as mode_t) } } @@ -85,20 +93,23 @@ impl FileAttr { pub fn accessed(&self) -> io::Result<SystemTime> { Ok(SystemTime::from(libc::timespec { - tv_sec: self.stat.st_atime as libc::time_t, - tv_nsec: 0, // hack - a proper fix would be better + tv_sec: self.stat.st_atime as libc::time_t, + tv_nsec: 0, // hack - a proper fix would be better })) } pub fn created(&self) -> io::Result<SystemTime> { - Err(io::Error::new(io::ErrorKind::Other, - "creation time is not available on this platform currently")) + Err(io::Error::new( + io::ErrorKind::Other, + "creation time is not available on this platform currently", + )) } - } impl AsInner<stat64> for FileAttr { - fn as_inner(&self) -> &stat64 { &self.stat } + fn as_inner(&self) -> &stat64 { + &self.stat + } } impl FilePermissions { @@ -116,15 +127,25 @@ impl FilePermissions { self.mode |= 0o222; } } - pub fn mode(&self) -> u32 { self.mode as u32 } + pub fn mode(&self) -> u32 { + self.mode as u32 + } } impl FileType { - pub fn is_dir(&self) -> bool { self.is(libc::S_IFDIR) } - pub fn is_file(&self) -> bool { self.is(libc::S_IFREG) } - pub fn is_symlink(&self) -> bool { self.is(libc::S_IFLNK) } + pub fn is_dir(&self) -> bool { + self.is(libc::S_IFDIR) + } + pub fn is_file(&self) -> bool { + self.is(libc::S_IFREG) + } + pub fn is_symlink(&self) -> bool { + self.is(libc::S_IFLNK) + } - pub fn is(&self, mode: mode_t) -> bool { self.mode & libc::S_IFMT == mode } + pub fn is(&self, mode: mode_t) -> bool { + self.mode & libc::S_IFMT == mode + } } impl FromInner<u32> for FilePermissions { @@ -149,10 +170,7 @@ impl Iterator for ReadDir { } unsafe { - let mut ret = DirEntry { - entry: mem::zeroed(), - dir: self.clone(), - }; + let mut ret = DirEntry { entry: mem::zeroed(), dir: self.clone() }; let mut entry_ptr = ptr::null_mut(); loop { if readdir64_r(self.inner.dirp.0, &mut ret.entry, &mut entry_ptr) != 0 { @@ -163,13 +181,13 @@ impl Iterator for ReadDir { // (instead of looping forever) self.end_of_stream = true; } - return Some(Err(Error::last_os_error())) + return Some(Err(Error::last_os_error())); } if entry_ptr.is_null() { - return None + return None; } if ret.name_bytes() != b"." && ret.name_bytes() != b".." { - return Some(Ok(ret)) + return Some(Ok(ret)); } } } @@ -185,22 +203,20 @@ impl Drop for Dir { impl DirEntry { pub fn path(&self) -> PathBuf { - use crate::sys::vxworks::ext::ffi::OsStrExt; - self.dir.inner.root.join(OsStr::from_bytes(self.name_bytes())) + use crate::sys::vxworks::ext::ffi::OsStrExt; + self.dir.inner.root.join(OsStr::from_bytes(self.name_bytes())) } pub fn file_name(&self) -> OsString { OsStr::from_bytes(self.name_bytes()).to_os_string() } - pub fn metadata(&self) -> io::Result<FileAttr> { lstat(&self.path()) } pub fn file_type(&self) -> io::Result<FileType> { lstat(&self.path()).map(|m| m.file_type()) - } pub fn ino(&self) -> u64 { @@ -231,21 +247,35 @@ impl OpenOptions { } } - pub fn read(&mut self, read: bool) { self.read = read; } - pub fn write(&mut self, write: bool) { self.write = write; } - pub fn append(&mut self, append: bool) { self.append = append; } - pub fn truncate(&mut self, truncate: bool) { self.truncate = truncate; } - pub fn create(&mut self, create: bool) { self.create = create; } - pub fn create_new(&mut self, create_new: bool) { self.create_new = create_new; } - pub fn mode(&mut self, mode: u32) { self.mode = mode as mode_t; } + pub fn read(&mut self, read: bool) { + self.read = read; + } + pub fn write(&mut self, write: bool) { + self.write = write; + } + pub fn append(&mut self, append: bool) { + self.append = append; + } + pub fn truncate(&mut self, truncate: bool) { + self.truncate = truncate; + } + pub fn create(&mut self, create: bool) { + self.create = create; + } + pub fn create_new(&mut self, create_new: bool) { + self.create_new = create_new; + } + pub fn mode(&mut self, mode: u32) { + self.mode = mode as mode_t; + } fn get_access_mode(&self) -> io::Result<c_int> { match (self.read, self.write, self.append) { - (true, false, false) => Ok(libc::O_RDONLY), - (false, true, false) => Ok(libc::O_WRONLY), - (true, true, false) => Ok(libc::O_RDWR), - (false, _, true) => Ok(libc::O_WRONLY | libc::O_APPEND), - (true, _, true) => Ok(libc::O_RDWR | libc::O_APPEND), + (true, false, false) => Ok(libc::O_RDONLY), + (false, true, false) => Ok(libc::O_WRONLY), + (true, true, false) => Ok(libc::O_RDWR), + (false, _, true) => Ok(libc::O_WRONLY | libc::O_APPEND), + (true, _, true) => Ok(libc::O_RDWR | libc::O_APPEND), (false, false, false) => Err(Error::from_raw_os_error(libc::EINVAL)), } } @@ -253,23 +283,25 @@ impl OpenOptions { fn get_creation_mode(&self) -> io::Result<c_int> { match (self.write, self.append) { (true, false) => {} - (false, false) => + (false, false) => { if self.truncate || self.create || self.create_new { return Err(Error::from_raw_os_error(libc::EINVAL)); - }, - (_, true) => + } + } + (_, true) => { if self.truncate && !self.create_new { return Err(Error::from_raw_os_error(libc::EINVAL)); - }, + } + } } Ok(match (self.create, self.truncate, self.create_new) { - (false, false, false) => 0, - (true, false, false) => libc::O_CREAT, - (false, true, false) => libc::O_TRUNC, - (true, true, false) => libc::O_CREAT | libc::O_TRUNC, - (_, _, true) => libc::O_CREAT | libc::O_EXCL, - }) + (false, false, false) => 0, + (true, false, false) => libc::O_CREAT, + (false, true, false) => libc::O_TRUNC, + (true, true, false) => libc::O_CREAT | libc::O_TRUNC, + (_, _, true) => libc::O_CREAT | libc::O_EXCL, + }) } } @@ -280,21 +312,17 @@ impl File { } pub fn open_c(path: &CStr, opts: &OpenOptions) -> io::Result<File> { - let flags = libc::O_CLOEXEC | - opts.get_access_mode()? | - opts.get_creation_mode()? | - (opts.custom_flags as c_int & !libc::O_ACCMODE); - let fd = cvt_r(|| unsafe { - open(path.as_ptr(), flags, opts.mode as c_int) - })?; + let flags = libc::O_CLOEXEC + | opts.get_access_mode()? + | opts.get_creation_mode()? + | (opts.custom_flags as c_int & !libc::O_ACCMODE); + let fd = cvt_r(|| unsafe { open(path.as_ptr(), flags, opts.mode as c_int) })?; Ok(File(FileDesc::new(fd))) } pub fn file_attr(&self) -> io::Result<FileAttr> { let mut stat: stat64 = unsafe { mem::zeroed() }; - cvt(unsafe { - ::libc::fstat(self.0.raw(), &mut stat) - })?; + cvt(unsafe { ::libc::fstat(self.0.raw(), &mut stat) })?; Ok(FileAttr { stat: stat }) } @@ -306,13 +334,13 @@ impl File { pub fn datasync(&self) -> io::Result<()> { cvt_r(|| unsafe { os_datasync(self.0.raw()) })?; return Ok(()); - unsafe fn os_datasync(fd: c_int) -> c_int { libc::fsync(fd) } //not supported + unsafe fn os_datasync(fd: c_int) -> c_int { + libc::fsync(fd) + } //not supported } 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(|_| ()); } pub fn read(&self, buf: &mut [u8]) -> io::Result<usize> { @@ -339,7 +367,9 @@ impl File { self.0.write_at(buf, offset) } - pub fn flush(&self) -> io::Result<()> { Ok(()) } + pub fn flush(&self) -> io::Result<()> { + Ok(()) + } pub fn seek(&self, pos: SeekFrom) -> io::Result<u64> { let (whence, pos) = match pos { @@ -357,9 +387,13 @@ impl File { self.0.duplicate().map(File) } - pub fn fd(&self) -> &FileDesc { &self.0 } + pub fn fd(&self) -> &FileDesc { + &self.0 + } - pub fn into_fd(self) -> FileDesc { self.0 } + pub fn into_fd(self) -> FileDesc { + self.0 + } pub fn set_permissions(&self, perm: FilePermissions) -> io::Result<()> { cvt_r(|| unsafe { libc::fchmod(self.0.raw(), perm.mode) })?; @@ -401,7 +435,7 @@ impl FromInner<c_int> for File { impl fmt::Debug for File { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { fn get_path(fd: c_int) -> Option<PathBuf> { - let mut buf = vec![0;libc::PATH_MAX as usize]; + let mut buf = vec![0; libc::PATH_MAX as usize]; let n = unsafe { libc::ioctl(fd, libc::FIOGETNAME, buf.as_ptr()) }; if n == -1 { return None; @@ -419,7 +453,7 @@ impl fmt::Debug for File { libc::O_RDONLY => Some((true, false)), libc::O_RDWR => Some((true, true)), libc::O_WRONLY => Some((false, true)), - _ => None + _ => None, } } @@ -445,10 +479,7 @@ pub fn readdir(p: &Path) -> io::Result<ReadDir> { Err(Error::last_os_error()) } else { let inner = InnerReadDir { dirp: Dir(ptr), root }; - Ok(ReadDir{ - inner: Arc::new(inner), - end_of_stream: false, - }) + Ok(ReadDir { inner: Arc::new(inner), end_of_stream: false }) } } } @@ -480,11 +511,7 @@ pub fn rmdir(p: &Path) -> io::Result<()> { pub fn remove_dir_all(path: &Path) -> io::Result<()> { let filetype = lstat(path)?.file_type(); - if filetype.is_symlink() { - unlink(path) - } else { - remove_dir_all_recursive(path) - } + if filetype.is_symlink() { unlink(path) } else { remove_dir_all_recursive(path) } } fn remove_dir_all_recursive(path: &Path) -> io::Result<()> { @@ -506,11 +533,12 @@ pub fn readlink(p: &Path) -> io::Result<PathBuf> { let mut buf = Vec::with_capacity(256); loop { - let buf_read = cvt(unsafe { - libc::readlink(p, buf.as_mut_ptr() as *mut _, buf.capacity()) - })? as usize; + let buf_read = + cvt(unsafe { libc::readlink(p, buf.as_mut_ptr() as *mut _, buf.capacity()) })? as usize; - unsafe { buf.set_len(buf_read); } + unsafe { + buf.set_len(buf_read); + } if buf_read != buf.capacity() { buf.shrink_to_fit(); @@ -542,18 +570,14 @@ pub fn link(src: &Path, dst: &Path) -> io::Result<()> { pub fn stat(p: &Path) -> io::Result<FileAttr> { let p = cstr(p)?; let mut stat: stat64 = unsafe { mem::zeroed() }; - cvt(unsafe { - libc::stat(p.as_ptr(), &mut stat as *mut _ as *mut _) - })?; + cvt(unsafe { libc::stat(p.as_ptr(), &mut stat as *mut _ as *mut _) })?; Ok(FileAttr { stat }) } pub fn lstat(p: &Path) -> io::Result<FileAttr> { let p = cstr(p)?; let mut stat: stat64 = unsafe { mem::zeroed() }; - cvt(unsafe { - ::libc::lstat(p.as_ptr(), &mut stat as *mut _ as *mut _) - })?; + cvt(unsafe { ::libc::lstat(p.as_ptr(), &mut stat as *mut _ as *mut _) })?; Ok(FileAttr { stat }) } @@ -564,7 +588,7 @@ pub fn canonicalize(p: &Path) -> io::Result<PathBuf> { unsafe { let r = libc::realpath(path.as_ptr(), ptr::null_mut()); if r.is_null() { - return Err(io::Error::last_os_error()) + return Err(io::Error::last_os_error()); } buf = CStr::from_ptr(r).to_bytes().to_vec(); libc::free(r as *mut _); @@ -575,8 +599,10 @@ pub fn canonicalize(p: &Path) -> io::Result<PathBuf> { pub fn copy(from: &Path, to: &Path) -> io::Result<u64> { use crate::fs::File; if !from.is_file() { - return Err(Error::new(ErrorKind::InvalidInput, - "the source path is not an existing regular file")) + return Err(Error::new( + ErrorKind::InvalidInput, + "the source path is not an existing regular file", + )); } let mut reader = File::open(from)?; diff --git a/src/libstd/sys/vxworks/io.rs b/src/libstd/sys/vxworks/io.rs index 8cd11cbf5df..f1a2c8446ff 100644 --- a/src/libstd/sys/vxworks/io.rs +++ b/src/libstd/sys/vxworks/io.rs @@ -1,7 +1,7 @@ use crate::marker::PhantomData; use crate::slice; -use libc::{iovec, c_void}; +use libc::{c_void, iovec}; #[repr(transparent)] pub struct IoSlice<'a> { @@ -13,10 +13,7 @@ impl<'a> IoSlice<'a> { #[inline] pub fn new(buf: &'a [u8]) -> IoSlice<'a> { IoSlice { - vec: iovec { - iov_base: buf.as_ptr() as *mut u8 as *mut c_void, - iov_len: buf.len() - }, + vec: iovec { iov_base: buf.as_ptr() as *mut u8 as *mut c_void, iov_len: buf.len() }, _p: PhantomData, } } @@ -35,9 +32,7 @@ impl<'a> IoSlice<'a> { #[inline] pub fn as_slice(&self) -> &[u8] { - unsafe { - slice::from_raw_parts(self.vec.iov_base as *mut u8, self.vec.iov_len) - } + unsafe { slice::from_raw_parts(self.vec.iov_base as *mut u8, self.vec.iov_len) } } } @@ -50,10 +45,7 @@ impl<'a> IoSliceMut<'a> { #[inline] pub fn new(buf: &'a mut [u8]) -> IoSliceMut<'a> { IoSliceMut { - vec: iovec { - iov_base: buf.as_mut_ptr() as *mut c_void, - iov_len: buf.len() - }, + vec: iovec { iov_base: buf.as_mut_ptr() as *mut c_void, iov_len: buf.len() }, _p: PhantomData, } } @@ -72,15 +64,11 @@ impl<'a> IoSliceMut<'a> { #[inline] pub fn as_slice(&self) -> &[u8] { - unsafe { - slice::from_raw_parts(self.vec.iov_base as *mut u8, self.vec.iov_len) - } + unsafe { slice::from_raw_parts(self.vec.iov_base as *mut u8, self.vec.iov_len) } } #[inline] pub fn as_mut_slice(&mut self) -> &mut [u8] { - unsafe { - slice::from_raw_parts_mut(self.vec.iov_base as *mut u8, self.vec.iov_len) - } + unsafe { slice::from_raw_parts_mut(self.vec.iov_base as *mut u8, self.vec.iov_len) } } } diff --git a/src/libstd/sys/vxworks/memchr.rs b/src/libstd/sys/vxworks/memchr.rs index b5b4e6d9c13..928100c92ff 100644 --- a/src/libstd/sys/vxworks/memchr.rs +++ b/src/libstd/sys/vxworks/memchr.rs @@ -6,13 +6,10 @@ pub fn memchr(needle: u8, haystack: &[u8]) -> Option<usize> { libc::memchr( haystack.as_ptr() as *const libc::c_void, needle as libc::c_int, - haystack.len()) + haystack.len(), + ) }; - if p.is_null() { - None - } else { - Some(p as usize - (haystack.as_ptr() as usize)) - } + if p.is_null() { None } else { Some(p as usize - (haystack.as_ptr() as usize)) } } pub fn memrchr(needle: u8, haystack: &[u8]) -> Option<usize> { diff --git a/src/libstd/sys/vxworks/mod.rs b/src/libstd/sys/vxworks/mod.rs index 1eff4fbcd83..f102e4d6adf 100644 --- a/src/libstd/sys/vxworks/mod.rs +++ b/src/libstd/sys/vxworks/mod.rs @@ -3,8 +3,8 @@ use crate::io::ErrorKind; -pub use crate::os::vxworks as platform; pub use self::rand::hashmap_random_keys; +pub use crate::os::vxworks as platform; pub use libc::strlen; pub mod alloc; @@ -16,8 +16,8 @@ pub mod ext; pub mod fast_thread_local; pub mod fd; pub mod fs; -pub mod memchr; pub mod io; +pub mod memchr; pub mod mutex; pub mod net; pub mod os; @@ -27,10 +27,10 @@ pub mod process; pub mod rand; pub mod rwlock; pub mod stack_overflow; +pub mod stdio; pub mod thread; pub mod thread_local; pub mod time; -pub mod stdio; pub use crate::sys_common::os_str_bytes as os_str; @@ -47,7 +47,7 @@ pub fn init() { reset_sigpipe(); } - unsafe fn reset_sigpipe() { } + unsafe fn reset_sigpipe() {} } pub use libc::signal; @@ -71,8 +71,7 @@ pub fn decode_error_kind(errno: i32) -> ErrorKind { // These two constants can have the same value on some systems, // but different values on others, so we can't use a match // clause - x if x == libc::EAGAIN || x == libc::EWOULDBLOCK => - ErrorKind::WouldBlock, + x if x == libc::EAGAIN || x == libc::EWOULDBLOCK => ErrorKind::WouldBlock, _ => ErrorKind::Other, } @@ -94,16 +93,13 @@ macro_rules! impl_is_minus_one { impl_is_minus_one! { i8 i16 i32 i64 isize } pub fn cvt<T: IsMinusOne>(t: T) -> crate::io::Result<T> { - if t.is_minus_one() { - Err(crate::io::Error::last_os_error()) - } else { - Ok(t) - } + if t.is_minus_one() { Err(crate::io::Error::last_os_error()) } else { Ok(t) } } pub fn cvt_r<T, F>(mut f: F) -> crate::io::Result<T> - where T: IsMinusOne, - F: FnMut() -> T +where + T: IsMinusOne, + F: FnMut() -> T, { loop { match cvt(f()) { diff --git a/src/libstd/sys/vxworks/mutex.rs b/src/libstd/sys/vxworks/mutex.rs index b43af8fdcaa..b38375a2e03 100644 --- a/src/libstd/sys/vxworks/mutex.rs +++ b/src/libstd/sys/vxworks/mutex.rs @@ -1,7 +1,9 @@ use crate::cell::UnsafeCell; use crate::mem::MaybeUninit; -pub struct Mutex { inner: UnsafeCell<libc::pthread_mutex_t> } +pub struct Mutex { + inner: UnsafeCell<libc::pthread_mutex_t>, +} #[inline] pub unsafe fn raw(m: &Mutex) -> *mut libc::pthread_mutex_t { @@ -82,7 +84,9 @@ impl Mutex { } } -pub struct ReentrantMutex { inner: UnsafeCell<libc::pthread_mutex_t> } +pub struct ReentrantMutex { + inner: UnsafeCell<libc::pthread_mutex_t>, +} unsafe impl Send for ReentrantMutex {} unsafe impl Sync for ReentrantMutex {} @@ -96,8 +100,8 @@ impl ReentrantMutex { let mut attr = MaybeUninit::<libc::pthread_mutexattr_t>::uninit(); let result = libc::pthread_mutexattr_init(attr.as_mut_ptr()); debug_assert_eq!(result, 0); - let result = libc::pthread_mutexattr_settype(attr.as_mut_ptr(), - libc::PTHREAD_MUTEX_RECURSIVE); + let result = + libc::pthread_mutexattr_settype(attr.as_mut_ptr(), libc::PTHREAD_MUTEX_RECURSIVE); debug_assert_eq!(result, 0); let result = libc::pthread_mutex_init(self.inner.get(), attr.as_ptr()); debug_assert_eq!(result, 0); diff --git a/src/libstd/sys/vxworks/net.rs b/src/libstd/sys/vxworks/net.rs index 56962e11dcf..85f5fcff2c2 100644 --- a/src/libstd/sys/vxworks/net.rs +++ b/src/libstd/sys/vxworks/net.rs @@ -1,15 +1,15 @@ +use crate::cmp; use crate::ffi::CStr; use crate::io; use crate::io::{IoSlice, IoSliceMut}; -use libc::{self, c_int, c_void, size_t, sockaddr, socklen_t, EAI_SYSTEM, MSG_PEEK}; use crate::mem; -use crate::net::{SocketAddr, Shutdown}; +use crate::net::{Shutdown, SocketAddr}; use crate::str; use crate::sys::fd::FileDesc; -use crate::sys_common::{AsInner, FromInner, IntoInner}; use crate::sys_common::net::{getsockopt, setsockopt, sockaddr_to_addr}; +use crate::sys_common::{AsInner, FromInner, IntoInner}; use crate::time::{Duration, Instant}; -use crate::cmp; +use libc::{self, c_int, c_void, size_t, sockaddr, socklen_t, EAI_SYSTEM, MSG_PEEK}; pub use crate::sys::{cvt, cvt_r}; @@ -18,7 +18,6 @@ pub extern crate libc as netc; pub type wrlen_t = size_t; - const SOCK_CLOEXEC: c_int = 0; const SO_NOSIGPIPE: c_int = 0; @@ -28,23 +27,23 @@ pub fn init() {} pub fn cvt_gai(err: c_int) -> io::Result<()> { if err == 0 { - return Ok(()) + return Ok(()); } // We may need to trigger a glibc workaround. See on_resolver_failure() for details. on_resolver_failure(); if err == EAI_SYSTEM { - return Err(io::Error::last_os_error()) + return Err(io::Error::last_os_error()); } let detail = unsafe { - str::from_utf8(CStr::from_ptr(libc::gai_strerror(err)).to_bytes()).unwrap() - .to_owned() + str::from_utf8(CStr::from_ptr(libc::gai_strerror(err)).to_bytes()).unwrap().to_owned() }; - Err(io::Error::new(io::ErrorKind::Other, - &format!("failed to lookup address information: {}", - detail)[..])) + Err(io::Error::new( + io::ErrorKind::Other, + &format!("failed to lookup address information: {}", detail)[..], + )) } impl Socket { @@ -67,7 +66,7 @@ impl Socket { } pub fn new_pair(_fam: c_int, _ty: c_int) -> io::Result<(Socket, Socket)> { - unimplemented!(); + unimplemented!(); } pub fn connect_timeout(&self, addr: &SocketAddr, timeout: Duration) -> io::Result<()> { @@ -85,15 +84,13 @@ impl Socket { Err(e) => return Err(e), } - let mut pollfd = libc::pollfd { - fd: self.0.raw(), - events: libc::POLLOUT, - revents: 0, - }; + let mut pollfd = libc::pollfd { fd: self.0.raw(), events: libc::POLLOUT, revents: 0 }; if timeout.as_secs() == 0 && timeout.subsec_nanos() == 0 { - return Err(io::Error::new(io::ErrorKind::InvalidInput, - "cannot set a 0 duration timeout")); + return Err(io::Error::new( + io::ErrorKind::InvalidInput, + "cannot set a 0 duration timeout", + )); } let start = Instant::now(); @@ -105,7 +102,8 @@ impl Socket { } let timeout = timeout - elapsed; - let mut timeout = timeout.as_secs() + let mut timeout = timeout + .as_secs() .saturating_mul(1_000) .saturating_add(timeout.subsec_nanos() as u64 / 1_000_000); if timeout == 0 { @@ -126,10 +124,9 @@ impl Socket { // linux returns POLLOUT|POLLERR|POLLHUP for refused connections (!), so look // for POLLHUP rather than read readiness if pollfd.revents & libc::POLLHUP != 0 { - let e = self.take_error()? - .unwrap_or_else(|| { - io::Error::new(io::ErrorKind::Other, "no error set after POLLHUP") - }); + let e = self.take_error()?.unwrap_or_else(|| { + io::Error::new(io::ErrorKind::Other, "no error set after POLLHUP") + }); return Err(e); } @@ -139,11 +136,8 @@ impl Socket { } } - pub fn accept(&self, storage: *mut sockaddr, len: *mut socklen_t) - -> io::Result<Socket> { - let fd = cvt_r(|| unsafe { - libc::accept(self.0.raw(), storage, len) - })?; + pub fn accept(&self, storage: *mut sockaddr, len: *mut socklen_t) -> io::Result<Socket> { + let fd = cvt_r(|| unsafe { libc::accept(self.0.raw(), storage, len) })?; let fd = FileDesc::new(fd); fd.set_cloexec()?; Ok(Socket(fd)) @@ -155,10 +149,7 @@ impl Socket { fn recv_with_flags(&self, buf: &mut [u8], flags: c_int) -> io::Result<usize> { let ret = cvt(unsafe { - libc::recv(self.0.raw(), - buf.as_mut_ptr() as *mut c_void, - buf.len(), - flags) + libc::recv(self.0.raw(), buf.as_mut_ptr() as *mut c_void, buf.len(), flags) })?; Ok(ret as usize) } @@ -175,18 +166,23 @@ impl Socket { self.0.read_vectored(bufs) } - fn recv_from_with_flags(&self, buf: &mut [u8], flags: c_int) - -> io::Result<(usize, SocketAddr)> { + fn recv_from_with_flags( + &self, + buf: &mut [u8], + flags: c_int, + ) -> io::Result<(usize, SocketAddr)> { let mut storage: libc::sockaddr_storage = unsafe { mem::zeroed() }; let mut addrlen = mem::size_of_val(&storage) as libc::socklen_t; let n = cvt(unsafe { - libc::recvfrom(self.0.raw(), - buf.as_mut_ptr() as *mut c_void, - buf.len(), - flags, - &mut storage as *mut _ as *mut _, - &mut addrlen) + libc::recvfrom( + self.0.raw(), + buf.as_mut_ptr() as *mut c_void, + buf.len(), + flags, + &mut storage as *mut _ as *mut _, + &mut addrlen, + ) })?; Ok((n as usize, sockaddr_to_addr(&storage, addrlen as usize)?)) } @@ -211,8 +207,10 @@ impl Socket { let timeout = match dur { Some(dur) => { if dur.as_secs() == 0 && dur.subsec_nanos() == 0 { - return Err(io::Error::new(io::ErrorKind::InvalidInput, - "cannot set a 0 duration timeout")); + return Err(io::Error::new( + io::ErrorKind::InvalidInput, + "cannot set a 0 duration timeout", + )); } let secs = if dur.as_secs() > libc::time_t::max_value() as u64 { @@ -229,12 +227,7 @@ impl Socket { } timeout } - None => { - libc::timeval { - tv_sec: 0, - tv_usec: 0, - } - } + None => libc::timeval { tv_sec: 0, tv_usec: 0 }, }; setsockopt(self, libc::SOL_SOCKET, kind, timeout) } @@ -276,24 +269,26 @@ impl Socket { pub fn take_error(&self) -> io::Result<Option<io::Error>> { let raw: c_int = getsockopt(self, libc::SOL_SOCKET, libc::SO_ERROR)?; - if raw == 0 { - Ok(None) - } else { - Ok(Some(io::Error::from_raw_os_error(raw as i32))) - } + if raw == 0 { Ok(None) } else { Ok(Some(io::Error::from_raw_os_error(raw as i32))) } } } impl AsInner<c_int> for Socket { - fn as_inner(&self) -> &c_int { self.0.as_inner() } + fn as_inner(&self) -> &c_int { + self.0.as_inner() + } } impl FromInner<c_int> for Socket { - fn from_inner(fd: c_int) -> Socket { Socket(FileDesc::new(fd)) } + fn from_inner(fd: c_int) -> Socket { + Socket(FileDesc::new(fd)) + } } impl IntoInner<c_int> for Socket { - fn into_inner(self) -> c_int { self.0.into_raw() } + fn into_inner(self) -> c_int { + self.0.into_raw() + } } // In versions of glibc prior to 2.26, there's a bug where the DNS resolver @@ -314,7 +309,7 @@ impl IntoInner<c_int> for Socket { // believe it's thread-safe). #[cfg(target_env = "gnu")] fn on_resolver_failure() { -/* + /* use crate::sys; // If the version fails to parse, we treat it the same as "not glibc". diff --git a/src/libstd/sys/vxworks/path.rs b/src/libstd/sys/vxworks/path.rs index 7a183956107..840a7ae0426 100644 --- a/src/libstd/sys/vxworks/path.rs +++ b/src/libstd/sys/vxworks/path.rs @@ -1,5 +1,5 @@ -use crate::path::Prefix; use crate::ffi::OsStr; +use crate::path::Prefix; #[inline] pub fn is_sep_byte(b: u8) -> bool { diff --git a/src/libstd/sys/vxworks/pipe.rs b/src/libstd/sys/vxworks/pipe.rs index e09dbe6e99b..b72a6554551 100644 --- a/src/libstd/sys/vxworks/pipe.rs +++ b/src/libstd/sys/vxworks/pipe.rs @@ -1,9 +1,9 @@ use crate::io::{self, IoSlice, IoSliceMut}; -use libc::{self /*, c_int apparently not used? */}; use crate::mem; -use crate::sync::atomic::{AtomicBool}; +use crate::sync::atomic::AtomicBool; use crate::sys::fd::FileDesc; use crate::sys::{cvt, cvt_r}; +use libc::{self /*, c_int apparently not used? */}; pub struct AnonPipe(FileDesc); @@ -25,29 +25,29 @@ impl AnonPipe { self.0.read(buf) } pub fn read_vectored(&self, bufs: &mut [IoSliceMut<'_>]) -> io::Result<usize> { - self.0.read_vectored(bufs) - } + self.0.read_vectored(bufs) + } pub fn write(&self, buf: &[u8]) -> io::Result<usize> { self.0.write(buf) } - pub fn write_vectored(&self, bufs: &[IoSlice<'_>]) -> io::Result<usize> { - self.0.write_vectored(bufs) - } + pub fn write_vectored(&self, bufs: &[IoSlice<'_>]) -> io::Result<usize> { + self.0.write_vectored(bufs) + } - pub fn fd(&self) -> &FileDesc { &self.0 } - pub fn into_fd(self) -> FileDesc { self.0 } + pub fn fd(&self) -> &FileDesc { + &self.0 + } + pub fn into_fd(self) -> FileDesc { + self.0 + } pub fn diverge(&self) -> ! { panic!() - } + } } -pub fn read2(p1: AnonPipe, - v1: &mut Vec<u8>, - p2: AnonPipe, - v2: &mut Vec<u8>) -> io::Result<()> { - +pub fn read2(p1: AnonPipe, v1: &mut Vec<u8>, p2: AnonPipe, v2: &mut Vec<u8>) -> io::Result<()> { // Set both pipes into nonblocking mode as we're gonna be reading from both // in the `select` loop below, and we wouldn't want one to block the other! let p1 = p1.into_fd(); @@ -83,8 +83,9 @@ pub fn read2(p1: AnonPipe, match fd.read_to_end(dst) { Ok(_) => Ok(true), Err(e) => { - if e.raw_os_error() == Some(libc::EWOULDBLOCK) || - e.raw_os_error() == Some(libc::EAGAIN) { + if e.raw_os_error() == Some(libc::EWOULDBLOCK) + || e.raw_os_error() == Some(libc::EAGAIN) + { Ok(false) } else { Err(e) diff --git a/src/libstd/sys/vxworks/process/mod.rs b/src/libstd/sys/vxworks/process/mod.rs index 3ecbe4e3b28..c59782ff44b 100644 --- a/src/libstd/sys/vxworks/process/mod.rs +++ b/src/libstd/sys/vxworks/process/mod.rs @@ -1,4 +1,4 @@ -pub use self::process_common::{Command, ExitStatus, ExitCode, Stdio, StdioPipes}; +pub use self::process_common::{Command, ExitCode, ExitStatus, Stdio, StdioPipes}; pub use self::process_inner::Process; pub use crate::ffi::OsString as EnvKey; diff --git a/src/libstd/sys/vxworks/process/process_common.rs b/src/libstd/sys/vxworks/process/process_common.rs index 13648abd1e4..a8139a27537 100644 --- a/src/libstd/sys/vxworks/process/process_common.rs +++ b/src/libstd/sys/vxworks/process/process_common.rs @@ -1,6 +1,7 @@ use crate::os::unix::prelude::*; -use crate::ffi::{OsString, OsStr, CString, CStr}; +use crate::collections::BTreeMap; +use crate::ffi::{CStr, CString, OsStr, OsString}; use crate::fmt; use crate::io; use crate::ptr; @@ -8,9 +9,8 @@ use crate::sys::fd::FileDesc; use crate::sys::fs::{File, OpenOptions}; use crate::sys::pipe::{self, AnonPipe}; use crate::sys_common::process::CommandEnv; -use crate::collections::BTreeMap; -use libc::{c_int, gid_t, uid_t, c_char, EXIT_SUCCESS, EXIT_FAILURE}; +use libc::{c_char, c_int, gid_t, uid_t, EXIT_FAILURE, EXIT_SUCCESS}; //////////////////////////////////////////////////////////////////////////////// // Command @@ -150,10 +150,7 @@ impl Command { &mut self.closures } - pub unsafe fn pre_exec( - &mut self, - _f: Box<dyn FnMut() -> io::Result<()> + Send + Sync>, - ) { + pub unsafe fn pre_exec(&mut self, _f: Box<dyn FnMut() -> io::Result<()> + Send + Sync>) { // Fork() is not supported in vxWorks so no way to run the closure in the new procecss. unimplemented!(); } @@ -183,26 +180,21 @@ impl Command { self.env.have_changed_path() } - pub fn setup_io(&self, default: Stdio, needs_stdin: bool) - -> io::Result<(StdioPipes, ChildPipes)> { + pub fn setup_io( + &self, + default: Stdio, + needs_stdin: bool, + ) -> io::Result<(StdioPipes, ChildPipes)> { let null = Stdio::Null; - let default_stdin = if needs_stdin {&default} else {&null}; + let default_stdin = if needs_stdin { &default } else { &null }; let stdin = self.stdin.as_ref().unwrap_or(default_stdin); let stdout = self.stdout.as_ref().unwrap_or(&default); let stderr = self.stderr.as_ref().unwrap_or(&default); let (their_stdin, our_stdin) = stdin.to_child_stdio(true)?; let (their_stdout, our_stdout) = stdout.to_child_stdio(false)?; let (their_stderr, our_stderr) = stderr.to_child_stdio(false)?; - let ours = StdioPipes { - stdin: our_stdin, - stdout: our_stdout, - stderr: our_stderr, - }; - let theirs = ChildPipes { - stdin: their_stdin, - stdout: their_stdout, - stderr: their_stderr, - }; + let ours = StdioPipes { stdin: our_stdin, stdout: our_stdout, stderr: our_stderr }; + let theirs = ChildPipes { stdin: their_stdin, stdout: their_stdout, stderr: their_stderr }; Ok((ours, theirs)) } } @@ -217,21 +209,21 @@ fn os2c(s: &OsStr, saw_nul: &mut bool) -> CString { // Helper type to manage ownership of the strings within a C-style array. pub struct CStringArray { items: Vec<CString>, - ptrs: Vec<*const c_char> + ptrs: Vec<*const c_char>, } impl CStringArray { pub fn with_capacity(capacity: usize) -> Self { let mut result = CStringArray { items: Vec::with_capacity(capacity), - ptrs: Vec::with_capacity(capacity+1) + ptrs: Vec::with_capacity(capacity + 1), }; result.ptrs.push(ptr::null()); result } pub fn push(&mut self, item: CString) { let l = self.ptrs.len(); - self.ptrs[l-1] = item.as_ptr(); + self.ptrs[l - 1] = item.as_ptr(); self.ptrs.push(ptr::null()); self.items.push(item); } @@ -262,12 +254,9 @@ fn construct_envp(env: BTreeMap<OsString, OsString>, saw_nul: &mut bool) -> CStr } impl Stdio { - pub fn to_child_stdio(&self, readable: bool) - -> io::Result<(ChildStdio, Option<AnonPipe>)> { + pub fn to_child_stdio(&self, readable: bool) -> io::Result<(ChildStdio, Option<AnonPipe>)> { match *self { - Stdio::Inherit => { - Ok((ChildStdio::Inherit, None)) - }, + Stdio::Inherit => Ok((ChildStdio::Inherit, None)), // Make sure that the source descriptors are not an stdio // descriptor, otherwise the order which we set the child's @@ -286,11 +275,7 @@ impl Stdio { Stdio::MakePipe => { let (reader, writer) = pipe::anon_pipe()?; - let (ours, theirs) = if readable { - (writer, reader) - } else { - (reader, writer) - }; + let (ours, theirs) = if readable { (writer, reader) } else { (reader, writer) }; Ok((ChildStdio::Owned(theirs.into_fd()), Some(ours))) } @@ -298,9 +283,7 @@ impl Stdio { let mut opts = OpenOptions::new(); opts.read(readable); opts.write(!readable); - let path = unsafe { - CStr::from_ptr("/null\0".as_ptr() as *const _) - }; + let path = unsafe { CStr::from_ptr("/null\0".as_ptr() as *const _) }; let fd = File::open_c(&path, &opts)?; Ok((ChildStdio::Owned(fd.into_fd()), None)) } @@ -350,7 +333,8 @@ impl ExitStatus { } fn exited(&self) -> bool { - /*unsafe*/ { libc::WIFEXITED(self.0) } + /*unsafe*/ + { libc::WIFEXITED(self.0) } } pub fn success(&self) -> bool { diff --git a/src/libstd/sys/vxworks/rand.rs b/src/libstd/sys/vxworks/rand.rs index c22880db2bf..87ebd2c9593 100644 --- a/src/libstd/sys/vxworks/rand.rs +++ b/src/libstd/sys/vxworks/rand.rs @@ -4,17 +4,16 @@ use crate::slice; pub fn hashmap_random_keys() -> (u64, u64) { let mut v = (0, 0); unsafe { - let view = slice::from_raw_parts_mut(&mut v as *mut _ as *mut u8, - mem::size_of_val(&v)); + let view = slice::from_raw_parts_mut(&mut v as *mut _ as *mut u8, mem::size_of_val(&v)); imp::fill_bytes(view); } - return v + return v; } mod imp { - use libc; use crate::io; use core::sync::atomic::{AtomicBool, Ordering::Relaxed}; + use libc; pub fn fill_bytes(v: &mut [u8]) { static RNG_INIT: AtomicBool = AtomicBool::new(false); diff --git a/src/libstd/sys/vxworks/rwlock.rs b/src/libstd/sys/vxworks/rwlock.rs index 19b123f2b61..fd2e1a6e7bc 100644 --- a/src/libstd/sys/vxworks/rwlock.rs +++ b/src/libstd/sys/vxworks/rwlock.rs @@ -1,6 +1,6 @@ -use libc; use crate::cell::UnsafeCell; use crate::sync::atomic::{AtomicUsize, Ordering}; +use libc; pub struct RWLock { inner: UnsafeCell<libc::pthread_rwlock_t>, @@ -29,7 +29,7 @@ impl RWLock { if r == 0 { self.raw_unlock(); } - panic!("rwlock read lock would result in deadlock"); + panic!("rwlock read lock would result in deadlock"); } else { debug_assert_eq!(r, 0); self.num_readers.fetch_add(1, Ordering::Relaxed); @@ -57,12 +57,14 @@ impl RWLock { let r = libc::pthread_rwlock_wrlock(self.inner.get()); // See comments above for why we check for EDEADLK and write_locked. We // also need to check that num_readers is 0. - if r == libc::EDEADLK || *self.write_locked.get() || - self.num_readers.load(Ordering::Relaxed) != 0 { + if r == libc::EDEADLK + || *self.write_locked.get() + || self.num_readers.load(Ordering::Relaxed) != 0 + { if r == 0 { self.raw_unlock(); } - panic!("rwlock write lock would result in deadlock"); + panic!("rwlock write lock would result in deadlock"); } else { debug_assert_eq!(r, 0); } @@ -80,8 +82,8 @@ impl RWLock { *self.write_locked.get() = true; true } - } else { - false + } else { + false } } @@ -98,7 +100,7 @@ impl RWLock { self.raw_unlock(); } - #[inline] + #[inline] pub unsafe fn write_unlock(&self) { debug_assert_eq!(self.num_readers.load(Ordering::Relaxed), 0); debug_assert!(*self.write_locked.get()); diff --git a/src/libstd/sys/vxworks/stack_overflow.rs b/src/libstd/sys/vxworks/stack_overflow.rs index 08e7b310ca1..7b58c83193b 100644 --- a/src/libstd/sys/vxworks/stack_overflow.rs +++ b/src/libstd/sys/vxworks/stack_overflow.rs @@ -1,12 +1,12 @@ #![cfg_attr(test, allow(dead_code))] -use self::imp::{make_handler, drop_handler}; +use self::imp::{drop_handler, make_handler}; pub use self::imp::cleanup; pub use self::imp::init; pub struct Handler { - _data: *mut libc::c_void + _data: *mut libc::c_void, } impl Handler { @@ -26,16 +26,13 @@ impl Drop for Handler { mod imp { use crate::ptr; - pub unsafe fn init() { - } + pub unsafe fn init() {} - pub unsafe fn cleanup() { - } + pub unsafe fn cleanup() {} pub unsafe fn make_handler() -> super::Handler { super::Handler { _data: ptr::null_mut() } } - pub unsafe fn drop_handler(_handler: &mut super::Handler) { - } + pub unsafe fn drop_handler(_handler: &mut super::Handler) {} } diff --git a/src/libstd/sys/vxworks/stdio.rs b/src/libstd/sys/vxworks/stdio.rs index 35f163bbdb1..622444ccafd 100644 --- a/src/libstd/sys/vxworks/stdio.rs +++ b/src/libstd/sys/vxworks/stdio.rs @@ -6,7 +6,9 @@ pub struct Stdout(()); pub struct Stderr(()); impl Stdin { - pub fn new() -> io::Result<Stdin> { Ok(Stdin(())) } + pub fn new() -> io::Result<Stdin> { + Ok(Stdin(())) + } } impl io::Read for Stdin { @@ -19,7 +21,9 @@ impl io::Read for Stdin { } impl Stdout { - pub fn new() -> io::Result<Stdout> { Ok(Stdout(())) } + pub fn new() -> io::Result<Stdout> { + Ok(Stdout(())) + } } impl io::Write for Stdout { @@ -36,7 +40,9 @@ impl io::Write for Stdout { } impl Stderr { - pub fn new() -> io::Result<Stderr> { Ok(Stderr(())) } + pub fn new() -> io::Result<Stderr> { + Ok(Stderr(())) + } } impl io::Write for Stderr { diff --git a/src/libstd/sys/vxworks/thread.rs b/src/libstd/sys/vxworks/thread.rs index e4396b05c00..e0d104b5f3e 100644 --- a/src/libstd/sys/vxworks/thread.rs +++ b/src/libstd/sys/vxworks/thread.rs @@ -21,15 +21,16 @@ unsafe impl Sync for Thread {} // The pthread_attr_setstacksize symbol doesn't exist in the emscripten libc, // so we have to not link to it to satisfy emcc's ERROR_ON_UNDEFINED_SYMBOLS. -unsafe fn pthread_attr_setstacksize(attr: *mut libc::pthread_attr_t, - stack_size: libc::size_t) -> libc::c_int { +unsafe fn pthread_attr_setstacksize( + attr: *mut libc::pthread_attr_t, + stack_size: libc::size_t, +) -> libc::c_int { libc::pthread_attr_setstacksize(attr, stack_size) } impl Thread { // unsafe: see thread::Builder::spawn_unchecked for safety requirements - pub unsafe fn new(stack: usize, p: Box<dyn FnOnce()>) - -> io::Result<Thread> { + pub unsafe fn new(stack: usize, p: Box<dyn FnOnce()>) -> io::Result<Thread> { let p = box p; let mut native: libc::pthread_t = mem::zeroed(); let mut attr: libc::pthread_attr_t = mem::zeroed(); @@ -37,8 +38,7 @@ impl Thread { let stack_size = cmp::max(stack, min_stack_size(&attr)); - match pthread_attr_setstacksize(&mut attr, - stack_size) { + match pthread_attr_setstacksize(&mut attr, stack_size) { 0 => {} n => { assert_eq!(n, libc::EINVAL); @@ -47,15 +47,13 @@ impl Thread { // >= PTHREAD_STACK_MIN, it must be an alignment issue. // Round up to the nearest page and try again. let page_size = os::page_size(); - let stack_size = (stack_size + page_size - 1) & - (-(page_size as isize - 1) as usize - 1); - assert_eq!(libc::pthread_attr_setstacksize(&mut attr, - stack_size), 0); + let stack_size = + (stack_size + page_size - 1) & (-(page_size as isize - 1) as usize - 1); + assert_eq!(libc::pthread_attr_setstacksize(&mut attr, stack_size), 0); } }; - let ret = libc::pthread_create(&mut native, &attr, thread_start, - &*p as *const _ as *mut _); + let ret = libc::pthread_create(&mut native, &attr, thread_start, &*p as *const _ as *mut _); assert_eq!(libc::pthread_attr_destroy(&mut attr), 0); return if ret != 0 { @@ -65,8 +63,10 @@ impl Thread { Ok(Thread { id: native }) }; - extern fn thread_start(main: *mut libc::c_void) -> *mut libc::c_void { - unsafe { start_thread(main as *mut u8); } + extern "C" fn thread_start(main: *mut libc::c_void) -> *mut libc::c_void { + unsafe { + start_thread(main as *mut u8); + } ptr::null_mut() } } @@ -108,12 +108,13 @@ impl Thread { unsafe { let ret = libc::pthread_join(self.id, ptr::null_mut()); mem::forget(self); - assert!(ret == 0, - "failed to join thread: {}", io::Error::from_raw_os_error(ret)); + assert!(ret == 0, "failed to join thread: {}", io::Error::from_raw_os_error(ret)); } } - pub fn id(&self) -> libc::pthread_t { self.id } + pub fn id(&self) -> libc::pthread_t { + self.id + } pub fn into_id(self) -> libc::pthread_t { let id = self.id; @@ -133,8 +134,12 @@ impl Drop for Thread { pub mod guard { use crate::ops::Range; pub type Guard = Range<usize>; - pub unsafe fn current() -> Option<Guard> { None } - pub unsafe fn init() -> Option<Guard> { None } + pub unsafe fn current() -> Option<Guard> { + None + } + pub unsafe fn init() -> Option<Guard> { + None + } pub unsafe fn deinit() {} } diff --git a/src/libstd/sys/vxworks/thread_local.rs b/src/libstd/sys/vxworks/thread_local.rs index ac615b76b36..2c5b94b1e61 100644 --- a/src/libstd/sys/vxworks/thread_local.rs +++ b/src/libstd/sys/vxworks/thread_local.rs @@ -5,7 +5,7 @@ use crate::mem; pub type Key = libc::pthread_key_t; #[inline] -pub unsafe fn create(dtor: Option<unsafe extern fn(*mut u8)>) -> Key { +pub unsafe fn create(dtor: Option<unsafe extern "C" fn(*mut u8)>) -> Key { let mut key = 0; assert_eq!(libc::pthread_key_create(&mut key, mem::transmute(dtor)), 0); key diff --git a/src/libstd/sys/vxworks/time.rs b/src/libstd/sys/vxworks/time.rs index cb3a4241ea6..8ebbf89213f 100644 --- a/src/libstd/sys/vxworks/time.rs +++ b/src/libstd/sys/vxworks/time.rs @@ -1,7 +1,7 @@ use crate::cmp::Ordering; -use libc; use crate::time::Duration; use ::core::hash::{Hash, Hasher}; +use libc; pub use self::inner::{Instant, SystemTime, UNIX_EPOCH}; use crate::convert::TryInto; @@ -15,20 +15,21 @@ struct Timespec { impl Timespec { const fn zero() -> Timespec { - Timespec { - t: libc::timespec { tv_sec: 0, tv_nsec: 0 }, - } + Timespec { t: libc::timespec { tv_sec: 0, tv_nsec: 0 } } } fn sub_timespec(&self, other: &Timespec) -> Result<Duration, Duration> { if self >= other { Ok(if self.t.tv_nsec >= other.t.tv_nsec { - Duration::new((self.t.tv_sec - other.t.tv_sec) as u64, - (self.t.tv_nsec - other.t.tv_nsec) as u32) - } else { - Duration::new((self.t.tv_sec - 1 - other.t.tv_sec) as u64, - self.t.tv_nsec as u32 + (NSEC_PER_SEC as u32) - - other.t.tv_nsec as u32) - }) + Duration::new( + (self.t.tv_sec - other.t.tv_sec) as u64, + (self.t.tv_nsec - other.t.tv_nsec) as u32, + ) + } else { + Duration::new( + (self.t.tv_sec - 1 - other.t.tv_sec) as u64, + self.t.tv_nsec as u32 + (NSEC_PER_SEC as u32) - other.t.tv_nsec as u32, + ) + }) } else { match other.sub_timespec(self) { Ok(d) => Err(d), @@ -51,12 +52,7 @@ impl Timespec { nsec -= NSEC_PER_SEC as u32; secs = secs.checked_add(1)?; } - Some(Timespec { - t: libc::timespec { - tv_sec: secs, - tv_nsec: nsec as _, - }, - }) + Some(Timespec { t: libc::timespec { tv_sec: secs, tv_nsec: nsec as _ } }) } fn checked_sub_duration(&self, other: &Duration) -> Option<Timespec> { @@ -72,12 +68,7 @@ impl Timespec { nsec += NSEC_PER_SEC as i32; secs = secs.checked_sub(1)?; } - Some(Timespec { - t: libc::timespec { - tv_sec: secs, - tv_nsec: nsec as _, - }, - }) + Some(Timespec { t: libc::timespec { tv_sec: secs, tv_nsec: nsec as _ } }) } } @@ -104,16 +95,16 @@ impl Ord for Timespec { } impl Hash for Timespec { - fn hash<H : Hasher>(&self, state: &mut H) { + fn hash<H: Hasher>(&self, state: &mut H) { self.t.tv_sec.hash(state); self.t.tv_nsec.hash(state); } } mod inner { use crate::fmt; - use libc; use crate::sys::cvt; use crate::time::Duration; + use libc; use super::Timespec; @@ -127,14 +118,8 @@ mod inner { t: Timespec, } - pub const UNIX_EPOCH: SystemTime = SystemTime { - t: Timespec { - t: libc::timespec { - tv_sec: 0, - tv_nsec: 0, - }, - }, - }; + pub const UNIX_EPOCH: SystemTime = + SystemTime { t: Timespec { t: libc::timespec { tv_sec: 0, tv_nsec: 0 } } }; impl Instant { pub fn now() -> Instant { @@ -142,9 +127,7 @@ mod inner { } pub const fn zero() -> Instant { - Instant { - t: Timespec::zero(), - } + Instant { t: Timespec::zero() } } pub fn actually_monotonic() -> bool { @@ -167,9 +150,9 @@ mod inner { impl fmt::Debug for Instant { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.debug_struct("Instant") - .field("tv_sec", &self.t.t.tv_sec) - .field("tv_nsec", &self.t.t.tv_nsec) - .finish() + .field("tv_sec", &self.t.t.tv_sec) + .field("tv_nsec", &self.t.t.tv_nsec) + .finish() } } @@ -178,8 +161,7 @@ mod inner { SystemTime { t: now(libc::CLOCK_REALTIME) } } - pub fn sub_time(&self, other: &SystemTime) - -> Result<Duration, Duration> { + pub fn sub_time(&self, other: &SystemTime) -> Result<Duration, Duration> { self.t.sub_timespec(&other.t) } @@ -201,24 +183,17 @@ mod inner { impl fmt::Debug for SystemTime { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.debug_struct("SystemTime") - .field("tv_sec", &self.t.t.tv_sec) - .field("tv_nsec", &self.t.t.tv_nsec) - .finish() + .field("tv_sec", &self.t.t.tv_sec) + .field("tv_nsec", &self.t.t.tv_nsec) + .finish() } } pub type clock_t = libc::c_int; fn now(clock: clock_t) -> Timespec { - let mut t = Timespec { - t: libc::timespec { - tv_sec: 0, - tv_nsec: 0, - } - }; - cvt(unsafe { - libc::clock_gettime(clock, &mut t.t) - }).unwrap(); + let mut t = Timespec { t: libc::timespec { tv_sec: 0, tv_nsec: 0 } }; + cvt(unsafe { libc::clock_gettime(clock, &mut t.t) }).unwrap(); t } } diff --git a/src/libstd/sys/vxworks/weak.rs b/src/libstd/sys/vxworks/weak.rs index 284f2116423..4c6fddefd3f 100644 --- a/src/libstd/sys/vxworks/weak.rs +++ b/src/libstd/sys/vxworks/weak.rs @@ -29,11 +29,7 @@ pub struct Weak<F> { impl<F> Weak<F> { pub const fn new(name: &'static str) -> Weak<F> { - Weak { - name, - addr: AtomicUsize::new(1), - _marker: marker::PhantomData, - } + Weak { name, addr: AtomicUsize::new(1), _marker: marker::PhantomData } } pub fn get(&self) -> Option<F> { @@ -56,5 +52,5 @@ unsafe fn fetch(name: &str) -> usize { Err(..) => return 0, }; assert!(false, "FIXME: fetch"); - libc::dlsym(libc::RTLD_DEFAULT, name.as_ptr()) as usize + libc::dlsym(libc::RTLD_DEFAULT, name.as_ptr()) as usize } |
