summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/fcntl.rs10
-rw-r--r--src/lib.rs88
-rw-r--r--src/mount.rs8
-rw-r--r--src/nix.rs80
-rw-r--r--src/sched.rs14
-rw-r--r--src/sys/epoll.rs12
-rw-r--r--src/sys/event.rs10
-rw-r--r--src/sys/eventfd.rs6
-rw-r--r--src/sys/ioctl.rs4
-rw-r--r--src/sys/mman.rs34
-rw-r--r--src/sys/signal.rs18
-rw-r--r--src/sys/socket/addr.rs8
-rw-r--r--src/sys/socket/mod.rs52
-rw-r--r--src/sys/socket/sockopt.rs8
-rw-r--r--src/sys/stat.rs12
-rw-r--r--src/sys/termios.rs20
-rw-r--r--src/sys/uio.rs10
-rw-r--r--src/sys/wait.rs6
-rw-r--r--src/unistd.rs78
-rw-r--r--test/sys/test_socket.rs2
-rw-r--r--test/sys/test_termios.rs6
-rw-r--r--test/test_stat.rs6
-rw-r--r--test/test_unistd.rs10
23 files changed, 251 insertions, 251 deletions
diff --git a/src/fcntl.rs b/src/fcntl.rs
index 8a88cbc4..ca0a2266 100644
--- a/src/fcntl.rs
+++ b/src/fcntl.rs
@@ -1,4 +1,4 @@
-use {NixError, NixResult, NixPath, AsExtStr};
+use {Error, Result, NixPath, AsExtStr};
use errno::Errno;
use libc::mode_t;
use sys::stat::Mode;
@@ -71,13 +71,13 @@ mod ffi {
}
}
-pub fn open<P: ?Sized + NixPath>(path: &P, oflag: OFlag, mode: Mode) -> NixResult<Fd> {
+pub fn open<P: ?Sized + NixPath>(path: &P, oflag: OFlag, mode: Mode) -> Result<Fd> {
let fd = try!(path.with_nix_path(|osstr| {
unsafe { ffi::open(osstr.as_ext_str(), oflag.bits(), mode.bits() as mode_t) }
}));
if fd < 0 {
- return Err(NixError::Sys(Errno::last()));
+ return Err(Error::Sys(Errno::last()));
}
Ok(fd)
@@ -104,7 +104,7 @@ pub enum FcntlArg<'a> {
}
// TODO: Figure out how to handle value fcntl returns
-pub fn fcntl(fd: Fd, arg: FcntlArg) -> NixResult<()> {
+pub fn fcntl(fd: Fd, arg: FcntlArg) -> Result<()> {
use self::FcntlArg::*;
let res = unsafe {
@@ -116,7 +116,7 @@ pub fn fcntl(fd: Fd, arg: FcntlArg) -> NixResult<()> {
};
if res < 0 {
- return Err(NixError::Sys(Errno::last()));
+ return Err(Error::Sys(Errno::last()));
}
Ok(())
diff --git a/src/lib.rs b/src/lib.rs
index 97676dd9..386bf1f8 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -19,10 +19,6 @@ extern crate "nix-test" as nixtest;
// Re-export some libc constants
pub use libc::{c_int, c_void};
-mod nix;
-pub use nix::{NixResult, NixError, NixPath, from_ffi};
-
-
#[cfg(unix)]
pub mod errno;
@@ -46,6 +42,90 @@ pub mod unistd;
/*
*
+ * ===== Result / Error =====
+ *
+ */
+
+use std::result;
+use std::ffi::AsOsStr;
+use std::path::{Path, PathBuf};
+use std::slice::bytes;
+
+pub type Result<T> = result::Result<T, Error>;
+
+#[derive(Clone, Copy, Debug, PartialEq)]
+pub enum Error {
+ Sys(errno::Errno),
+ InvalidPath,
+}
+
+impl Error {
+ pub fn last() -> Error {
+ Error::Sys(errno::Errno::last())
+ }
+
+ pub fn invalid_argument() -> Error {
+ Error::Sys(errno::EINVAL)
+ }
+
+ pub fn errno(&self) -> errno::Errno {
+ match *self {
+ Error::Sys(errno) => errno,
+ Error::InvalidPath => errno::Errno::EINVAL,
+ }
+ }
+}
+
+pub trait NixPath {
+ fn with_nix_path<T, F>(&self, f: F) -> Result<T>
+ where F: FnOnce(&OsStr) -> T;
+}
+
+impl NixPath for [u8] {
+ fn with_nix_path<T, F>(&self, f: F) -> Result<T>
+ where F: FnOnce(&OsStr) -> T {
+ // TODO: Extract this size as a const
+ let mut buf = [0u8; 4096];
+
+ if self.len() >= 4096 {
+ return Err(Error::InvalidPath);
+ }
+
+ match self.position_elem(&0) {
+ Some(_) => Err(Error::InvalidPath),
+ None => {
+ bytes::copy_memory(&mut buf, self);
+ Ok(f(<OsStr as OsStrExt>::from_bytes(&buf[..self.len()])))
+ }
+ }
+ }
+}
+
+impl NixPath for Path {
+ fn with_nix_path<T, F>(&self, f: F) -> Result<T>
+ where F: FnOnce(&OsStr) -> T {
+ Ok(f(self.as_os_str()))
+ }
+}
+
+impl NixPath for PathBuf {
+ fn with_nix_path<T, F>(&self, f: F) -> Result<T>
+ where F: FnOnce(&OsStr) -> T {
+ Ok(f(self.as_os_str()))
+ }
+}
+
+#[inline]
+pub fn from_ffi(res: libc::c_int) -> Result<()> {
+ if res != 0 {
+ return Err(Error::Sys(errno::Errno::last()));
+ }
+
+ Ok(())
+}
+
+/*
+ *
* ===== Impl utilities =====
*
*/
diff --git a/src/mount.rs b/src/mount.rs
index c8264559..d92e18bd 100644
--- a/src/mount.rs
+++ b/src/mount.rs
@@ -1,5 +1,5 @@
use libc::{c_ulong, c_int};
-use {NixResult, NixPath, AsExtStr, from_ffi};
+use {Result, NixPath, AsExtStr, from_ffi};
bitflags!(
flags MsFlags: c_ulong {
@@ -76,7 +76,7 @@ pub fn mount<P1: ?Sized + NixPath, P2: ?Sized + NixPath, P3: ?Sized + NixPath, P
target: P2,
fstype: Option<&P3>,
flags: MsFlags,
- data: Option<&P4>) -> NixResult<()> {
+ data: Option<&P4>) -> Result<()> {
use libc;
let res = try!(try!(try!(try!(
@@ -100,7 +100,7 @@ pub fn mount<P1: ?Sized + NixPath, P2: ?Sized + NixPath, P3: ?Sized + NixPath, P
}
*/
-pub fn umount<P: ?Sized + NixPath>(target: &P) -> NixResult<()> {
+pub fn umount<P: ?Sized + NixPath>(target: &P) -> Result<()> {
let res = try!(target.with_nix_path(|ptr| {
unsafe { ffi::umount(ptr.as_ext_str()) }
}));
@@ -108,7 +108,7 @@ pub fn umount<P: ?Sized + NixPath>(target: &P) -> NixResult<()> {
from_ffi(res)
}
-pub fn umount2<P: ?Sized + NixPath>(target: &P, flags: MntFlags) -> NixResult<()> {
+pub fn umount2<P: ?Sized + NixPath>(target: &P, flags: MntFlags) -> Result<()> {
let res = try!(target.with_nix_path(|ptr| {
unsafe { ffi::umount2(ptr.as_ext_str(), flags.bits) }
}));
diff --git a/src/nix.rs b/src/nix.rs
deleted file mode 100644
index 936812ed..00000000
--- a/src/nix.rs
+++ /dev/null
@@ -1,80 +0,0 @@
-use libc;
-use std::ffi::{OsStr, AsOsStr};
-use std::os::unix::ffi::OsStrExt;
-use std::path::{Path, PathBuf};
-use std::slice::bytes;
-
-use errno::{Errno, EINVAL};
-
-pub type NixResult<T> = Result<T, NixError>;
-
-#[derive(Clone, Copy, Debug, PartialEq)]
-pub enum NixError {
- Sys(Errno),
- InvalidPath
-}
-
-impl NixError {
- pub fn last() -> NixError {
- NixError::Sys(Errno::last())
- }
-
- pub fn invalid_argument() -> NixError {
- NixError::Sys(EINVAL)
- }
-
- pub fn errno(&self) -> Errno {
- match *self {
- NixError::Sys(errno) => errno,
- NixError::InvalidPath => Errno::EINVAL,
- }
- }
-}
-
-pub trait NixPath {
- fn with_nix_path<T, F>(&self, f: F) -> Result<T, NixError>
- where F: FnOnce(&OsStr) -> T;
-}
-
-impl NixPath for [u8] {
- fn with_nix_path<T, F>(&self, f: F) -> Result<T, NixError>
- where F: FnOnce(&OsStr) -> T {
- // TODO: Extract this size as a const
- let mut buf = [0u8; 4096];
-
- if self.len() >= 4096 {
- return Err(NixError::InvalidPath);
- }
-
- match self.position_elem(&0) {
- Some(_) => Err(NixError::InvalidPath),
- None => {
- bytes::copy_memory(&mut buf, self);
- Ok(f(<OsStr as OsStrExt>::from_bytes(&buf[..self.len()])))
- }
- }
- }
-}
-
-impl NixPath for Path {
- fn with_nix_path<T, F>(&self, f: F) -> Result<T, NixError>
- where F: FnOnce(&OsStr) -> T {
- Ok(f(self.as_os_str()))
- }
-}
-
-impl NixPath for PathBuf {
- fn with_nix_path<T, F>(&self, f: F) -> Result<T, NixError>
- where F: FnOnce(&OsStr) -> T {
- Ok(f(self.as_os_str()))
- }
-}
-
-#[inline]
-pub fn from_ffi(res: libc::c_int) -> NixResult<()> {
- if res != 0 {
- return Err(NixError::Sys(Errno::last()));
- }
-
- Ok(())
-}
diff --git a/src/sched.rs b/src/sched.rs
index aa09b316..4b6c955f 100644
--- a/src/sched.rs
+++ b/src/sched.rs
@@ -1,7 +1,7 @@
use std::mem;
use libc::{c_int, c_uint, c_void, c_ulong};
use errno::Errno;
-use {NixResult, NixError};
+use {Result, Error};
pub type CloneFlags = c_uint;
@@ -143,7 +143,7 @@ mod ffi {
}
}
-pub fn sched_setaffinity(pid: isize, cpuset: &CpuSet) -> NixResult<()> {
+pub fn sched_setaffinity(pid: isize, cpuset: &CpuSet) -> Result<()> {
use libc::{pid_t, size_t};
let res = unsafe {
@@ -151,13 +151,13 @@ pub fn sched_setaffinity(pid: isize, cpuset: &CpuSet) -> NixResult<()> {
};
if res != 0 {
- Err(NixError::Sys(Errno::last()))
+ Err(Error::Sys(Errno::last()))
} else {
Ok(())
}
}
-pub fn clone(mut cb: CloneCb, stack: &mut [u8], flags: CloneFlags) -> NixResult<()> {
+pub fn clone(mut cb: CloneCb, stack: &mut [u8], flags: CloneFlags) -> Result<()> {
extern "C" fn callback(data: *mut CloneCb) -> c_int {
let cb: &mut CloneCb = unsafe { &mut *data };
(*cb)() as c_int
@@ -169,17 +169,17 @@ pub fn clone(mut cb: CloneCb, stack: &mut [u8], flags: CloneFlags) -> NixResult<
};
if res != 0 {
- return Err(NixError::Sys(Errno::last()));
+ return Err(Error::Sys(Errno::last()));
}
Ok(())
}
-pub fn unshare(flags: CloneFlags) -> NixResult<()> {
+pub fn unshare(flags: CloneFlags) -> Result<()> {
let res = unsafe { ffi::unshare(flags) };
if res != 0 {
- return Err(NixError::Sys(Errno::last()));
+ return Err(Error::Sys(Errno::last()));
}
Ok(())
diff --git a/src/sys/epoll.rs b/src/sys/epoll.rs
index 138680fe..a68a7b6f 100644
--- a/src/sys/epoll.rs
+++ b/src/sys/epoll.rs
@@ -1,7 +1,7 @@
use std::fmt;
use libc::c_int;
use errno::Errno;
-use {NixError, NixResult, from_ffi};
+use {Error, Result, from_ffi};
use fcntl::Fd;
mod ffi {
@@ -102,30 +102,30 @@ pub struct EpollEvent {
}
#[inline]
-pub fn epoll_create() -> NixResult<Fd> {
+pub fn epoll_create() -> Result<Fd> {
let res = unsafe { ffi::epoll_create(1024) };
if res < 0 {
- return Err(NixError::Sys(Errno::last()));
+ return Err(Error::Sys(Errno::last()));
}
Ok(res)
}
#[inline]
-pub fn epoll_ctl(epfd: Fd, op: EpollOp, fd: Fd, event: &EpollEvent) -> NixResult<()> {
+pub fn epoll_ctl(epfd: Fd, op: EpollOp, fd: Fd, 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) -> NixResult<usize> {
+pub fn epoll_wait(epfd: Fd, events: &mut [EpollEvent], timeout_ms: usize) -> Result<usize> {
let res = unsafe {
ffi::epoll_wait(epfd, events.as_mut_ptr(), events.len() as c_int, timeout_ms as c_int)
};
if res < 0 {
- return Err(NixError::Sys(Errno::last()));
+ return Err(Error::Sys(Errno::last()));
}
Ok(res as usize)
diff --git a/src/sys/event.rs b/src/sys/event.rs
index efe54b19..9a0ede1e 100644
--- a/src/sys/event.rs
+++ b/src/sys/event.rs
@@ -5,7 +5,7 @@ use libc::{timespec, time_t, c_int, c_long, uintptr_t};
use errno::Errno;
use fcntl::Fd;
use std::fmt;
-use {NixError, NixResult};
+use {Error, Result};
pub use self::ffi::kevent as KEvent;
@@ -159,11 +159,11 @@ bitflags!(
pub const EV_POLL: EventFlag = EV_FLAG0;
pub const EV_OOBAND: EventFlag = EV_FLAG1;
-pub fn kqueue() -> NixResult<Fd> {
+pub fn kqueue() -> Result<Fd> {
let res = unsafe { ffi::kqueue() };
if res < 0 {
- return Err(NixError::Sys(Errno::last()));
+ return Err(Error::Sys(Errno::last()));
}
Ok(res)
@@ -172,7 +172,7 @@ pub fn kqueue() -> NixResult<Fd> {
pub fn kevent(kq: Fd,
changelist: &[KEvent],
eventlist: &mut [KEvent],
- timeout_ms: usize) -> NixResult<usize> {
+ timeout_ms: usize) -> Result<usize> {
// Convert ms to timespec
let timeout = timespec {
@@ -191,7 +191,7 @@ pub fn kevent(kq: Fd,
};
if res < 0 {
- return Err(NixError::Sys(Errno::last()));
+ return Err(Error::Sys(Errno::last()));
}
return Ok(res as usize)
diff --git a/src/sys/eventfd.rs b/src/sys/eventfd.rs
index 07162f85..f072405f 100644
--- a/src/sys/eventfd.rs
+++ b/src/sys/eventfd.rs
@@ -2,7 +2,7 @@ use std::mem;
use libc::{c_int, c_uint};
use errno::Errno;
use fcntl::Fd;
-use {NixError, NixResult};
+use {Error, Result};
bitflags!(
flags EventFdFlag: c_int {
@@ -12,7 +12,7 @@ bitflags!(
}
);
-pub fn eventfd(initval: usize, flags: EventFdFlag) -> NixResult<Fd> {
+pub fn eventfd(initval: usize, flags: EventFdFlag) -> Result<Fd> {
type F = unsafe extern "C" fn(initval: c_uint, flags: c_int) -> c_int;
extern {
@@ -30,7 +30,7 @@ pub fn eventfd(initval: usize, flags: EventFdFlag) -> NixResult<Fd> {
};
if res < 0 {
- return Err(NixError::Sys(Errno::last()));
+ return Err(Error::Sys(Errno::last()));
}
Ok(res)
diff --git a/src/sys/ioctl.rs b/src/sys/ioctl.rs
index 516b29bc..5003a4f6 100644
--- a/src/sys/ioctl.rs
+++ b/src/sys/ioctl.rs
@@ -1,6 +1,6 @@
use libc;
use fcntl::Fd;
-use {NixResult, from_ffi};
+use {Result, from_ffi};
pub use self::ffi::Winsize;
pub use self::IoctlArg::*;
@@ -34,7 +34,7 @@ pub enum IoctlArg<'a> {
TIOCGWINSZ(&'a mut Winsize)
}
-pub fn ioctl(fd: Fd, arg: IoctlArg) -> NixResult<()> {
+pub fn ioctl(fd: Fd, 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 60171a9e..a905744d 100644
--- a/src/sys/mman.rs
+++ b/src/sys/mman.rs
@@ -1,4 +1,4 @@
-use {NixError, NixResult, NixPath, AsExtStr};
+use {Error, Result, NixPath, AsExtStr};
use errno::Errno;
use fcntl::{Fd, OFlag};
use libc::{c_void, size_t, off_t, mode_t};
@@ -128,54 +128,54 @@ mod ffi {
}
}
-pub unsafe fn mlock(addr: *const c_void, length: size_t) -> NixResult<()> {
+pub unsafe fn mlock(addr: *const c_void, length: size_t) -> Result<()> {
match ffi::mlock(addr, length) {
0 => Ok(()),
- _ => Err(NixError::Sys(Errno::last()))
+ _ => Err(Error::Sys(Errno::last()))
}
}
-pub fn munlock(addr: *const c_void, length: size_t) -> NixResult<()> {
+pub fn munlock(addr: *const c_void, length: size_t) -> Result<()> {
match unsafe { ffi::munlock(addr, length) } {
0 => Ok(()),
- _ => Err(NixError::Sys(Errno::last()))
+ _ => Err(Error::Sys(Errno::last()))
}
}
/// 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) -> NixResult<*mut c_void> {
+pub fn mmap(addr: *mut c_void, length: size_t, prot: MmapProt, flags: MmapFlag, fd: Fd, offset: off_t) -> Result<*mut c_void> {
let ret = unsafe { ffi::mmap(addr, length, prot, flags, fd, offset) };
if ret as isize == MAP_FAILED {
- Err(NixError::Sys(Errno::last()))
+ Err(Error::Sys(Errno::last()))
} else {
Ok(ret)
}
}
-pub fn munmap(addr: *mut c_void, len: size_t) -> NixResult<()> {
+pub fn munmap(addr: *mut c_void, len: size_t) -> Result<()> {
match unsafe { ffi::munmap(addr, len) } {
0 => Ok(()),
- _ => Err(NixError::Sys(Errno::last()))
+ _ => Err(Error::Sys(Errno::last()))
}
}
-pub fn madvise(addr: *const c_void, length: size_t, advise: MmapAdvise) -> NixResult<()> {
+pub fn madvise(addr: *const c_void, length: size_t, advise: MmapAdvise) -> Result<()> {
match unsafe { ffi::madvise(addr, length, advise) } {
0 => Ok(()),
- _ => Err(NixError::Sys(Errno::last()))
+ _ => Err(Error::Sys(Errno::last()))
}
}
-pub fn msync(addr: *const c_void, length: size_t, flags: MmapSync) -> NixResult<()> {
+pub fn msync(addr: *const c_void, length: size_t, flags: MmapSync) -> Result<()> {
match unsafe { ffi::msync(addr, length, flags) } {
0 => Ok(()),
- _ => Err(NixError::Sys(Errno::last()))
+ _ => Err(Error::Sys(Errno::last()))
}
}
-pub fn shm_open<P: ?Sized + NixPath>(name: &P, flag: OFlag, mode: Mode) -> NixResult<Fd> {
+pub fn shm_open<P: ?Sized + NixPath>(name: &P, flag: OFlag, mode: Mode) -> Result<Fd> {
let ret = try!(name.with_nix_path(|osstr| {
unsafe {
ffi::shm_open(osstr.as_ext_str(), flag.bits(), mode.bits() as mode_t)
@@ -183,19 +183,19 @@ pub fn shm_open<P: ?Sized + NixPath>(name: &P, flag: OFlag, mode: Mode) -> NixRe
}));
if ret < 0 {
- Err(NixError::Sys(Errno::last()))
+ Err(Error::Sys(Errno::last()))
} else {
Ok(ret)
}
}
-pub fn shm_unlink<P: ?Sized + NixPath>(name: &P) -> NixResult<()> {
+pub fn shm_unlink<P: ?Sized + NixPath>(name: &P) -> Result<()> {
let ret = try!(name.with_nix_path(|osstr| {
unsafe { ffi::shm_unlink(osstr.as_ext_str()) }
}));
if ret < 0 {
- Err(NixError::Sys(Errno::last()))
+ Err(Error::Sys(Errno::last()))
} else {
Ok(())
}
diff --git a/src/sys/signal.rs b/src/sys/signal.rs
index e63cff13..5dd974cc 100644
--- a/src/sys/signal.rs
+++ b/src/sys/signal.rs
@@ -4,7 +4,7 @@
use libc;
use errno::Errno;
use core::mem;
-use {NixError, NixResult};
+use {Error, Result};
pub use libc::consts::os::posix88::{
SIGHUP, // 1
@@ -312,21 +312,21 @@ impl SigSet {
SigSet { sigset: sigset }
}
- pub fn add(&mut self, signum: SigNum) -> NixResult<()> {
+ pub fn add(&mut self, signum: SigNum) -> Result<()> {
let res = unsafe { ffi::sigaddset(&mut self.sigset as *mut sigset_t, signum) };
if res < 0 {
- return Err(NixError::Sys(Errno::last()));
+ return Err(Error::Sys(Errno::last()));
}
Ok(())
}
- pub fn remove(&mut self, signum: SigNum) -> NixResult<()> {
+ pub fn remove(&mut self, signum: SigNum) -> Result<()> {
let res = unsafe { ffi::sigdelset(&mut self.sigset as *mut sigset_t, signum) };
if res < 0 {
- return Err(NixError::Sys(Errno::last()));
+ return Err(Error::Sys(Errno::last()));
}
Ok(())
@@ -350,7 +350,7 @@ impl SigAction {
}
}
-pub fn sigaction(signum: SigNum, sigaction: &SigAction) -> NixResult<SigAction> {
+pub fn sigaction(signum: SigNum, sigaction: &SigAction) -> Result<SigAction> {
let mut oldact = unsafe { mem::uninitialized::<sigaction_t>() };
let res = unsafe {
@@ -358,17 +358,17 @@ pub fn sigaction(signum: SigNum, sigaction: &SigAction) -> NixResult<SigAction>
};
if res < 0 {
- return Err(NixError::Sys(Errno::last()));
+ return Err(Error::Sys(Errno::last()));
}
Ok(SigAction { sigaction: oldact })
}
-pub fn kill(pid: libc::pid_t, signum: SigNum) -> NixResult<()> {
+pub fn kill(pid: libc::pid_t, signum: SigNum) -> Result<()> {
let res = unsafe { ffi::kill(pid, signum) };
if res < 0 {
- return Err(NixError::Sys(Errno::last()));
+ return Err(Error::Sys(Errno::last()));
}
Ok(())
diff --git a/src/sys/socket/addr.rs b/src/sys/socket/addr.rs
index 5ff65594..46c8d920 100644
--- a/src/sys/socket/addr.rs
+++ b/src/sys/socket/addr.rs
@@ -1,4 +1,4 @@
-use {NixResult, NixError, NixPath};
+use {Result, Error, NixPath};
use super::{consts, sa_family_t};
use errno::Errno;
use libc;
@@ -334,7 +334,7 @@ impl fmt::Display for Ipv6Addr {
pub struct UnixAddr(pub libc::sockaddr_un);
impl UnixAddr {
- pub fn new<P: ?Sized + NixPath>(path: &P) -> NixResult<UnixAddr> {
+ pub fn new<P: ?Sized + NixPath>(path: &P) -> Result<UnixAddr> {
try!(path.with_nix_path(|osstr| {
unsafe {
let bytes = osstr.as_bytes();
@@ -345,7 +345,7 @@ impl UnixAddr {
};
if bytes.len() >= ret.sun_path.len() {
- return Err(NixError::Sys(Errno::ENAMETOOLONG));
+ return Err(Error::Sys(Errno::ENAMETOOLONG));
}
ptr::copy(
@@ -413,7 +413,7 @@ impl SockAddr {
SockAddr::Inet(addr)
}
- pub fn new_unix<P: ?Sized + NixPath>(path: &P) -> NixResult<SockAddr> {
+ pub fn new_unix<P: ?Sized + NixPath>(path: &P) -> Result<SockAddr> {
Ok(SockAddr::Unix(try!(UnixAddr::new(path))))
}
diff --git a/src/sys/socket/mod.rs b/src/sys/socket/mod.rs
index 16cf0dfc..33d58301 100644
--- a/src/sys/socket/mod.rs
+++ b/src/sys/socket/mod.rs
@@ -1,7 +1,7 @@
//! Socket interface functions
//!
//! [Further reading](http://man7.org/linux/man-pages/man7/socket.7.html)
-use {NixError, NixResult, from_ffi};
+use {Error, Result, from_ffi};
use errno::Errno;
use features;
use fcntl::{fcntl, FD_CLOEXEC, O_NONBLOCK};
@@ -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) -> NixResult<Fd> {
+pub fn socket(domain: AddressFamily, ty: SockType, flags: SockFlag) -> Result<Fd> {
let mut ty = ty as c_int;
let feat_atomic = features::socket_atomic_cloexec();
@@ -90,7 +90,7 @@ pub fn socket(domain: AddressFamily, ty: SockType, flags: SockFlag) -> NixResult
let res = unsafe { ffi::socket(domain as c_int, ty, 0) };
if res < 0 {
- return Err(NixError::Sys(Errno::last()));
+ return Err(Error::Sys(Errno::last()));
}
if !feat_atomic {
@@ -109,7 +109,7 @@ pub fn socket(domain: AddressFamily, ty: SockType, flags: SockFlag) -> NixResult
/// 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) -> NixResult<()> {
+pub fn listen(sockfd: Fd, 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) -> NixResult<()> {
/// 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) -> NixResult<()> {
+pub fn bind(fd: Fd, addr: &SockAddr) -> Result<()> {
let res = unsafe {
let (ptr, len) = addr.as_ffi_pair();
ffi::bind(fd, ptr, len)
@@ -129,11 +129,11 @@ pub fn bind(fd: Fd, addr: &SockAddr) -> NixResult<()> {
/// Accept a connection on a socket
///
/// [Further reading](http://man7.org/linux/man-pages/man2/accept.2.html)
-pub fn accept(sockfd: Fd) -> NixResult<Fd> {
+pub fn accept(sockfd: Fd) -> Result<Fd> {
let res = unsafe { ffi::accept(sockfd, ptr::null_mut(), ptr::null_mut()) };
if res < 0 {
- return Err(NixError::Sys(Errno::last()));
+ return Err(Error::Sys(Errno::last()));
}
Ok(res)
@@ -143,7 +143,7 @@ pub fn accept(sockfd: Fd) -> NixResult<Fd> {
///
/// [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) -> NixResult<Fd> {
+pub fn accept4(sockfd: Fd, flags: SockFlag) -> Result<Fd> {
use libc::sockaddr;
type F = unsafe extern "C" fn(c_int, *mut sockaddr, *mut socklen_t, c_int) -> c_int;
@@ -160,7 +160,7 @@ pub fn accept4(sockfd: Fd, flags: SockFlag) -> NixResult<Fd> {
};
if res < 0 {
- return Err(NixError::Sys(Errno::last()));
+ return Err(Error::Sys(Errno::last()));
}
Ok(res)
@@ -173,16 +173,16 @@ pub fn accept4(sockfd: Fd, flags: SockFlag) -> NixResult<Fd> {
///
/// [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) -> NixResult<Fd> {
+pub fn accept4(sockfd: Fd, flags: SockFlag) -> Result<Fd> {
accept4_polyfill(sockfd, flags)
}
#[inline]
-fn accept4_polyfill(sockfd: Fd, flags: SockFlag) -> NixResult<Fd> {
+fn accept4_polyfill(sockfd: Fd, flags: SockFlag) -> Result<Fd> {
let res = unsafe { ffi::accept(sockfd, ptr::null_mut(), ptr::null_mut()) };
if res < 0 {
- return Err(NixError::Sys(Errno::last()));
+ return Err(Error::Sys(Errno::last()));
}
if flags.contains(SOCK_CLOEXEC) {
@@ -199,7 +199,7 @@ fn accept4_polyfill(sockfd: Fd, flags: SockFlag) -> NixResult<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) -> NixResult<()> {
+pub fn connect(fd: Fd, 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) -> NixResult<()> {
/// 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]) -> NixResult<(usize, SockAddr)> {
+pub fn recvfrom(sockfd: Fd, buf: &mut [u8]) -> Result<(usize, SockAddr)> {
unsafe {
let addr: sockaddr_storage = mem::zeroed();
let mut len = mem::size_of::<sockaddr_storage>() as socklen_t;
@@ -226,7 +226,7 @@ pub fn recvfrom(sockfd: Fd, buf: &mut [u8]) -> NixResult<(usize, SockAddr)> {
&mut len as *mut socklen_t);
if ret < 0 {
- return Err(NixError::last());
+ return Err(Error::last());
}
sockaddr_storage_to_addr(&addr, len as usize)
@@ -234,14 +234,14 @@ pub fn recvfrom(sockfd: Fd, buf: &mut [u8]) -> NixResult<(usize, SockAddr)> {
}
}
-pub fn sendto(fd: Fd, buf: &[u8], addr: &SockAddr, flags: SockMessageFlags) -> NixResult<usize> {
+pub fn sendto(fd: Fd, 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)
};
if ret < 0 {
- Err(NixError::Sys(Errno::last()))
+ Err(Error::Sys(Errno::last()))
} else {
Ok(ret as usize)
}
@@ -284,30 +284,30 @@ pub trait SockOpt : Copy + fmt::Debug {
type Set;
#[doc(hidden)]
- fn get(&self, fd: Fd, level: c_int) -> NixResult<Self::Get>;
+ fn get(&self, fd: Fd, level: c_int) -> Result<Self::Get>;
#[doc(hidden)]
- fn set(&self, fd: Fd, level: c_int, val: Self::Set) -> NixResult<()>;
+ fn set(&self, fd: Fd, 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<O: SockOpt>(fd: Fd, level: SockLevel, opt: O) -> NixResult<O::Get> {
+pub fn getsockopt<O: SockOpt>(fd: Fd, level: SockLevel, opt: O) -> Result<O::Get> {
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::Set) -> NixResult<()> {
+pub fn setsockopt<O: SockOpt>(fd: Fd, 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) -> NixResult<SockAddr> {
+pub fn getpeername(fd: Fd) -> Result<SockAddr> {
unsafe {
let addr: sockaddr_storage = mem::uninitialized();
let mut len = mem::size_of::<sockaddr_storage>() as socklen_t;
@@ -315,7 +315,7 @@ pub fn getpeername(fd: Fd) -> NixResult<SockAddr> {
let ret = ffi::getpeername(fd, mem::transmute(&addr), &mut len);
if ret < 0 {
- return Err(NixError::last());
+ return Err(Error::last());
}
sockaddr_storage_to_addr(&addr, len as usize)
@@ -325,7 +325,7 @@ pub fn getpeername(fd: Fd) -> NixResult<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) -> NixResult<SockAddr> {
+pub fn getsockname(fd: Fd) -> Result<SockAddr> {
unsafe {
let addr: sockaddr_storage = mem::uninitialized();
let mut len = mem::size_of::<sockaddr_storage>() as socklen_t;
@@ -333,7 +333,7 @@ pub fn getsockname(fd: Fd) -> NixResult<SockAddr> {
let ret = ffi::getsockname(fd, mem::transmute(&addr), &mut len);
if ret < 0 {
- return Err(NixError::last());
+ return Err(Error::last());
}
sockaddr_storage_to_addr(&addr, len as usize)
@@ -342,7 +342,7 @@ pub fn getsockname(fd: Fd) -> NixResult<SockAddr> {
pub unsafe fn sockaddr_storage_to_addr(
addr: &sockaddr_storage,
- len: usize) -> NixResult<SockAddr> {
+ len: usize) -> Result<SockAddr> {
match addr.ss_family as c_int {
consts::AF_INET => {
diff --git a/src/sys/socket/sockopt.rs b/src/sys/socket/sockopt.rs
index be3ff8e7..9a06d198 100644
--- a/src/sys/socket/sockopt.rs
+++ b/src/sys/socket/sockopt.rs
@@ -1,4 +1,4 @@
-use {NixResult, NixError, from_ffi};
+use {Result, Error, from_ffi};
use super::{ffi, consts, SockOpt};
use errno::Errno;
use sys::time::TimeVal;
@@ -29,7 +29,7 @@ macro_rules! sockopt_impl {
type Get = $get_ty;
type Set = $set_ty;
- fn get(&self, fd: Fd, level: c_int) -> NixResult<$get_ty> {
+ fn get(&self, fd: Fd, level: c_int) -> Result<$get_ty> {
unsafe {
let mut getter: $getter = Get::blank();
@@ -39,14 +39,14 @@ macro_rules! sockopt_impl {
getter.ffi_len());
if res < 0 {
- return Err(NixError::Sys(Errno::last()));
+ return Err(Error::Sys(Errno::last()));
}
Ok(getter.unwrap())
}
}
- fn set(&self, fd: Fd, level: c_int, val: $set_ty) -> NixResult<()> {
+ fn set(&self, fd: Fd, 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 f51fec4a..d98d20ec 100644
--- a/src/sys/stat.rs
+++ b/src/sys/stat.rs
@@ -1,7 +1,7 @@
pub use libc::dev_t;
pub use libc::stat as FileStat;
-use {NixError, NixResult, NixPath, AsExtStr,from_ffi};
+use {Error, Result, NixPath, AsExtStr,from_ffi};
use errno::Errno;
use fcntl::Fd;
use libc::mode_t;
@@ -57,7 +57,7 @@ impl fmt::Debug for SFlag {
}
}
-pub fn mknod<P: ?Sized + NixPath>(path: &P, kind: SFlag, perm: Mode, dev: dev_t) -> NixResult<()> {
+pub fn mknod<P: ?Sized + NixPath>(path: &P, kind: SFlag, perm: Mode, dev: dev_t) -> Result<()> {
let res = try!(path.with_nix_path(|osstr| {
unsafe {
ffi::mknod(osstr.as_ext_str(), kind.bits | perm.bits() as mode_t, dev)
@@ -79,7 +79,7 @@ pub fn umask(mode: Mode) -> Mode {
Mode::from_bits(prev).expect("[BUG] umask returned invalid Mode")
}
-pub fn stat<P: ?Sized + NixPath>(path: &P) -> NixResult<FileStat> {
+pub fn stat<P: ?Sized + NixPath>(path: &P) -> Result<FileStat> {
let mut dst = unsafe { mem::uninitialized() };
let res = try!(path.with_nix_path(|osstr| {
unsafe {
@@ -88,18 +88,18 @@ pub fn stat<P: ?Sized + NixPath>(path: &P) -> NixResult<FileStat> {
}));
if res < 0 {
- return Err(NixError::Sys(Errno::last()));
+ return Err(Error::Sys(Errno::last()));
}
Ok(dst)
}
-pub fn fstat(fd: Fd) -> NixResult<FileStat> {
+pub fn fstat(fd: Fd) -> Result<FileStat> {
let mut dst = unsafe { mem::uninitialized() };
let res = unsafe { ffi::fstat(fd, &mut dst as *mut FileStat) };
if res < 0 {
- return Err(NixError::Sys(Errno::last()));
+ return Err(Error::Sys(Errno::last()));
}
Ok(dst)
diff --git a/src/sys/termios.rs b/src/sys/termios.rs
index 7ef2ca57..c5758fe0 100644
--- a/src/sys/termios.rs
+++ b/src/sys/termios.rs
@@ -2,7 +2,7 @@ use errno::Errno;
use fcntl::Fd;
use libc::c_int;
use std::mem;
-use {NixError, NixResult, from_ffi};
+use {Error, Result, from_ffi};
pub use self::ffi::consts::*;
pub use self::ffi::consts::SetArg::*;
@@ -421,19 +421,19 @@ pub fn cfgetospeed(termios: &Termios) -> speed_t {
}
}
-pub fn cfsetispeed(termios: &mut Termios, speed: speed_t) -> NixResult<()> {
+pub fn cfsetispeed(termios: &mut Termios, speed: speed_t) -> Result<()> {
from_ffi(unsafe {
ffi::cfsetispeed(termios, speed)
})
}
-pub fn cfsetospeed(termios: &mut Termios, speed: speed_t) -> NixResult<()> {
+pub fn cfsetospeed(termios: &mut Termios, speed: speed_t) -> Result<()> {
from_ffi(unsafe {
ffi::cfsetospeed(termios, speed)
})
}
-pub fn tcgetattr(fd: Fd) -> NixResult<Termios> {
+pub fn tcgetattr(fd: Fd) -> Result<Termios> {
let mut termios = unsafe { mem::uninitialized() };
let res = unsafe {
@@ -441,7 +441,7 @@ pub fn tcgetattr(fd: Fd) -> NixResult<Termios> {
};
if res < 0 {
- return Err(NixError::Sys(Errno::last()));
+ return Err(Error::Sys(Errno::last()));
}
Ok(termios)
@@ -449,31 +449,31 @@ pub fn tcgetattr(fd: Fd) -> NixResult<Termios> {
pub fn tcsetattr(fd: Fd,
actions: SetArg,
- termios: &Termios) -> NixResult<()> {
+ termios: &Termios) -> Result<()> {
from_ffi(unsafe {
ffi::tcsetattr(fd, actions as c_int, termios)
})
}
-pub fn tcdrain(fd: Fd) -> NixResult<()> {
+pub fn tcdrain(fd: Fd) -> Result<()> {
from_ffi(unsafe {
ffi::tcdrain(fd)
})
}
-pub fn tcflow(fd: Fd, action: FlowArg) -> NixResult<()> {
+pub fn tcflow(fd: Fd, action: FlowArg) -> Result<()> {
from_ffi(unsafe {
ffi::tcflow(fd, action as c_int)
})
}
-pub fn tcflush(fd: Fd, action: FlushArg) -> NixResult<()> {
+pub fn tcflush(fd: Fd, action: FlushArg) -> Result<()> {
from_ffi(unsafe {
ffi::tcflush(fd, action as c_int)
})
}
-pub fn tcsendbreak(fd: Fd, action: c_int) -> NixResult<()> {
+pub fn tcsendbreak(fd: Fd, action: c_int) -> Result<()> {
from_ffi(unsafe {
ffi::tcsendbreak(fd, action)
})
diff --git a/src/sys/uio.rs b/src/sys/uio.rs
index 0d2072b9..62b1819b 100644
--- a/src/sys/uio.rs
+++ b/src/sys/uio.rs
@@ -1,7 +1,7 @@
// Silence invalid warnings due to rust-lang/rust#16719
#![allow(improper_ctypes)]
-use {NixResult, NixError};
+use {Result, Error};
use errno::Errno;
use fcntl::Fd;
use libc::{c_int, c_void, size_t};
@@ -23,20 +23,20 @@ mod ffi {
}
}
-pub fn writev(fd: Fd, iov: &[IoVec<&[u8]>]) -> NixResult<usize> {
+pub fn writev(fd: Fd, iov: &[IoVec<&[u8]>]) -> Result<usize> {
let res = unsafe { ffi::writev(fd, iov.as_ptr(), iov.len() as c_int) };
if res < 0 {
- return Err(NixError::Sys(Errno::last()));
+ return Err(Error::Sys(Errno::last()));
}
return Ok(res as usize)
}
-pub fn readv(fd: Fd, iov: &mut [IoVec<&mut [u8]>]) -> NixResult<usize> {
+pub fn readv(fd: Fd, 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(NixError::Sys(Errno::last()));
+ return Err(Error::Sys(Errno::last()));
}
return Ok(res as usize)
diff --git a/src/sys/wait.rs b/src/sys/wait.rs
index b07c68b5..6772dd90 100644
--- a/src/sys/wait.rs
+++ b/src/sys/wait.rs
@@ -1,6 +1,6 @@
use libc::{pid_t, c_int};
use errno::Errno;
-use {NixError, NixResult};
+use {Error, Result};
mod ffi {
use libc::{pid_t, c_int};
@@ -22,7 +22,7 @@ pub enum WaitStatus {
StillAlive
}
-pub fn waitpid(pid: pid_t, options: Option<WaitPidFlag>) -> NixResult<WaitStatus> {
+pub fn waitpid(pid: pid_t, options: Option<WaitPidFlag>) -> Result<WaitStatus> {
use self::WaitStatus::*;
let mut status: i32 = 0;
@@ -35,7 +35,7 @@ pub fn waitpid(pid: pid_t, options: Option<WaitPidFlag>) -> NixResult<WaitStatus
let res = unsafe { ffi::waitpid(pid as pid_t, &mut status as *mut c_int, option_bits) };
if res < 0 {
- Err(NixError::Sys(Errno::last()))
+ Err(Error::Sys(Errno::last()))
} else if res == 0 {
Ok(StillAlive)
} else {
diff --git a/src/unistd.rs b/src/unistd.rs
index d07a170a..9df6cd76 100644
--- a/src/unistd.rs
+++ b/src/unistd.rs
@@ -1,6 +1,6 @@
//! Standard symbolic constants and types
//!
-use {NixError, NixResult, NixPath, AsExtStr, from_ffi};
+use {Error, Result, NixPath, AsExtStr, from_ffi};
use errno::Errno;
use fcntl::{fcntl, Fd, OFlag, O_NONBLOCK, O_CLOEXEC, FD_CLOEXEC};
use fcntl::FcntlArg::{F_SETFD, F_SETFL};
@@ -66,13 +66,13 @@ impl Fork {
}
}
-pub fn fork() -> NixResult<Fork> {
+pub fn fork() -> Result<Fork> {
use self::Fork::*;
let res = unsafe { ffi::fork() };
if res < 0 {
- return Err(NixError::Sys(Errno::last()));
+ return Err(Error::Sys(Errno::last()));
} else if res == 0 {
Ok(Child)
} else {
@@ -81,29 +81,29 @@ pub fn fork() -> NixResult<Fork> {
}
#[inline]
-pub fn dup(oldfd: Fd) -> NixResult<Fd> {
+pub fn dup(oldfd: Fd) -> Result<Fd> {
let res = unsafe { ffi::dup(oldfd) };
if res < 0 {
- return Err(NixError::Sys(Errno::last()));
+ return Err(Error::Sys(Errno::last()));
}
Ok(res)
}
#[inline]
-pub fn dup2(oldfd: Fd, newfd: Fd) -> NixResult<Fd> {
+pub fn dup2(oldfd: Fd, newfd: Fd) -> Result<Fd> {
let res = unsafe { ffi::dup2(oldfd, newfd) };
if res < 0 {
- return Err(NixError::Sys(Errno::last()));
+ return Err(Error::Sys(Errno::last()));
}
Ok(res)
}
#[cfg(not(any(target_os = "macos", target_os = "ios")))]
-pub fn dup3(oldfd: Fd, newfd: Fd, flags: OFlag) -> NixResult<Fd> {
+pub fn dup3(oldfd: Fd, newfd: Fd, flags: OFlag) -> Result<Fd> {
type F = unsafe extern "C" fn(c_int, c_int, c_int) -> c_int;
extern {
@@ -118,7 +118,7 @@ pub fn dup3(oldfd: Fd, newfd: Fd, flags: OFlag) -> NixResult<Fd> {
};
if res < 0 {
- return Err(NixError::Sys(Errno::last()));
+ return Err(Error::Sys(Errno::last()));
}
Ok(res)
@@ -128,16 +128,16 @@ pub fn dup3(oldfd: Fd, newfd: Fd, flags: OFlag) -> NixResult<Fd> {
}
#[cfg(any(target_os = "macos", target_os = "ios"))]
-pub fn dup3(oldfd: Fd, newfd: Fd, flags: OFlag) -> NixResult<Fd> {
+pub fn dup3(oldfd: Fd, newfd: Fd, flags: OFlag) -> Result<Fd> {
dup3_polyfill(oldfd, newfd, flags)
}
#[inline]
-fn dup3_polyfill(oldfd: Fd, newfd: Fd, flags: OFlag) -> NixResult<Fd> {
+fn dup3_polyfill(oldfd: Fd, newfd: Fd, flags: OFlag) -> Result<Fd> {
use errno::EINVAL;
if oldfd == newfd {
- return Err(NixError::Sys(Errno::EINVAL));
+ return Err(Error::Sys(Errno::EINVAL));
}
let fd = try!(dup2(oldfd, newfd));
@@ -153,20 +153,20 @@ fn dup3_polyfill(oldfd: Fd, newfd: Fd, flags: OFlag) -> NixResult<Fd> {
}
#[inline]
-pub fn chdir<P: ?Sized + NixPath>(path: &P) -> NixResult<()> {
+pub fn chdir<P: ?Sized + NixPath>(path: &P) -> Result<()> {
let res = try!(path.with_nix_path(|osstr| {
unsafe { ffi::chdir(osstr.as_ext_str()) }
}));
if res != 0 {
- return Err(NixError::Sys(Errno::last()));
+ return Err(Error::Sys(Errno::last()));
}
return Ok(())
}
#[inline]
-pub fn execve(filename: &CString, args: &[CString], env: &[CString]) -> NixResult<()> {
+pub fn execve(filename: &CString, args: &[CString], env: &[CString]) -> Result<()> {
let mut args_p: Vec<*const c_char> = args.iter().map(|s| s.as_ptr()).collect();
args_p.push(ptr::null());
@@ -178,18 +178,18 @@ pub fn execve(filename: &CString, args: &[CString], env: &[CString]) -> NixResul
};
if res != 0 {
- return Err(NixError::Sys(Errno::last()));
+ return Err(Error::Sys(Errno::last()));
}
unreachable!()
}
-pub fn daemon(nochdir: bool, noclose: bool) -> NixResult<()> {
+pub fn daemon(nochdir: bool, noclose: bool) -> Result<()> {
let res = unsafe { ffi::daemon(nochdir as c_int, noclose as c_int) };
from_ffi(res)
}
-pub fn sethostname(name: &[u8]) -> NixResult<()> {
+pub fn sethostname(name: &[u8]) -> Result<()> {
let ptr = name.as_ptr() as *const c_char;
let len = name.len() as size_t;
@@ -197,7 +197,7 @@ pub fn sethostname(name: &[u8]) -> NixResult<()> {
from_ffi(res)
}
-pub fn gethostname(name: &mut [u8]) -> NixResult<()> {
+pub fn gethostname(name: &mut [u8]) -> Result<()> {
let ptr = name.as_mut_ptr() as *mut c_char;
let len = name.len() as size_t;
@@ -205,32 +205,32 @@ pub fn gethostname(name: &mut [u8]) -> NixResult<()> {
from_ffi(res)
}
-pub fn close(fd: Fd) -> NixResult<()> {
+pub fn close(fd: Fd) -> Result<()> {
let res = unsafe { ffi::close(fd) };
from_ffi(res)
}
-pub fn read(fd: Fd, buf: &mut [u8]) -> NixResult<usize> {
+pub fn read(fd: Fd, 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 {
- return Err(NixError::Sys(Errno::last()));
+ return Err(Error::Sys(Errno::last()));
}
return Ok(res as usize)
}
-pub fn write(fd: Fd, buf: &[u8]) -> NixResult<usize> {
+pub fn write(fd: Fd, 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 {
- return Err(NixError::Sys(Errno::last()));
+ return Err(Error::Sys(Errno::last()));
}
return Ok(res as usize)
}
-pub fn pipe() -> NixResult<(Fd, Fd)> {
+pub fn pipe() -> Result<(Fd, Fd)> {
unsafe {
let mut res;
let mut fds: [c_int; 2] = mem::uninitialized();
@@ -238,7 +238,7 @@ pub fn pipe() -> NixResult<(Fd, Fd)> {
res = ffi::pipe(fds.as_mut_ptr());
if res < 0 {
- return Err(NixError::Sys(Errno::last()));
+ return Err(Error::Sys(Errno::last()));
}
Ok((fds[0], fds[1]))
@@ -246,7 +246,7 @@ pub fn pipe() -> NixResult<(Fd, Fd)> {
}
#[cfg(any(target_os = "linux", target_os = "android"))]
-pub fn pipe2(flags: OFlag) -> NixResult<(Fd, Fd)> {
+pub fn pipe2(flags: OFlag) -> Result<(Fd, Fd)> {
type F = unsafe extern "C" fn(fds: *mut c_int, flags: c_int) -> c_int;
extern {
@@ -268,7 +268,7 @@ pub fn pipe2(flags: OFlag) -> NixResult<(Fd, Fd)> {
}
if res < 0 {
- return Err(NixError::Sys(Errno::last()));
+ return Err(Error::Sys(Errno::last()));
}
if !feat_atomic {
@@ -280,7 +280,7 @@ pub fn pipe2(flags: OFlag) -> NixResult<(Fd, Fd)> {
}
#[cfg(any(target_os = "macos", target_os = "ios"))]
-pub fn pipe2(flags: OFlag) -> NixResult<(Fd, Fd)> {
+pub fn pipe2(flags: OFlag) -> Result<(Fd, Fd)> {
unsafe {
let mut res;
let mut fds: [c_int; 2] = mem::uninitialized();
@@ -288,7 +288,7 @@ pub fn pipe2(flags: OFlag) -> NixResult<(Fd, Fd)> {
res = ffi::pipe(fds.as_mut_ptr());
if res < 0 {
- return Err(NixError::Sys(Errno::last()));
+ return Err(Error::Sys(Errno::last()));
}
try!(pipe2_setflags(fds[0], fds[1], flags));
@@ -297,7 +297,7 @@ pub fn pipe2(flags: OFlag) -> NixResult<(Fd, Fd)> {
}
}
-fn pipe2_setflags(fd1: Fd, fd2: Fd, flags: OFlag) -> NixResult<()> {
+fn pipe2_setflags(fd1: Fd, fd2: Fd, flags: OFlag) -> Result<()> {
let mut res = Ok(());
if flags.contains(O_CLOEXEC) {
@@ -322,15 +322,15 @@ fn pipe2_setflags(fd1: Fd, fd2: Fd, flags: OFlag) -> NixResult<()> {
}
}
-pub fn ftruncate(fd: Fd, len: off_t) -> NixResult<()> {
+pub fn ftruncate(fd: Fd, len: off_t) -> Result<()> {
if unsafe { ffi::ftruncate(fd, len) } < 0 {
- Err(NixError::Sys(Errno::last()))
+ Err(Error::Sys(Errno::last()))
} else {
Ok(())
}
}
-pub fn isatty(fd: Fd) -> NixResult<bool> {
+pub fn isatty(fd: Fd) -> Result<bool> {
use libc;
if unsafe { libc::isatty(fd) } == 1 {
@@ -340,12 +340,12 @@ pub fn isatty(fd: Fd) -> NixResult<bool> {
// ENOTTY means `fd` is a valid file descriptor, but not a TTY, so
// we return `Ok(false)`
Errno::ENOTTY => Ok(false),
- err => Err(NixError::Sys(err))
+ err => Err(Error::Sys(err))
}
}
}
-pub fn unlink<P: ?Sized + NixPath>(path: &P) -> NixResult<()> {
+pub fn unlink<P: ?Sized + NixPath>(path: &P) -> Result<()> {
let res = try!(path.with_nix_path(|osstr| {
unsafe {
ffi::unlink(osstr.as_ext_str())
@@ -358,10 +358,10 @@ pub fn unlink<P: ?Sized + NixPath>(path: &P) -> NixResult<()> {
mod linux {
use sys::syscall::{syscall, SYSPIVOTROOT};
use errno::Errno;
- use {NixError, NixResult, NixPath};
+ use {Error, Result, NixPath};
pub fn pivot_root<P1: ?Sized + NixPath, P2: ?Sized + NixPath>(
- new_root: &P1, put_old: &P2) -> NixResult<()> {
+ new_root: &P1, put_old: &P2) -> Result<()> {
let res = try!(try!(new_root.with_nix_path(|new_root| {
put_old.with_nix_path(|put_old| {
unsafe {
@@ -371,7 +371,7 @@ mod linux {
})));
if res != 0 {
- return Err(NixError::Sys(Errno::last()));
+ return Err(Error::Sys(Errno::last()));
}
Ok(())
diff --git a/test/sys/test_socket.rs b/test/sys/test_socket.rs
index d175b693..97ee889d 100644
--- a/test/sys/test_socket.rs
+++ b/test/sys/test_socket.rs
@@ -30,7 +30,7 @@ pub fn test_path_to_sock_addr() {
let actual = Path::new("/foo/bar");
let addr = UnixAddr::new(actual).unwrap();
- let expect: &'static [i8] = unsafe { mem::transmute(b"/foo/bar") };
+ let expect: &'static [i8] = unsafe { mem::transmute(b"/foo/bar".as_slice()) };
assert_eq!(&addr.0.sun_path[..8], expect);
assert_eq!(addr.path(), actual);
diff --git a/test/sys/test_termios.rs b/test/sys/test_termios.rs
index 24ce3434..fd6dbcd6 100644
--- a/test/sys/test_termios.rs
+++ b/test/sys/test_termios.rs
@@ -1,6 +1,6 @@
use nix::errno::Errno;
use nix::sys::termios;
-use nix::{NixError, unistd};
+use nix::{Error, unistd};
#[test]
fn test_tcgetattr() {
@@ -11,8 +11,8 @@ fn test_tcgetattr() {
Ok(true) => assert!(termios.is_ok()),
// If it's an invalid file descriptor, tcgetattr should also return
// the same error
- Err(NixError::Sys(Errno::EBADF)) => {
- assert!(termios.err() == Some(NixError::Sys(Errno::EBADF)));
+ Err(Error::Sys(Errno::EBADF)) => {
+ assert!(termios.err() == Some(Error::Sys(Errno::EBADF)));
},
// Otherwise it should return any error
_ => assert!(termios.is_err())
diff --git a/test/test_stat.rs b/test/test_stat.rs
index 023cb569..dc3bddad 100644
--- a/test/test_stat.rs
+++ b/test/test_stat.rs
@@ -4,9 +4,9 @@ use nix::fcntl::open;
use nix::unistd::{close, unlink};
use nix::fcntl::O_CREAT;
use nix::sys::stat::{FileStat, S_IWUSR};
-use nix::NixResult;
+use nix::Result;
-fn assert_stat_results(stat_result: NixResult<FileStat>) {
+fn assert_stat_results(stat_result: Result<FileStat>) {
match stat_result {
Ok(stats) => {
assert!(stats.st_dev > 0); // must be positive integer, exact number machine dependent
@@ -27,7 +27,7 @@ fn assert_stat_results(stat_result: NixResult<FileStat>) {
#[test]
fn test_stat_and_fstat() {
- let filename = b"target/foo.txt";
+ let filename = b"target/foo.txt".as_slice();
let fd = open(filename, O_CREAT, S_IWUSR).unwrap(); // create empty file
let stat_result = stat(filename);
diff --git a/test/test_unistd.rs b/test/test_unistd.rs
index d457c668..7a70dca1 100644
--- a/test/test_unistd.rs
+++ b/test/test_unistd.rs
@@ -50,11 +50,11 @@ fn test_execve() {
dup(writer).unwrap();
// exec!
execve(&CString::new(SH_PATH).unwrap(),
- &[CString::new(b"").unwrap(),
- CString::new(b"-c").unwrap(),
- CString::new(b"echo nix!!! && echo foo=$foo && echo baz=$baz").unwrap()],
- &[CString::new(b"foo=bar").unwrap(),
- CString::new(b"baz=quux").unwrap()]).unwrap();
+ &[CString::new(b"".as_slice()).unwrap(),
+ CString::new(b"-c".as_slice()).unwrap(),
+ CString::new(b"echo nix!!! && echo foo=$foo && echo baz=$baz".as_slice()).unwrap()],
+ &[CString::new(b"foo=bar".as_slice()).unwrap(),
+ CString::new(b"baz=quux".as_slice()).unwrap()]).unwrap();
},
Parent(child_pid) => {
// Wait for the child to exit.