summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/fcntl.rs12
-rw-r--r--src/lib.rs8
-rw-r--r--src/sys/epoll.rs14
-rw-r--r--src/sys/event.rs10
-rw-r--r--src/sys/ioctl.rs16
-rw-r--r--src/sys/mman.rs7
-rw-r--r--src/sys/socket/mod.rs41
-rw-r--r--src/sys/socket/sockopt.rs6
-rw-r--r--src/sys/stat.rs7
-rw-r--r--src/sys/termios.rs16
-rw-r--r--src/sys/uio.rs12
-rw-r--r--src/unistd.rs27
12 files changed, 84 insertions, 92 deletions
diff --git a/src/fcntl.rs b/src/fcntl.rs
index 76ea9f65..28fce037 100644
--- a/src/fcntl.rs
+++ b/src/fcntl.rs
@@ -2,13 +2,11 @@ use {Error, Result, NixPath};
use errno::Errno;
use libc::mode_t;
use sys::stat::Mode;
+use std::os::unix::io::RawFd;
pub use self::consts::*;
pub use self::ffi::flock;
-// Re-export Fd defined in std
-pub type Fd = ::std::os::unix::io::RawFd;
-
#[allow(dead_code)]
mod ffi {
pub use libc::{open, fcntl};
@@ -71,7 +69,7 @@ mod ffi {
}
}
-pub fn open<P: ?Sized + NixPath>(path: &P, oflag: OFlag, mode: Mode) -> Result<Fd> {
+pub fn open<P: ?Sized + NixPath>(path: &P, oflag: OFlag, mode: Mode) -> Result<RawFd> {
let fd = try!(path.with_nix_path(|cstr| {
unsafe { ffi::open(cstr.as_ptr(), oflag.bits(), mode.bits() as mode_t) }
}));
@@ -84,8 +82,8 @@ pub fn open<P: ?Sized + NixPath>(path: &P, oflag: OFlag, mode: Mode) -> Result<F
}
pub enum FcntlArg<'a> {
- 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 +102,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 1e510e57..b63920bd 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -18,13 +18,8 @@ extern crate nix_test as nixtest;
// Re-export some libc constants
pub use libc::{c_int, c_void};
-#[cfg(unix)]
pub mod errno;
-
-#[cfg(unix)]
pub mod features;
-
-#[cfg(unix)]
pub mod fcntl;
#[cfg(any(target_os = "linux", target_os = "android"))]
@@ -36,10 +31,7 @@ pub mod mqueue;
#[cfg(any(target_os = "linux", target_os = "android"))]
pub mod sched;
-#[cfg(unix)]
pub mod sys;
-
-#[cfg(unix)]
pub mod unistd;
/*
diff --git a/src/sys/epoll.rs b/src/sys/epoll.rs
index a14bf8a1..9d4b7ceb 100644
--- a/src/sys/epoll.rs
+++ b/src/sys/epoll.rs
@@ -1,8 +1,8 @@
-use std::fmt;
-use libc::c_int;
-use errno::Errno;
use {Error, Result, from_ffi};
-use fcntl::Fd;
+use errno::Errno;
+use libc::c_int;
+use std::fmt;
+use std::os::unix::io::RawFd;
mod ffi {
use libc::{c_int};
@@ -102,7 +102,7 @@ pub struct EpollEvent {
}
#[inline]
-pub fn epoll_create() -> Result<Fd> {
+pub fn epoll_create() -> Result<RawFd> {
let res = unsafe { ffi::epoll_create(1024) };
if res < 0 {
@@ -113,13 +113,13 @@ pub fn epoll_create() -> Result<Fd> {
}
#[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: isize) -> Result<usize> {
+pub fn epoll_wait(epfd: RawFd, events: &mut [EpollEvent], timeout_ms: isize) -> Result<usize> {
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/event.rs b/src/sys/event.rs
index c2c65dad..62be0af2 100644
--- a/src/sys/event.rs
+++ b/src/sys/event.rs
@@ -1,11 +1,11 @@
/* TOOD: Implement for other kqueue based systems
*/
-use libc::{timespec, time_t, c_int, c_long, uintptr_t};
+use {Error, Result};
use errno::Errno;
-use fcntl::Fd;
+use libc::{timespec, time_t, c_int, c_long, uintptr_t};
use std::fmt;
-use {Error, Result};
+use std::os::unix::io::RawFd;
pub use self::ffi::kevent as KEvent;
@@ -159,7 +159,7 @@ bitflags!(
pub const EV_POLL: EventFlag = EV_FLAG0;
pub const EV_OOBAND: EventFlag = EV_FLAG1;
-pub fn kqueue() -> Result<Fd> {
+pub fn kqueue() -> Result<RawFd> {
let res = unsafe { ffi::kqueue() };
if res < 0 {
@@ -169,7 +169,7 @@ pub fn kqueue() -> Result<Fd> {
Ok(res)
}
-pub fn kevent(kq: Fd,
+pub fn kevent(kq: RawFd,
changelist: &[KEvent],
eventlist: &mut [KEvent],
timeout_ms: usize) -> Result<usize> {
diff --git a/src/sys/ioctl.rs b/src/sys/ioctl.rs
index 6904ce56..d295d08d 100644
--- a/src/sys/ioctl.rs
+++ b/src/sys/ioctl.rs
@@ -70,11 +70,11 @@
//! necessary for cases (notably slices) where a reference cannot
//! be generically cast to a pointer.
+use {Error, Result, errno};
use libc::{c_int, c_ulong};
use libc::funcs::bsd44::ioctl as libc_ioctl;
use std::mem;
-use fcntl::Fd;
-use {Error, Result, errno};
+use std::os::unix::io::RawFd;
pub type ioctl_op_t = c_ulong;
@@ -177,7 +177,7 @@ fn convert_ioctl_res(res: c_int) -> Result<c_int> {
///
/// This function will allocate allocate space for and returned an owned
/// reference to the result.
-pub unsafe fn read<T>(fd: Fd, op: ioctl_op_t) -> Result<T> {
+pub unsafe fn read<T>(fd: RawFd, op: ioctl_op_t) -> Result<T> {
// allocate memory for the result (should get a value from kernel)
let mut dst: T = mem::zeroed();
let dst_ptr: *mut T = &mut dst;
@@ -190,7 +190,7 @@ pub unsafe fn read<T>(fd: Fd, op: ioctl_op_t) -> Result<T> {
///
/// The refernced data may also contain information that will be consumed
/// by the kernel.
-pub unsafe fn read_into<T>(fd: Fd, op: ioctl_op_t, data: &mut T) -> Result<c_int> {
+pub unsafe fn read_into<T>(fd: RawFd, op: ioctl_op_t, data: &mut T) -> Result<c_int> {
read_into_ptr(fd, op, data as *mut T)
}
@@ -199,25 +199,25 @@ pub unsafe fn read_into<T>(fd: Fd, op: ioctl_op_t, data: &mut T) -> Result<c_int
///
/// The refernced data may also contain information that will be consumed
/// by the kernel.
-pub unsafe fn read_into_ptr<T>(fd: Fd, op: ioctl_op_t, data_ptr: *mut T) -> Result<c_int> {
+pub unsafe fn read_into_ptr<T>(fd: RawFd, op: ioctl_op_t, data_ptr: *mut T) -> Result<c_int> {
convert_ioctl_res(libc_ioctl(fd, op as os_ioctl_op_t, data_ptr))
}
/// Ioctl call that sends a value to the kernel but
/// does not return anything (pure side effect).
-pub unsafe fn write<T>(fd: Fd, op: ioctl_op_t, data: &T) -> Result<c_int> {
+pub unsafe fn write<T>(fd: RawFd, op: ioctl_op_t, data: &T) -> Result<c_int> {
write_ptr(fd, op, data as *const T)
}
/// Ioctl call that sends a value to the kernel but
/// does not return anything (pure side effect).
-pub unsafe fn write_ptr<T>(fd: Fd, op: ioctl_op_t, data: *const T) -> Result<c_int> {
+pub unsafe fn write_ptr<T>(fd: RawFd, op: ioctl_op_t, data: *const T) -> Result<c_int> {
convert_ioctl_res(libc_ioctl(fd, op as os_ioctl_op_t, data as *const T))
}
/// Ioctl call for which no data pointer is provided to the kernel.
/// That is, the kernel has sufficient information about what to
/// do based on the op alone.
-pub fn execute(fd: Fd, op: ioctl_op_t) -> Result<c_int> {
+pub fn execute(fd: RawFd, op: ioctl_op_t) -> Result<c_int> {
convert_ioctl_res(unsafe { libc_ioctl(fd, op as os_ioctl_op_t) })
}
diff --git a/src/sys/mman.rs b/src/sys/mman.rs
index 04664fd0..0815b618 100644
--- a/src/sys/mman.rs
+++ b/src/sys/mman.rs
@@ -1,8 +1,9 @@
use {Error, Result, NixPath};
use errno::Errno;
-use fcntl::{Fd, OFlag};
+use fcntl::OFlag;
use libc::{c_void, size_t, off_t, mode_t};
use sys::stat::Mode;
+use std::os::unix::io::RawFd;
pub use self::consts::*;
@@ -193,7 +194,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 {
@@ -224,7 +225,7 @@ pub fn msync(addr: *const c_void, length: size_t, flags: MmapSync) -> Result<()>
}
}
-pub fn shm_open<P: ?Sized + NixPath>(name: &P, flag: OFlag, mode: Mode) -> Result<Fd> {
+pub fn shm_open<P: ?Sized + NixPath>(name: &P, flag: OFlag, mode: Mode) -> Result<RawFd> {
let ret = try!(name.with_nix_path(|cstr| {
unsafe {
ffi::shm_open(cstr.as_ptr(), flag.bits(), mode.bits() as mode_t)
diff --git a/src/sys/socket/mod.rs b/src/sys/socket/mod.rs
index e00c8fe5..dd8893d6 100644
--- a/src/sys/socket/mod.rs
+++ b/src/sys/socket/mod.rs
@@ -4,10 +4,11 @@
use {Error, Result, from_ffi};
use errno::Errno;
use features;
-use fcntl::{fcntl, Fd, FD_CLOEXEC, O_NONBLOCK};
+use fcntl::{fcntl, FD_CLOEXEC, O_NONBLOCK};
use fcntl::FcntlArg::{F_SETFD, F_SETFL};
use libc::{c_void, c_int, socklen_t, size_t};
use std::{fmt, mem, ptr};
+use std::os::unix::io::RawFd;
mod addr;
mod consts;
@@ -78,7 +79,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<Fd> {
+pub fn socket(domain: AddressFamily, ty: SockType, flags: SockFlag) -> Result<RawFd> {
let mut ty = ty as c_int;
let feat_atomic = features::socket_atomic_cloexec();
@@ -110,7 +111,7 @@ pub fn socket(domain: AddressFamily, ty: SockType, flags: SockFlag) -> Result<Fd
///
/// [Further reading](http://man7.org/linux/man-pages/man2/socketpair.2.html)
pub fn socketpair(domain: AddressFamily, ty: SockType, protocol: c_int,
- flags: SockFlag) -> Result<(Fd, Fd)> {
+ flags: SockFlag) -> Result<(RawFd, RawFd)> {
let mut ty = ty as c_int;
let feat_atomic = features::socket_atomic_cloexec();
@@ -143,7 +144,7 @@ pub fn socketpair(domain: AddressFamily, ty: SockType, protocol: c_int,
/// Listen for connections on a socket
///
/// [Further reading](http://man7.org/linux/man-pages/man2/listen.2.html)
-pub fn listen(sockfd: Fd, backlog: usize) -> Result<()> {
+pub fn listen(sockfd: RawFd, backlog: usize) -> Result<()> {
let res = unsafe { ffi::listen(sockfd, backlog as c_int) };
from_ffi(res)
}
@@ -151,7 +152,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)
@@ -163,7 +164,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<Fd> {
+pub fn accept(sockfd: RawFd) -> Result<RawFd> {
let res = unsafe { ffi::accept(sockfd, ptr::null_mut(), ptr::null_mut()) };
if res < 0 {
@@ -176,12 +177,12 @@ pub fn accept(sockfd: Fd) -> Result<Fd> {
/// Accept a connection on a socket
///
/// [Further reading](http://man7.org/linux/man-pages/man2/accept.2.html)
-pub fn accept4(sockfd: Fd, flags: SockFlag) -> Result<Fd> {
+pub fn accept4(sockfd: RawFd, flags: SockFlag) -> Result<RawFd> {
accept4_polyfill(sockfd, flags)
}
#[inline]
-fn accept4_polyfill(sockfd: Fd, flags: SockFlag) -> Result<Fd> {
+fn accept4_polyfill(sockfd: RawFd, flags: SockFlag) -> Result<RawFd> {
let res = unsafe { ffi::accept(sockfd, ptr::null_mut(), ptr::null_mut()) };
if res < 0 {
@@ -202,7 +203,7 @@ fn accept4_polyfill(sockfd: Fd, flags: SockFlag) -> Result<Fd> {
/// 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)
@@ -215,7 +216,7 @@ pub fn connect(fd: Fd, addr: &SockAddr) -> Result<()> {
/// bytes read
///
/// [Further reading](http://man7.org/linux/man-pages/man2/recv.2.html)
-pub fn recv(sockfd: Fd, buf: &mut [u8], flags: SockMessageFlags) -> Result<usize> {
+pub fn recv(sockfd: RawFd, buf: &mut [u8], flags: SockMessageFlags) -> Result<usize> {
unsafe {
let ret = ffi::recv(
sockfd,
@@ -235,7 +236,7 @@ pub fn recv(sockfd: Fd, buf: &mut [u8], flags: SockMessageFlags) -> Result<usize
/// 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::<sockaddr_storage>() as socklen_t;
@@ -257,7 +258,7 @@ pub fn recvfrom(sockfd: Fd, buf: &mut [u8]) -> Result<(usize, SockAddr)> {
}
}
-pub fn sendto(fd: Fd, buf: &[u8], addr: &SockAddr, flags: SockMessageFlags) -> Result<usize> {
+pub fn sendto(fd: RawFd, buf: &[u8], addr: &SockAddr, flags: SockMessageFlags) -> Result<usize> {
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)
@@ -273,7 +274,7 @@ pub fn sendto(fd: Fd, buf: &[u8], addr: &SockAddr, flags: SockMessageFlags) -> R
/// Send data to a connection-oriented socket. Returns the number of bytes read
///
/// [Further reading](http://man7.org/linux/man-pages/man2/send.2.html)
-pub fn send(fd: Fd, buf: &[u8], flags: SockMessageFlags) -> Result<usize> {
+pub fn send(fd: RawFd, buf: &[u8], flags: SockMessageFlags) -> Result<usize> {
let ret = unsafe {
ffi::send(fd, buf.as_ptr() as *const c_void, buf.len() as size_t, flags)
};
@@ -317,30 +318,30 @@ pub trait SockOpt : Copy + fmt::Debug {
type Val;
#[doc(hidden)]
- fn get(&self, fd: Fd, level: c_int) -> Result<Self::Val>;
+ fn get(&self, fd: RawFd, level: c_int) -> Result<Self::Val>;
#[doc(hidden)]
- fn set(&self, fd: Fd, level: c_int, val: &Self::Val) -> Result<()>;
+ fn set(&self, fd: RawFd, level: c_int, val: &Self::Val) -> 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<O: SockOpt>(fd: Fd, level: SockLevel, opt: O) -> Result<O::Val> {
+pub fn getsockopt<O: SockOpt>(fd: RawFd, level: SockLevel, opt: O) -> Result<O::Val> {
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<O: SockOpt>(fd: Fd, level: SockLevel, opt: O, val: &O::Val) -> Result<()> {
+pub fn setsockopt<O: SockOpt>(fd: RawFd, level: SockLevel, opt: O, val: &O::Val) -> 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<SockAddr> {
+pub fn getpeername(fd: RawFd) -> Result<SockAddr> {
unsafe {
let addr: sockaddr_storage = mem::uninitialized();
let mut len = mem::size_of::<sockaddr_storage>() as socklen_t;
@@ -358,7 +359,7 @@ pub fn getpeername(fd: Fd) -> Result<SockAddr> {
/// 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<SockAddr> {
+pub fn getsockname(fd: RawFd) -> Result<SockAddr> {
unsafe {
let addr: sockaddr_storage = mem::uninitialized();
let mut len = mem::size_of::<sockaddr_storage>() as socklen_t;
@@ -409,7 +410,7 @@ pub enum Shutdown {
/// Shut down part of a full-duplex connection.
///
/// [Further reading](http://man7.org/linux/man-pages/man2/shutdown.2.html)
-pub fn shutdown(df: Fd, how: Shutdown) -> Result<()> {
+pub fn shutdown(df: RawFd, how: Shutdown) -> Result<()> {
unsafe {
use libc::shutdown;
diff --git a/src/sys/socket/sockopt.rs b/src/sys/socket/sockopt.rs
index f03f243a..83aec5cb 100644
--- a/src/sys/socket/sockopt.rs
+++ b/src/sys/socket/sockopt.rs
@@ -1,10 +1,10 @@
use {Result, Error, from_ffi};
use super::{ffi, consts, SockOpt};
use errno::Errno;
-use fcntl::Fd;
use sys::time::TimeVal;
use libc::{c_int, uint8_t, c_void, socklen_t};
use std::mem;
+use std::os::unix::io::RawFd;
// Helper to generate the sockopt accessors
// TODO: Figure out how to ommit gets when not supported by opt
@@ -28,7 +28,7 @@ macro_rules! sockopt_impl {
impl SockOpt for $name {
type Val = $ty;
- fn get(&self, fd: Fd, level: c_int) -> Result<$ty> {
+ fn get(&self, fd: RawFd, level: c_int) -> Result<$ty> {
unsafe {
let mut getter: $getter = Get::blank();
@@ -45,7 +45,7 @@ macro_rules! sockopt_impl {
}
}
- fn set(&self, fd: Fd, level: c_int, val: &$ty) -> Result<()> {
+ fn set(&self, fd: RawFd, level: c_int, val: &$ty) -> Result<()> {
unsafe {
let setter: $setter = Set::new(val);
diff --git a/src/sys/stat.rs b/src/sys/stat.rs
index 60153a61..aee47a67 100644
--- a/src/sys/stat.rs
+++ b/src/sys/stat.rs
@@ -3,10 +3,9 @@ pub use libc::stat as FileStat;
use {Error, Result, NixPath, from_ffi};
use errno::Errno;
-use fcntl::Fd;
use libc::mode_t;
-use std::fmt;
-use std::mem;
+use std::{fmt, mem};
+use std::os::unix::io::RawFd;
mod ffi {
use libc::{c_char, c_int, mode_t, dev_t};
@@ -109,7 +108,7 @@ pub fn lstat<P: ?Sized + NixPath>(path: &P) -> Result<FileStat> {
Ok(dst)
}
-pub fn fstat(fd: Fd) -> Result<FileStat> {
+pub fn fstat(fd: RawFd) -> Result<FileStat> {
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 0c636e77..7473eab4 100644
--- a/src/sys/termios.rs
+++ b/src/sys/termios.rs
@@ -1,8 +1,8 @@
+use {Error, Result, from_ffi};
use errno::Errno;
-use fcntl::Fd;
use libc::c_int;
use std::mem;
-use {Error, Result, from_ffi};
+use std::os::unix::io::RawFd;
pub use self::ffi::consts::*;
pub use self::ffi::consts::SetArg::*;
@@ -433,7 +433,7 @@ pub fn cfsetospeed(termios: &mut Termios, speed: speed_t) -> Result<()> {
})
}
-pub fn tcgetattr(fd: Fd) -> Result<Termios> {
+pub fn tcgetattr(fd: RawFd) -> Result<Termios> {
let mut termios = unsafe { mem::uninitialized() };
let res = unsafe {
@@ -447,7 +447,7 @@ pub fn tcgetattr(fd: Fd) -> Result<Termios> {
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 62b1819b..9f65cf09 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 libc::{c_int, c_void, size_t};
use std::marker::PhantomData;
+use std::os::unix::io::RawFd;
mod ffi {
use super::IoVec;
use libc::{ssize_t, c_int};
- use fcntl::Fd;
+ use std::os::unix::io::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<usize> {
+pub fn writev(fd: RawFd, iov: &[IoVec<&[u8]>]) -> Result<usize> {
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<usize> {
return Ok(res as usize)
}
-pub fn readv(fd: Fd, iov: &mut [IoVec<&mut [u8]>]) -> Result<usize> {
+pub fn readv(fd: RawFd, iov: &mut [IoVec<&mut [u8]>]) -> Result<usize> {
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/unistd.rs b/src/unistd.rs
index 68447f5b..93214a25 100644
--- a/src/unistd.rs
+++ b/src/unistd.rs
@@ -2,11 +2,12 @@
//!
use {Error, Result, NixPath, from_ffi};
use errno::Errno;
-use fcntl::{fcntl, Fd, OFlag, O_NONBLOCK, O_CLOEXEC, FD_CLOEXEC};
+use fcntl::{fcntl, 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};
use std::ffi::CString;
+use std::os::unix::io::RawFd;
#[cfg(any(target_os = "linux", target_os = "android"))]
pub use self::linux::*;
@@ -97,7 +98,7 @@ pub fn getppid() -> pid_t {
}
#[inline]
-pub fn dup(oldfd: Fd) -> Result<Fd> {
+pub fn dup(oldfd: RawFd) -> Result<RawFd> {
let res = unsafe { ffi::dup(oldfd) };
if res < 0 {
@@ -108,7 +109,7 @@ pub fn dup(oldfd: Fd) -> Result<Fd> {
}
#[inline]
-pub fn dup2(oldfd: Fd, newfd: Fd) -> Result<Fd> {
+pub fn dup2(oldfd: RawFd, newfd: RawFd) -> Result<RawFd> {
let res = unsafe { ffi::dup2(oldfd, newfd) };
if res < 0 {
@@ -118,12 +119,12 @@ pub fn dup2(oldfd: Fd, newfd: Fd) -> Result<Fd> {
Ok(res)
}
-pub fn dup3(oldfd: Fd, newfd: Fd, flags: OFlag) -> Result<Fd> {
+pub fn dup3(oldfd: RawFd, newfd: RawFd, flags: OFlag) -> Result<RawFd> {
dup3_polyfill(oldfd, newfd, flags)
}
#[inline]
-fn dup3_polyfill(oldfd: Fd, newfd: Fd, flags: OFlag) -> Result<Fd> {
+fn dup3_polyfill(oldfd: RawFd, newfd: RawFd, flags: OFlag) -> Result<RawFd> {
use errno::EINVAL;
if oldfd == newfd {
@@ -195,12 +196,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<usize> {
+pub fn read(fd: RawFd, buf: &mut [u8]) -> Result<usize> {
let res = unsafe { ffi::read(fd, buf.as_mut_ptr() as *mut c_void, buf.len() as size_t) };
if res < 0 {
@@ -210,7 +211,7 @@ pub fn read(fd: Fd, buf: &mut [u8]) -> Result<usize> {
return Ok(res as usize)
}
-pub fn write(fd: Fd, buf: &[u8]) -> Result<usize> {
+pub fn write(fd: RawFd, buf: &[u8]) -> Result<usize> {
let res = unsafe { ffi::write(fd, buf.as_ptr() as *const c_void, buf.len() as size_t) };
if res < 0 {
@@ -220,7 +221,7 @@ pub fn write(fd: Fd, buf: &[u8]) -> Result<usize> {
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();
@@ -235,7 +236,7 @@ pub fn pipe() -> Result<(Fd, Fd)> {
}
}
-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();
@@ -252,7 +253,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) {
@@ -277,7 +278,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 {
@@ -285,7 +286,7 @@ pub fn ftruncate(fd: Fd, len: off_t) -> Result<()> {
}
}
-pub fn isatty(fd: Fd) -> Result<bool> {
+pub fn isatty(fd: RawFd) -> Result<bool> {
use libc;
if unsafe { libc::isatty(fd) } == 1 {