diff --git a/src/fcntl.rs b/src/fcntl.rs index ca0a226622..2e2d8aa212 100644 --- a/src/fcntl.rs +++ b/src/fcntl.rs @@ -7,7 +7,7 @@ pub use self::consts::*; pub use self::ffi::flock; // Re-export Fd defined in std -pub type Fd = ::std::os::unix::io::Fd; +pub type Fd = ::std::os::unix::io::RawFd; #[allow(dead_code)] mod ffi { @@ -19,7 +19,7 @@ mod ffi { use libc::{c_int, c_short, off_t, pid_t}; #[repr(C)] - #[derive(Copy)] + #[derive(Clone, Copy)] pub struct flock { pub l_type: c_short, pub l_whence: c_short, @@ -47,7 +47,7 @@ mod ffi { use libc::{c_int, c_short, off_t, pid_t}; #[repr(C)] - #[derive(Copy)] + #[derive(Clone, Copy)] pub struct flock { pub l_start: off_t, pub l_len: off_t, diff --git a/src/lib.rs b/src/lib.rs index 09d96509fa..3731d39cb2 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -4,7 +4,7 @@ //! defined in. #![crate_name = "nix"] -#![feature(collections, core, io_ext, linkage, std_misc)] +#![feature(collections, core, linkage, std_misc)] #![allow(non_camel_case_types)] #[macro_use] diff --git a/src/sched.rs b/src/sched.rs index 4b6c955f88..c1746f2e1b 100644 --- a/src/sched.rs +++ b/src/sched.rs @@ -89,7 +89,7 @@ pub type CpuMask = c_ulong; // Structure representing the CPU set to apply #[repr(C)] -#[derive(Copy)] +#[derive(Clone, Copy)] pub struct CpuSet { cpu_mask: [CpuMask; cpuset_attribs::CPU_SETSIZE/cpuset_attribs::CPU_MASK_BITS] } diff --git a/src/sys/epoll.rs b/src/sys/epoll.rs index a68a7b6f8f..1028af78f6 100644 --- a/src/sys/epoll.rs +++ b/src/sys/epoll.rs @@ -70,7 +70,7 @@ impl fmt::Debug for EpollEventKind { } } -#[derive(Copy)] +#[derive(Clone, Copy)] #[repr(C)] pub enum EpollOp { EpollCtlAdd = 1, @@ -94,7 +94,7 @@ fn test_epoll_event_size() { } #[cfg(any(not(target_os = "android"), target_arch = "x86_64"))] -#[derive(Copy)] +#[derive(Clone, Copy)] #[repr(C, packed)] pub struct EpollEvent { pub events: EpollEventKind, diff --git a/src/sys/event.rs b/src/sys/event.rs index 9a0ede1e0d..c2c65dad21 100644 --- a/src/sys/event.rs +++ b/src/sys/event.rs @@ -13,7 +13,7 @@ mod ffi { pub use libc::{c_int, c_void, uintptr_t, intptr_t, timespec}; use super::{EventFilter, EventFlag, FilterFlag}; - #[derive(Copy)] + #[derive(Clone, Copy)] #[repr(C)] pub struct kevent { pub ident: uintptr_t, // 8 @@ -40,7 +40,7 @@ mod ffi { } #[repr(i16)] -#[derive(Copy, Debug, PartialEq)] +#[derive(Clone, Copy, Debug, PartialEq)] pub enum EventFilter { EVFILT_READ = -1, EVFILT_WRITE = -2, diff --git a/src/sys/ioctl.rs b/src/sys/ioctl.rs index 5003a4f682..18b8b1abe4 100644 --- a/src/sys/ioctl.rs +++ b/src/sys/ioctl.rs @@ -8,7 +8,7 @@ pub use self::IoctlArg::*; mod ffi { use libc::c_ushort; - #[derive(Copy, Debug)] + #[derive(Clone, Copy, Debug)] pub struct Winsize { pub ws_row: c_ushort, pub ws_col: c_ushort, diff --git a/src/sys/signal.rs b/src/sys/signal.rs index 5dd974cc02..afeb9c6cb5 100644 --- a/src/sys/signal.rs +++ b/src/sys/signal.rs @@ -96,7 +96,7 @@ pub mod signal { // actually a giant union. Currently we're only interested in these fields, // however. #[repr(C)] - #[derive(Copy)] + #[derive(Clone, Copy)] pub struct siginfo { si_signo: libc::c_int, si_errno: libc::c_int, @@ -117,14 +117,14 @@ pub mod signal { #[repr(C)] #[cfg(target_pointer_width = "32")] - #[derive(Copy)] + #[derive(Clone, Copy)] pub struct sigset_t { __val: [libc::c_ulong; 32], } #[repr(C)] #[cfg(target_pointer_width = "64")] - #[derive(Copy)] + #[derive(Clone, Copy)] pub struct sigset_t { __val: [libc::c_ulong; 16], } @@ -249,7 +249,7 @@ pub mod signal { // This structure has more fields, but we're not all that interested in // them. #[repr(C)] - #[derive(Copy)] + #[derive(Clone, Copy)] pub struct siginfo { pub si_signo: libc::c_int, pub si_errno: libc::c_int, @@ -297,7 +297,7 @@ mod ffi { } } -#[derive(Copy)] +#[derive(Clone, Copy)] pub struct SigSet { sigset: sigset_t } diff --git a/src/sys/socket/addr.rs b/src/sys/socket/addr.rs index 34028246bd..1ae5a9c3e1 100644 --- a/src/sys/socket/addr.rs +++ b/src/sys/socket/addr.rs @@ -275,7 +275,7 @@ impl fmt::Display for Ipv4Addr { * */ -#[derive(Copy)] +#[derive(Clone, Copy)] pub struct Ipv6Addr(pub libc::in6_addr); impl Ipv6Addr { diff --git a/src/sys/socket/mod.rs b/src/sys/socket/mod.rs index 33d5830176..ea5c99167f 100644 --- a/src/sys/socket/mod.rs +++ b/src/sys/socket/mod.rs @@ -57,7 +57,7 @@ pub struct sockaddr_storage { pub __ss_pad2: [u8; 120], } -#[derive(Copy, PartialEq, Eq, Debug, FromPrimitive)] +#[derive(Clone, Copy, PartialEq, Eq, Debug, FromPrimitive)] #[repr(i32)] pub enum SockType { Stream = consts::SOCK_STREAM, @@ -78,7 +78,7 @@ bitflags!( /// Create an endpoint for communication /// /// [Further reading](http://man7.org/linux/man-pages/man2/socket.2.html) -pub fn socket(domain: AddressFamily, ty: SockType, flags: SockFlag) -> Result { +pub fn socket(domain: AddressFamily, ty: SockType, flags: SockFlag) -> Result { let mut ty = ty as c_int; let feat_atomic = features::socket_atomic_cloexec(); @@ -109,7 +109,7 @@ pub fn socket(domain: AddressFamily, ty: SockType, flags: SockFlag) -> Result Result<()> { +pub fn listen(sockfd: RawFd, backlog: usize) -> Result<()> { let res = unsafe { ffi::listen(sockfd, backlog as c_int) }; from_ffi(res) } @@ -117,7 +117,7 @@ pub fn listen(sockfd: Fd, backlog: usize) -> Result<()> { /// Bind a name to a socket /// /// [Further reading](http://man7.org/linux/man-pages/man2/bind.2.html) -pub fn bind(fd: Fd, addr: &SockAddr) -> Result<()> { +pub fn bind(fd: RawFd, addr: &SockAddr) -> Result<()> { let res = unsafe { let (ptr, len) = addr.as_ffi_pair(); ffi::bind(fd, ptr, len) @@ -129,7 +129,7 @@ pub fn bind(fd: Fd, addr: &SockAddr) -> Result<()> { /// Accept a connection on a socket /// /// [Further reading](http://man7.org/linux/man-pages/man2/accept.2.html) -pub fn accept(sockfd: Fd) -> Result { +pub fn accept(sockfd: RawFd) -> Result { let res = unsafe { ffi::accept(sockfd, ptr::null_mut(), ptr::null_mut()) }; if res < 0 { @@ -143,7 +143,7 @@ pub fn accept(sockfd: Fd) -> Result { /// /// [Further reading](http://man7.org/linux/man-pages/man2/accept.2.html) #[cfg(not(any(target_os = "macos", target_os = "ios", target_os = "android")))] -pub fn accept4(sockfd: Fd, flags: SockFlag) -> Result { +pub fn accept4(sockfd: RawFd, flags: SockFlag) -> Result { use libc::sockaddr; type F = unsafe extern "C" fn(c_int, *mut sockaddr, *mut socklen_t, c_int) -> c_int; @@ -173,12 +173,12 @@ pub fn accept4(sockfd: Fd, flags: SockFlag) -> Result { /// /// [Further reading](http://man7.org/linux/man-pages/man2/accept.2.html) #[cfg(any(target_os = "macos", target_os = "ios", target_os = "android"))] -pub fn accept4(sockfd: Fd, flags: SockFlag) -> Result { +pub fn accept4(sockfd: RawFd, flags: SockFlag) -> Result { accept4_polyfill(sockfd, flags) } #[inline] -fn accept4_polyfill(sockfd: Fd, flags: SockFlag) -> Result { +fn accept4_polyfill(sockfd: RawFd, flags: SockFlag) -> Result { let res = unsafe { ffi::accept(sockfd, ptr::null_mut(), ptr::null_mut()) }; if res < 0 { @@ -199,7 +199,7 @@ fn accept4_polyfill(sockfd: Fd, flags: SockFlag) -> Result { /// Initiate a connection on a socket /// /// [Further reading](http://man7.org/linux/man-pages/man2/connect.2.html) -pub fn connect(fd: Fd, addr: &SockAddr) -> Result<()> { +pub fn connect(fd: RawFd, addr: &SockAddr) -> Result<()> { let res = unsafe { let (ptr, len) = addr.as_ffi_pair(); ffi::connect(fd, ptr, len) @@ -212,7 +212,7 @@ pub fn connect(fd: Fd, addr: &SockAddr) -> Result<()> { /// the number of bytes read and the socket address of the sender. /// /// [Further reading](http://man7.org/linux/man-pages/man2/recvmsg.2.html) -pub fn recvfrom(sockfd: Fd, buf: &mut [u8]) -> Result<(usize, SockAddr)> { +pub fn recvfrom(sockfd: RawFd, buf: &mut [u8]) -> Result<(usize, SockAddr)> { unsafe { let addr: sockaddr_storage = mem::zeroed(); let mut len = mem::size_of::() as socklen_t; @@ -234,7 +234,7 @@ pub fn recvfrom(sockfd: Fd, buf: &mut [u8]) -> Result<(usize, SockAddr)> { } } -pub fn sendto(fd: Fd, buf: &[u8], addr: &SockAddr, flags: SockMessageFlags) -> Result { +pub fn sendto(fd: RawFd, buf: &[u8], addr: &SockAddr, flags: SockMessageFlags) -> Result { let ret = unsafe { let (ptr, len) = addr.as_ffi_pair(); ffi::sendto(fd, buf.as_ptr() as *const c_void, buf.len() as size_t, flags, ptr, len) @@ -248,7 +248,7 @@ pub fn sendto(fd: Fd, buf: &[u8], addr: &SockAddr, flags: SockMessageFlags) -> R } #[repr(C)] -#[derive(Copy, Debug)] +#[derive(Clone, Copy, Debug)] pub struct linger { pub l_onoff: c_int, pub l_linger: c_int @@ -284,30 +284,30 @@ pub trait SockOpt : Copy + fmt::Debug { type Set; #[doc(hidden)] - fn get(&self, fd: Fd, level: c_int) -> Result; + fn get(&self, fd: RawFd, level: c_int) -> Result; #[doc(hidden)] - fn set(&self, fd: Fd, level: c_int, val: Self::Set) -> Result<()>; + fn set(&self, fd: RawFd, level: c_int, val: Self::Set) -> Result<()>; } /// Get the current value for the requested socket option /// /// [Further reading](http://man7.org/linux/man-pages/man2/setsockopt.2.html) -pub fn getsockopt(fd: Fd, level: SockLevel, opt: O) -> Result { +pub fn getsockopt(fd: RawFd, level: SockLevel, opt: O) -> Result { opt.get(fd, level as c_int) } /// Sets the value for the requested socket option /// /// [Further reading](http://man7.org/linux/man-pages/man2/setsockopt.2.html) -pub fn setsockopt(fd: Fd, level: SockLevel, opt: O, val: O::Set) -> Result<()> { +pub fn setsockopt(fd: RawFd, level: SockLevel, opt: O, val: O::Set) -> Result<()> { opt.set(fd, level as c_int, val) } /// Get the address of the peer connected to the socket `fd`. /// /// [Further reading](http://man7.org/linux/man-pages/man2/getpeername.2.html) -pub fn getpeername(fd: Fd) -> Result { +pub fn getpeername(fd: RawFd) -> Result { unsafe { let addr: sockaddr_storage = mem::uninitialized(); let mut len = mem::size_of::() as socklen_t; @@ -325,7 +325,7 @@ pub fn getpeername(fd: Fd) -> Result { /// Get the current address to which the socket `fd` is bound. /// /// [Further reading](http://man7.org/linux/man-pages/man2/getsockname.2.html) -pub fn getsockname(fd: Fd) -> Result { +pub fn getsockname(fd: RawFd) -> Result { unsafe { let addr: sockaddr_storage = mem::uninitialized(); let mut len = mem::size_of::() as socklen_t; diff --git a/src/sys/socket/multicast.rs b/src/sys/socket/multicast.rs index f40de76240..1efac40c11 100644 --- a/src/sys/socket/multicast.rs +++ b/src/sys/socket/multicast.rs @@ -3,7 +3,7 @@ use libc::in_addr; use std::fmt; #[repr(C)] -#[derive(Copy)] +#[derive(Clone, Copy)] pub struct ip_mreq { pub imr_multiaddr: in_addr, pub imr_interface: in_addr, diff --git a/src/sys/socket/sockopt.rs b/src/sys/socket/sockopt.rs index 9a06d19806..dc93f08513 100644 --- a/src/sys/socket/sockopt.rs +++ b/src/sys/socket/sockopt.rs @@ -4,7 +4,7 @@ use errno::Errno; use sys::time::TimeVal; use libc::{c_int, uint8_t, c_void, socklen_t}; use std::mem; -use std::os::unix::io::Fd; +use std::os::unix::io::RawFd; // Helper to generate the sockopt accessors // TODO: Figure out how to ommit gets when not supported by opt @@ -22,14 +22,14 @@ macro_rules! sockopt_impl { }; ($name:ident, $flag:path, $get_ty:ty, $getter:ty, $set_ty:ty, $setter:ty) => { - #[derive(Copy, Debug)] + #[derive(Clone, Copy, Debug)] pub struct $name; impl<'a> SockOpt for $name { type Get = $get_ty; type Set = $set_ty; - fn get(&self, fd: Fd, level: c_int) -> Result<$get_ty> { + fn get(&self, fd: RawFd, level: c_int) -> Result<$get_ty> { unsafe { let mut getter: $getter = Get::blank(); @@ -46,7 +46,7 @@ macro_rules! sockopt_impl { } } - fn set(&self, fd: Fd, level: c_int, val: $set_ty) -> Result<()> { + fn set(&self, fd: RawFd, level: c_int, val: $set_ty) -> Result<()> { unsafe { let setter: $setter = Set::new(val); diff --git a/src/sys/termios.rs b/src/sys/termios.rs index c5758fe090..57612f0bf6 100644 --- a/src/sys/termios.rs +++ b/src/sys/termios.rs @@ -98,7 +98,7 @@ mod ffi { pub type speed_t = c_ulong; #[repr(C)] - #[derive(Copy)] + #[derive(Clone, Copy)] pub struct Termios { pub c_iflag: InputFlags, pub c_oflag: OutputFlags, @@ -224,7 +224,7 @@ mod ffi { // XXX: We're using `repr(C)` because `c_int` doesn't work here. // See https://github.com/rust-lang/rust/issues/10374. - #[derive(Copy)] + #[derive(Clone, Copy)] #[repr(C)] pub enum SetArg { TCSANOW = 0, @@ -235,7 +235,7 @@ mod ffi { // XXX: We're using `repr(C)` because `c_int` doesn't work here. // See https://github.com/rust-lang/rust/issues/10374. - #[derive(Copy)] + #[derive(Clone, Copy)] #[repr(C)] pub enum FlushArg { TCIFLUSH = 1, @@ -245,7 +245,7 @@ mod ffi { // XXX: We're using `repr(C)` because `c_int` doesn't work here. // See https://github.com/rust-lang/rust/issues/10374. - #[derive(Copy)] + #[derive(Clone, Copy)] #[repr(C)] pub enum FlowArg { TCOOFF = 1, @@ -264,7 +264,7 @@ mod ffi { pub type speed_t = c_uint; #[repr(C)] - #[derive(Copy)] + #[derive(Clone, Copy)] pub struct Termios { pub c_iflag: InputFlags, pub c_oflag: OutputFlags, @@ -378,7 +378,7 @@ mod ffi { // XXX: We're using `repr(C)` because `c_int` doesn't work here. // See https://github.com/rust-lang/rust/issues/10374. - #[derive(Copy)] + #[derive(Clone, Copy)] #[repr(C)] pub enum SetArg { TCSANOW = 0, @@ -388,7 +388,7 @@ mod ffi { // XXX: We're using `repr(C)` because `c_int` doesn't work here. // See https://github.com/rust-lang/rust/issues/10374. - #[derive(Copy)] + #[derive(Clone, Copy)] #[repr(C)] pub enum FlushArg { TCIFLUSH = 0, @@ -398,7 +398,7 @@ mod ffi { // XXX: We're using `repr(C)` because `c_int` doesn't work here. // See https://github.com/rust-lang/rust/issues/10374. - #[derive(Copy)] + #[derive(Clone, Copy)] #[repr(C)] pub enum FlowArg { TCOOFF = 0, diff --git a/src/sys/utsname.rs b/src/sys/utsname.rs index 69683bf6e9..7eeb323b2a 100644 --- a/src/sys/utsname.rs +++ b/src/sys/utsname.rs @@ -28,6 +28,9 @@ pub struct UtsName { domainname: [c_char; UTSNAME_LEN] } +// workaround for `derive(Clone)` not working for fixed-length arrays +impl Clone for UtsName { fn clone(&self) -> UtsName { *self } } + impl UtsName { pub fn sysname<'a>(&'a self) -> &'a str { to_str(&(&self.sysname as *const c_char ) as *const *const c_char) diff --git a/src/sys/wait.rs b/src/sys/wait.rs index 6772dd900b..a6bccd8a87 100644 --- a/src/sys/wait.rs +++ b/src/sys/wait.rs @@ -16,7 +16,7 @@ bitflags!( } ); -#[derive(Copy)] +#[derive(Clone, Copy)] pub enum WaitStatus { Exited(pid_t), StillAlive diff --git a/src/unistd.rs b/src/unistd.rs index 9df6cd766e..64203f0226 100644 --- a/src/unistd.rs +++ b/src/unistd.rs @@ -44,7 +44,7 @@ mod ffi { } } -#[derive(Copy)] +#[derive(Clone, Copy)] pub enum Fork { Parent(pid_t), Child diff --git a/test/test.rs b/test/test.rs index 7e30fb1931..be1e0ad883 100644 --- a/test/test.rs +++ b/test/test.rs @@ -1,5 +1,3 @@ -#![feature(convert, io_ext)] - extern crate nix; extern crate libc; extern crate rand;