From 18a1e2769fb20fb0ea5ed248a76454f723463736 Mon Sep 17 00:00:00 2001 From: Andrei Bocan Date: Sat, 4 Apr 2015 22:45:48 +0300 Subject: [PATCH] Compatibility with rust latest --- src/fcntl.rs | 14 +++++++------- src/lib.rs | 2 +- src/sched.rs | 2 +- src/sys/epoll.rs | 14 +++++++------- src/sys/eventfd.rs | 4 ++-- src/sys/ioctl.rs | 6 +++--- src/sys/mman.rs | 6 +++--- src/sys/signal.rs | 10 +++++----- src/sys/socket/addr.rs | 2 +- src/sys/socket/mod.rs | 36 ++++++++++++++++++------------------ src/sys/socket/multicast.rs | 2 +- src/sys/socket/sockopt.rs | 8 ++++---- src/sys/stat.rs | 4 ++-- src/sys/termios.rs | 22 +++++++++++----------- src/sys/uio.rs | 12 ++++++------ src/sys/utsname.rs | 12 ++++++++++++ src/sys/wait.rs | 2 +- src/unistd.rs | 32 ++++++++++++++++---------------- test/test.rs | 2 -- 19 files changed, 101 insertions(+), 91 deletions(-) diff --git a/src/fcntl.rs b/src/fcntl.rs index ca0a226622..fecf5bc363 100644 --- a/src/fcntl.rs +++ b/src/fcntl.rs @@ -6,8 +6,8 @@ use sys::stat::Mode; pub use self::consts::*; pub use self::ffi::flock; -// Re-export Fd defined in std -pub type Fd = ::std::os::unix::io::Fd; +// Re-export RawFd defined in std +pub type RawFd = ::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, @@ -71,7 +71,7 @@ mod ffi { } } -pub fn open(path: &P, oflag: OFlag, mode: Mode) -> Result { +pub fn open(path: &P, oflag: OFlag, mode: Mode) -> Result { let fd = try!(path.with_nix_path(|osstr| { unsafe { ffi::open(osstr.as_ext_str(), oflag.bits(), mode.bits() as mode_t) } })); @@ -84,8 +84,8 @@ pub fn open(path: &P, oflag: OFlag, mode: Mode) -> Result { - F_DUPFD(Fd), - F_DUPFD_CLOEXEC(Fd), + F_DUPFD(RawFd), + F_DUPFD_CLOEXEC(RawFd), F_GETFD, F_SETFD(FdFlag), // FD_FLAGS F_GETFL, @@ -104,7 +104,7 @@ pub enum FcntlArg<'a> { } // TODO: Figure out how to handle value fcntl returns -pub fn fcntl(fd: Fd, arg: FcntlArg) -> Result<()> { +pub fn fcntl(fd: RawFd, arg: FcntlArg) -> Result<()> { use self::FcntlArg::*; let res = unsafe { 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..bbe11e9a26 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..44f622ed63 100644 --- a/src/sys/epoll.rs +++ b/src/sys/epoll.rs @@ -2,7 +2,7 @@ use std::fmt; use libc::c_int; use errno::Errno; use {Error, Result, from_ffi}; -use fcntl::Fd; +use fcntl::RawFd; mod ffi { use libc::{c_int}; @@ -70,7 +70,7 @@ impl fmt::Debug for EpollEventKind { } } -#[derive(Copy)] +#[derive(Clone, Copy)] #[repr(C)] pub enum EpollOp { EpollCtlAdd = 1, @@ -79,7 +79,7 @@ pub enum EpollOp { } #[cfg(all(target_os = "android", not(target_arch = "x86_64")))] -#[derive(Copy)] +#[derive(Clone, Copy)] #[repr(C)] pub struct EpollEvent { pub events: EpollEventKind, @@ -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, @@ -102,7 +102,7 @@ pub struct EpollEvent { } #[inline] -pub fn epoll_create() -> Result { +pub fn epoll_create() -> Result { let res = unsafe { ffi::epoll_create(1024) }; if res < 0 { @@ -113,13 +113,13 @@ pub fn epoll_create() -> Result { } #[inline] -pub fn epoll_ctl(epfd: Fd, op: EpollOp, fd: Fd, event: &EpollEvent) -> Result<()> { +pub fn epoll_ctl(epfd: RawFd, op: EpollOp, fd: RawFd, event: &EpollEvent) -> Result<()> { let res = unsafe { ffi::epoll_ctl(epfd, op as c_int, fd, event as *const EpollEvent) }; from_ffi(res) } #[inline] -pub fn epoll_wait(epfd: Fd, events: &mut [EpollEvent], timeout_ms: usize) -> Result { +pub fn epoll_wait(epfd: RawFd, events: &mut [EpollEvent], timeout_ms: usize) -> Result { let res = unsafe { ffi::epoll_wait(epfd, events.as_mut_ptr(), events.len() as c_int, timeout_ms as c_int) }; diff --git a/src/sys/eventfd.rs b/src/sys/eventfd.rs index f072405f9f..4aba580a27 100644 --- a/src/sys/eventfd.rs +++ b/src/sys/eventfd.rs @@ -1,7 +1,7 @@ use std::mem; use libc::{c_int, c_uint}; use errno::Errno; -use fcntl::Fd; +use fcntl::RawFd; use {Error, Result}; bitflags!( @@ -12,7 +12,7 @@ bitflags!( } ); -pub fn eventfd(initval: usize, flags: EventFdFlag) -> Result { +pub fn eventfd(initval: usize, flags: EventFdFlag) -> Result { type F = unsafe extern "C" fn(initval: c_uint, flags: c_int) -> c_int; extern { diff --git a/src/sys/ioctl.rs b/src/sys/ioctl.rs index 5003a4f682..46495f4af7 100644 --- a/src/sys/ioctl.rs +++ b/src/sys/ioctl.rs @@ -1,5 +1,5 @@ use libc; -use fcntl::Fd; +use fcntl::RawFd; use {Result, from_ffi}; pub use self::ffi::Winsize; @@ -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, @@ -34,7 +34,7 @@ pub enum IoctlArg<'a> { TIOCGWINSZ(&'a mut Winsize) } -pub fn ioctl(fd: Fd, arg: IoctlArg) -> Result<()> { +pub fn ioctl(fd: RawFd, arg: IoctlArg) -> Result<()> { match arg { TIOCGWINSZ(&mut ref winsize) => { from_ffi(unsafe { diff --git a/src/sys/mman.rs b/src/sys/mman.rs index a905744d58..99cff72e1a 100644 --- a/src/sys/mman.rs +++ b/src/sys/mman.rs @@ -1,6 +1,6 @@ use {Error, Result, NixPath, AsExtStr}; use errno::Errno; -use fcntl::{Fd, OFlag}; +use fcntl::{RawFd, OFlag}; use libc::{c_void, size_t, off_t, mode_t}; use sys::stat::Mode; @@ -144,7 +144,7 @@ pub fn munlock(addr: *const c_void, length: size_t) -> Result<()> { /// Calls to mmap are inherently unsafe, so they must be made in an unsafe block. Typically /// a higher-level abstraction will hide the unsafe interactions with the mmap'd region. -pub fn mmap(addr: *mut c_void, length: size_t, prot: MmapProt, flags: MmapFlag, fd: Fd, offset: off_t) -> Result<*mut c_void> { +pub fn mmap(addr: *mut c_void, length: size_t, prot: MmapProt, flags: MmapFlag, fd: RawFd, offset: off_t) -> Result<*mut c_void> { let ret = unsafe { ffi::mmap(addr, length, prot, flags, fd, offset) }; if ret as isize == MAP_FAILED { @@ -175,7 +175,7 @@ pub fn msync(addr: *const c_void, length: size_t, flags: MmapSync) -> Result<()> } } -pub fn shm_open(name: &P, flag: OFlag, mode: Mode) -> Result { +pub fn shm_open(name: &P, flag: OFlag, mode: Mode) -> Result { let ret = try!(name.with_nix_path(|osstr| { unsafe { ffi::shm_open(osstr.as_ext_str(), flag.bits(), mode.bits() as mode_t) 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/stat.rs b/src/sys/stat.rs index d98d20ecfe..2fa43a5737 100644 --- a/src/sys/stat.rs +++ b/src/sys/stat.rs @@ -3,7 +3,7 @@ pub use libc::stat as FileStat; use {Error, Result, NixPath, AsExtStr,from_ffi}; use errno::Errno; -use fcntl::Fd; +use fcntl::RawFd; use libc::mode_t; use std::fmt; use std::mem; @@ -94,7 +94,7 @@ pub fn stat(path: &P) -> Result { Ok(dst) } -pub fn fstat(fd: Fd) -> Result { +pub fn fstat(fd: RawFd) -> Result { let mut dst = unsafe { mem::uninitialized() }; let res = unsafe { ffi::fstat(fd, &mut dst as *mut FileStat) }; diff --git a/src/sys/termios.rs b/src/sys/termios.rs index c5758fe090..c4f1597a96 100644 --- a/src/sys/termios.rs +++ b/src/sys/termios.rs @@ -1,5 +1,5 @@ use errno::Errno; -use fcntl::Fd; +use fcntl::RawFd; use libc::c_int; use std::mem; use {Error, Result, from_ffi}; @@ -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, @@ -433,7 +433,7 @@ pub fn cfsetospeed(termios: &mut Termios, speed: speed_t) -> Result<()> { }) } -pub fn tcgetattr(fd: Fd) -> Result { +pub fn tcgetattr(fd: RawFd) -> Result { let mut termios = unsafe { mem::uninitialized() }; let res = unsafe { @@ -447,7 +447,7 @@ pub fn tcgetattr(fd: Fd) -> Result { Ok(termios) } -pub fn tcsetattr(fd: Fd, +pub fn tcsetattr(fd: RawFd, actions: SetArg, termios: &Termios) -> Result<()> { from_ffi(unsafe { @@ -455,25 +455,25 @@ pub fn tcsetattr(fd: Fd, }) } -pub fn tcdrain(fd: Fd) -> Result<()> { +pub fn tcdrain(fd: RawFd) -> Result<()> { from_ffi(unsafe { ffi::tcdrain(fd) }) } -pub fn tcflow(fd: Fd, action: FlowArg) -> Result<()> { +pub fn tcflow(fd: RawFd, action: FlowArg) -> Result<()> { from_ffi(unsafe { ffi::tcflow(fd, action as c_int) }) } -pub fn tcflush(fd: Fd, action: FlushArg) -> Result<()> { +pub fn tcflush(fd: RawFd, action: FlushArg) -> Result<()> { from_ffi(unsafe { ffi::tcflush(fd, action as c_int) }) } -pub fn tcsendbreak(fd: Fd, action: c_int) -> Result<()> { +pub fn tcsendbreak(fd: RawFd, action: c_int) -> Result<()> { from_ffi(unsafe { ffi::tcsendbreak(fd, action) }) diff --git a/src/sys/uio.rs b/src/sys/uio.rs index 62b1819ba4..2ef1fb43ba 100644 --- a/src/sys/uio.rs +++ b/src/sys/uio.rs @@ -3,27 +3,27 @@ use {Result, Error}; use errno::Errno; -use fcntl::Fd; +use fcntl::RawFd; use libc::{c_int, c_void, size_t}; use std::marker::PhantomData; mod ffi { use super::IoVec; use libc::{ssize_t, c_int}; - use fcntl::Fd; + use fcntl::RawFd; extern { // vectorized version of write // doc: http://man7.org/linux/man-pages/man2/writev.2.html - pub fn writev(fd: Fd, iov: *const IoVec<&[u8]>, iovcnt: c_int) -> ssize_t; + pub fn writev(fd: RawFd, iov: *const IoVec<&[u8]>, iovcnt: c_int) -> ssize_t; // vectorized version of read // doc: http://man7.org/linux/man-pages/man2/readv.2.html - pub fn readv(fd: Fd, iov: *const IoVec<&mut [u8]>, iovcnt: c_int) -> ssize_t; + pub fn readv(fd: RawFd, iov: *const IoVec<&mut [u8]>, iovcnt: c_int) -> ssize_t; } } -pub fn writev(fd: Fd, iov: &[IoVec<&[u8]>]) -> Result { +pub fn writev(fd: RawFd, iov: &[IoVec<&[u8]>]) -> Result { let res = unsafe { ffi::writev(fd, iov.as_ptr(), iov.len() as c_int) }; if res < 0 { @@ -33,7 +33,7 @@ pub fn writev(fd: Fd, iov: &[IoVec<&[u8]>]) -> Result { return Ok(res as usize) } -pub fn readv(fd: Fd, iov: &mut [IoVec<&mut [u8]>]) -> Result { +pub fn readv(fd: RawFd, iov: &mut [IoVec<&mut [u8]>]) -> Result { let res = unsafe { ffi::readv(fd, iov.as_ptr(), iov.len() as c_int) }; if res < 0 { return Err(Error::Sys(Errno::last())); diff --git a/src/sys/utsname.rs b/src/sys/utsname.rs index 69683bf6e9..7e5513da43 100644 --- a/src/sys/utsname.rs +++ b/src/sys/utsname.rs @@ -28,6 +28,18 @@ pub struct UtsName { domainname: [c_char; UTSNAME_LEN] } +impl Clone for UtsName { + fn clone(&self) -> UtsName { + unsafe { + use std::ptr::copy_nonoverlapping; + use std::mem; + let mut ret:UtsName = mem::uninitialized(); + copy_nonoverlapping(self, &mut ret, mem::size_of::()); + return ret + } + } +} + 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..99fa1aaa09 100644 --- a/src/unistd.rs +++ b/src/unistd.rs @@ -2,7 +2,7 @@ //! use {Error, Result, NixPath, AsExtStr, from_ffi}; use errno::Errno; -use fcntl::{fcntl, Fd, OFlag, O_NONBLOCK, O_CLOEXEC, FD_CLOEXEC}; +use fcntl::{fcntl, RawFd, OFlag, O_NONBLOCK, O_CLOEXEC, FD_CLOEXEC}; use fcntl::FcntlArg::{F_SETFD, F_SETFL}; use libc::{c_char, c_void, c_int, size_t, pid_t, off_t}; use std::{mem, ptr}; @@ -44,7 +44,7 @@ mod ffi { } } -#[derive(Copy)] +#[derive(Clone, Copy)] pub enum Fork { Parent(pid_t), Child @@ -81,7 +81,7 @@ pub fn fork() -> Result { } #[inline] -pub fn dup(oldfd: Fd) -> Result { +pub fn dup(oldfd: RawFd) -> Result { let res = unsafe { ffi::dup(oldfd) }; if res < 0 { @@ -92,7 +92,7 @@ pub fn dup(oldfd: Fd) -> Result { } #[inline] -pub fn dup2(oldfd: Fd, newfd: Fd) -> Result { +pub fn dup2(oldfd: RawFd, newfd: RawFd) -> Result { let res = unsafe { ffi::dup2(oldfd, newfd) }; if res < 0 { @@ -103,7 +103,7 @@ pub fn dup2(oldfd: Fd, newfd: Fd) -> Result { } #[cfg(not(any(target_os = "macos", target_os = "ios")))] -pub fn dup3(oldfd: Fd, newfd: Fd, flags: OFlag) -> Result { +pub fn dup3(oldfd: RawFd, newfd: RawFd, flags: OFlag) -> Result { type F = unsafe extern "C" fn(c_int, c_int, c_int) -> c_int; extern { @@ -128,12 +128,12 @@ pub fn dup3(oldfd: Fd, newfd: Fd, flags: OFlag) -> Result { } #[cfg(any(target_os = "macos", target_os = "ios"))] -pub fn dup3(oldfd: Fd, newfd: Fd, flags: OFlag) -> Result { +pub fn dup3(oldfd: RawFd, newfd: RawFd, flags: OFlag) -> Result { dup3_polyfill(oldfd, newfd, flags) } #[inline] -fn dup3_polyfill(oldfd: Fd, newfd: Fd, flags: OFlag) -> Result { +fn dup3_polyfill(oldfd: RawFd, newfd: RawFd, flags: OFlag) -> Result { use errno::EINVAL; if oldfd == newfd { @@ -205,12 +205,12 @@ pub fn gethostname(name: &mut [u8]) -> Result<()> { from_ffi(res) } -pub fn close(fd: Fd) -> Result<()> { +pub fn close(fd: RawFd) -> Result<()> { let res = unsafe { ffi::close(fd) }; from_ffi(res) } -pub fn read(fd: Fd, buf: &mut [u8]) -> Result { +pub fn read(fd: RawFd, buf: &mut [u8]) -> Result { let res = unsafe { ffi::read(fd, buf.as_mut_ptr() as *mut c_void, buf.len() as size_t) }; if res < 0 { @@ -220,7 +220,7 @@ pub fn read(fd: Fd, buf: &mut [u8]) -> Result { return Ok(res as usize) } -pub fn write(fd: Fd, buf: &[u8]) -> Result { +pub fn write(fd: RawFd, buf: &[u8]) -> Result { let res = unsafe { ffi::write(fd, buf.as_ptr() as *const c_void, buf.len() as size_t) }; if res < 0 { @@ -230,7 +230,7 @@ pub fn write(fd: Fd, buf: &[u8]) -> Result { return Ok(res as usize) } -pub fn pipe() -> Result<(Fd, Fd)> { +pub fn pipe() -> Result<(RawFd, RawFd)> { unsafe { let mut res; let mut fds: [c_int; 2] = mem::uninitialized(); @@ -246,7 +246,7 @@ pub fn pipe() -> Result<(Fd, Fd)> { } #[cfg(any(target_os = "linux", target_os = "android"))] -pub fn pipe2(flags: OFlag) -> Result<(Fd, Fd)> { +pub fn pipe2(flags: OFlag) -> Result<(RawFd, RawFd)> { type F = unsafe extern "C" fn(fds: *mut c_int, flags: c_int) -> c_int; extern { @@ -280,7 +280,7 @@ pub fn pipe2(flags: OFlag) -> Result<(Fd, Fd)> { } #[cfg(any(target_os = "macos", target_os = "ios"))] -pub fn pipe2(flags: OFlag) -> Result<(Fd, Fd)> { +pub fn pipe2(flags: OFlag) -> Result<(RawFd, RawFd)> { unsafe { let mut res; let mut fds: [c_int; 2] = mem::uninitialized(); @@ -297,7 +297,7 @@ pub fn pipe2(flags: OFlag) -> Result<(Fd, Fd)> { } } -fn pipe2_setflags(fd1: Fd, fd2: Fd, flags: OFlag) -> Result<()> { +fn pipe2_setflags(fd1: RawFd, fd2: RawFd, flags: OFlag) -> Result<()> { let mut res = Ok(()); if flags.contains(O_CLOEXEC) { @@ -322,7 +322,7 @@ fn pipe2_setflags(fd1: Fd, fd2: Fd, flags: OFlag) -> Result<()> { } } -pub fn ftruncate(fd: Fd, len: off_t) -> Result<()> { +pub fn ftruncate(fd: RawFd, len: off_t) -> Result<()> { if unsafe { ffi::ftruncate(fd, len) } < 0 { Err(Error::Sys(Errno::last())) } else { @@ -330,7 +330,7 @@ pub fn ftruncate(fd: Fd, len: off_t) -> Result<()> { } } -pub fn isatty(fd: Fd) -> Result { +pub fn isatty(fd: RawFd) -> Result { use libc; if unsafe { libc::isatty(fd) } == 1 { 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;