summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorbors[bot] <bors[bot]@users.noreply.github.com>2018-12-09 01:05:23 +0000
committerbors[bot] <bors[bot]@users.noreply.github.com>2018-12-09 01:05:23 +0000
commitf1b12d6b1b8bf6d8ad41e7b2967b95c6f876745c (patch)
treedbbf94ee5189b13ea4d448ba63512b43f85b4ba8 /src
parent5a3ac8df3fa2de86477d961d8b5720b1d283b2d5 (diff)
parentca035734df2e3dfeb866cbfee51de7b582be83f5 (diff)
downloadnix-f1b12d6b1b8bf6d8ad41e7b2967b95c6f876745c.zip
Merge #995
995: Replace try! with ? r=asomers a=asomers try! is not available in Rust 2018. It would be premature to convert the entire project to Rust 2018, since that would bump the minimum compiler to 1.31.0. But his change will help us when we do convert it eventually. Co-authored-by: Alan Somers <asomers@gmail.com>
Diffstat (limited to 'src')
-rw-r--r--src/fcntl.rs16
-rw-r--r--src/mount.rs12
-rw-r--r--src/mqueue.rs4
-rw-r--r--src/net/if_.rs2
-rw-r--r--src/sys/mman.rs8
-rw-r--r--src/sys/quota.rs14
-rw-r--r--src/sys/signal.rs4
-rw-r--r--src/sys/signalfd.rs2
-rw-r--r--src/sys/socket/addr.rs8
-rw-r--r--src/sys/socket/mod.rs10
-rw-r--r--src/sys/socket/sockopt.rs2
-rw-r--r--src/sys/stat.rs24
-rw-r--r--src/sys/statfs.rs4
-rw-r--r--src/sys/statvfs.rs6
-rw-r--r--src/sys/termios.rs2
-rw-r--r--src/sys/time.rs22
-rw-r--r--src/sys/wait.rs11
-rw-r--r--src/unistd.rs54
18 files changed, 101 insertions, 104 deletions
diff --git a/src/fcntl.rs b/src/fcntl.rs
index 5942506b..a763c10f 100644
--- a/src/fcntl.rs
+++ b/src/fcntl.rs
@@ -139,17 +139,17 @@ libc_bitflags!(
);
pub fn open<P: ?Sized + NixPath>(path: &P, oflag: OFlag, mode: Mode) -> Result<RawFd> {
- let fd = try!(path.with_nix_path(|cstr| {
+ let fd = path.with_nix_path(|cstr| {
unsafe { libc::open(cstr.as_ptr(), oflag.bits(), mode.bits() as c_uint) }
- }));
+ })?;
Errno::result(fd)
}
pub fn openat<P: ?Sized + NixPath>(dirfd: RawFd, path: &P, oflag: OFlag, mode: Mode) -> Result<RawFd> {
- let fd = try!(path.with_nix_path(|cstr| {
+ let fd = path.with_nix_path(|cstr| {
unsafe { libc::openat(dirfd, cstr.as_ptr(), oflag.bits(), mode.bits() as c_uint) }
- }));
+ })?;
Errno::result(fd)
}
@@ -167,18 +167,18 @@ fn wrap_readlink_result(buffer: &mut[u8], res: ssize_t) -> Result<&OsStr> {
}
pub fn readlink<'a, P: ?Sized + NixPath>(path: &P, buffer: &'a mut [u8]) -> Result<&'a OsStr> {
- let res = try!(path.with_nix_path(|cstr| {
+ let res = path.with_nix_path(|cstr| {
unsafe { libc::readlink(cstr.as_ptr(), buffer.as_mut_ptr() as *mut c_char, buffer.len() as size_t) }
- }));
+ })?;
wrap_readlink_result(buffer, res)
}
pub fn readlinkat<'a, P: ?Sized + NixPath>(dirfd: RawFd, path: &P, buffer: &'a mut [u8]) -> Result<&'a OsStr> {
- let res = try!(path.with_nix_path(|cstr| {
+ let res = path.with_nix_path(|cstr| {
unsafe { libc::readlinkat(dirfd, cstr.as_ptr(), buffer.as_mut_ptr() as *mut c_char, buffer.len() as size_t) }
- }));
+ })?;
wrap_readlink_result(buffer, res)
}
diff --git a/src/mount.rs b/src/mount.rs
index 8fe99513..72b719d7 100644
--- a/src/mount.rs
+++ b/src/mount.rs
@@ -63,7 +63,7 @@ pub fn mount<P1: ?Sized + NixPath, P2: ?Sized + NixPath, P3: ?Sized + NixPath, P
data: Option<&P4>) -> Result<()> {
use libc;
- let res = try!(try!(try!(try!(
+ let res =
source.with_nix_path(|source| {
target.with_nix_path(|target| {
fstype.with_nix_path(|fstype| {
@@ -78,23 +78,23 @@ pub fn mount<P1: ?Sized + NixPath, P2: ?Sized + NixPath, P3: ?Sized + NixPath, P
})
})
})
- })))));
+ })????;
Errno::result(res).map(drop)
}
pub fn umount<P: ?Sized + NixPath>(target: &P) -> Result<()> {
- let res = try!(target.with_nix_path(|cstr| {
+ let res = target.with_nix_path(|cstr| {
unsafe { libc::umount(cstr.as_ptr()) }
- }));
+ })?;
Errno::result(res).map(drop)
}
pub fn umount2<P: ?Sized + NixPath>(target: &P, flags: MntFlags) -> Result<()> {
- let res = try!(target.with_nix_path(|cstr| {
+ let res = target.with_nix_path(|cstr| {
unsafe { libc::umount2(cstr.as_ptr(), flags.bits) }
- }));
+ })?;
Errno::result(res).map(drop)
}
diff --git a/src/mqueue.rs b/src/mqueue.rs
index 0c6990f6..87be6532 100644
--- a/src/mqueue.rs
+++ b/src/mqueue.rs
@@ -152,7 +152,7 @@ pub fn mq_setattr(mqd: mqd_t, newattr: &MqAttr) -> Result<MqAttr> {
/// Sets the `O_NONBLOCK` attribute for a given message queue descriptor
/// Returns the old attributes
pub fn mq_set_nonblock(mqd: mqd_t) -> Result<(MqAttr)> {
- let oldattr = try!(mq_getattr(mqd));
+ let oldattr = mq_getattr(mqd)?;
let newattr = MqAttr::new(MQ_OFlag::O_NONBLOCK.bits() as c_long,
oldattr.mq_attr.mq_maxmsg,
oldattr.mq_attr.mq_msgsize,
@@ -164,7 +164,7 @@ pub fn mq_set_nonblock(mqd: mqd_t) -> Result<(MqAttr)> {
/// Removes `O_NONBLOCK` attribute for a given message queue descriptor
/// Returns the old attributes
pub fn mq_remove_nonblock(mqd: mqd_t) -> Result<(MqAttr)> {
- let oldattr = try!(mq_getattr(mqd));
+ let oldattr = mq_getattr(mqd)?;
let newattr = MqAttr::new(0,
oldattr.mq_attr.mq_maxmsg,
oldattr.mq_attr.mq_msgsize,
diff --git a/src/net/if_.rs b/src/net/if_.rs
index 714eac77..58d677ae 100644
--- a/src/net/if_.rs
+++ b/src/net/if_.rs
@@ -9,7 +9,7 @@ use {Result, Error, NixPath};
/// Resolve an interface into a interface number.
pub fn if_nametoindex<P: ?Sized + NixPath>(name: &P) -> Result<c_uint> {
- let if_index = try!(name.with_nix_path(|name| unsafe { libc::if_nametoindex(name.as_ptr()) }));
+ let if_index = name.with_nix_path(|name| unsafe { libc::if_nametoindex(name.as_ptr()) })?;
if if_index == 0 {
Err(Error::last())
diff --git a/src/sys/mman.rs b/src/sys/mman.rs
index 48b5767e..a30629db 100644
--- a/src/sys/mman.rs
+++ b/src/sys/mman.rs
@@ -264,7 +264,7 @@ pub unsafe fn msync(addr: *mut c_void, length: size_t, flags: MsFlags) -> Result
#[cfg(not(target_os = "android"))]
pub fn shm_open<P: ?Sized + NixPath>(name: &P, flag: OFlag, mode: Mode) -> Result<RawFd> {
- let ret = try!(name.with_nix_path(|cstr| {
+ let ret = name.with_nix_path(|cstr| {
#[cfg(any(target_os = "macos", target_os = "ios"))]
unsafe {
libc::shm_open(cstr.as_ptr(), flag.bits(), mode.bits() as libc::c_uint)
@@ -273,16 +273,16 @@ pub fn shm_open<P: ?Sized + NixPath>(name: &P, flag: OFlag, mode: Mode) -> Resul
unsafe {
libc::shm_open(cstr.as_ptr(), flag.bits(), mode.bits() as libc::mode_t)
}
- }));
+ })?;
Errno::result(ret)
}
#[cfg(not(target_os = "android"))]
pub fn shm_unlink<P: ?Sized + NixPath>(name: &P) -> Result<()> {
- let ret = try!(name.with_nix_path(|cstr| {
+ let ret = name.with_nix_path(|cstr| {
unsafe { libc::shm_unlink(cstr.as_ptr()) }
- }));
+ })?;
Errno::result(ret).map(drop)
}
diff --git a/src/sys/quota.rs b/src/sys/quota.rs
index b4cac1dc..14c04629 100644
--- a/src/sys/quota.rs
+++ b/src/sys/quota.rs
@@ -231,12 +231,10 @@ impl Dqblk {
fn quotactl<P: ?Sized + NixPath>(cmd: QuotaCmd, special: Option<&P>, id: c_int, addr: *mut c_char) -> Result<()> {
unsafe {
Errno::clear();
- let res = try!(
- match special {
- Some(dev) => dev.with_nix_path(|path| libc::quotactl(cmd.as_int(), path.as_ptr(), id, addr)),
- None => Ok(libc::quotactl(cmd.as_int(), ptr::null(), id, addr)),
- }
- );
+ let res = match special {
+ Some(dev) => dev.with_nix_path(|path| libc::quotactl(cmd.as_int(), path.as_ptr(), id, addr)),
+ None => Ok(libc::quotactl(cmd.as_int(), ptr::null(), id, addr)),
+ }?;
Errno::result(res).map(drop)
}
@@ -244,11 +242,11 @@ fn quotactl<P: ?Sized + NixPath>(cmd: QuotaCmd, special: Option<&P>, id: c_int,
/// Turn on disk quotas for a block device.
pub fn quotactl_on<P: ?Sized + NixPath>(which: QuotaType, special: &P, format: QuotaFmt, quota_file: &P) -> Result<()> {
- try!(quota_file.with_nix_path(|path| {
+ quota_file.with_nix_path(|path| {
let mut path_copy = path.to_bytes_with_nul().to_owned();
let p: *mut c_char = path_copy.as_mut_ptr() as *mut c_char;
quotactl(QuotaCmd(QuotaSubCmd::Q_QUOTAON, which), Some(special), format as c_int, p)
- }))
+ })?
}
/// Disable disk quotas for a block device.
diff --git a/src/sys/signal.rs b/src/sys/signal.rs
index c9826d72..7135b733 100644
--- a/src/sys/signal.rs
+++ b/src/sys/signal.rs
@@ -413,7 +413,7 @@ impl SigSet {
/// Gets the currently blocked (masked) set of signals for the calling thread.
pub fn thread_get_mask() -> Result<SigSet> {
let mut oldmask: SigSet = unsafe { mem::uninitialized() };
- try!(pthread_sigmask(SigmaskHow::SIG_SETMASK, None, Some(&mut oldmask)));
+ pthread_sigmask(SigmaskHow::SIG_SETMASK, None, Some(&mut oldmask))?;
Ok(oldmask)
}
@@ -435,7 +435,7 @@ impl SigSet {
/// Sets the set of signals as the signal mask, and returns the old mask.
pub fn thread_swap_mask(&self, how: SigmaskHow) -> Result<SigSet> {
let mut oldmask: SigSet = unsafe { mem::uninitialized() };
- try!(pthread_sigmask(how, Some(self), Some(&mut oldmask)));
+ pthread_sigmask(how, Some(self), Some(&mut oldmask))?;
Ok(oldmask)
}
diff --git a/src/sys/signalfd.rs b/src/sys/signalfd.rs
index 65c09ea4..5425a27b 100644
--- a/src/sys/signalfd.rs
+++ b/src/sys/signalfd.rs
@@ -88,7 +88,7 @@ impl SignalFd {
}
pub fn with_flags(mask: &SigSet, flags: SfdFlags) -> Result<SignalFd> {
- let fd = try!(signalfd(SIGNALFD_NEW, mask, flags));
+ let fd = signalfd(SIGNALFD_NEW, mask, flags)?;
Ok(SignalFd(fd))
}
diff --git a/src/sys/socket/addr.rs b/src/sys/socket/addr.rs
index ebd32c1f..b2cafe3c 100644
--- a/src/sys/socket/addr.rs
+++ b/src/sys/socket/addr.rs
@@ -600,7 +600,7 @@ pub struct UnixAddr(pub libc::sockaddr_un, pub usize);
impl UnixAddr {
/// Create a new sockaddr_un representing a filesystem path.
pub fn new<P: ?Sized + NixPath>(path: &P) -> Result<UnixAddr> {
- try!(path.with_nix_path(|cstr| {
+ path.with_nix_path(|cstr| {
unsafe {
let mut ret = libc::sockaddr_un {
sun_family: AddressFamily::Unix as sa_family_t,
@@ -619,7 +619,7 @@ impl UnixAddr {
Ok(UnixAddr(ret, bytes.len()))
}
- }))
+ })?
}
/// Create a new `sockaddr_un` representing an address in the "abstract namespace".
@@ -759,7 +759,7 @@ impl SockAddr {
}
pub fn new_unix<P: ?Sized + NixPath>(path: &P) -> Result<SockAddr> {
- Ok(SockAddr::Unix(try!(UnixAddr::new(path))))
+ Ok(SockAddr::Unix(UnixAddr::new(path)?))
}
#[cfg(any(target_os = "android", target_os = "linux"))]
@@ -1079,7 +1079,7 @@ pub mod sys_control {
ctl_name[..name.len()].clone_from_slice(name.as_bytes());
let mut info = ctl_ioc_info { ctl_id: 0, ctl_name: ctl_name };
- unsafe { try!(ctl_info(sockfd, &mut info)); }
+ unsafe { ctl_info(sockfd, &mut info)?; }
Ok(SysControlAddr::new(info.ctl_id, unit))
}
diff --git a/src/sys/socket/mod.rs b/src/sys/socket/mod.rs
index 85acaf4c..2ac0e24a 100644
--- a/src/sys/socket/mod.rs
+++ b/src/sys/socket/mod.rs
@@ -750,7 +750,7 @@ pub fn recvmsg<'a, T>(fd: RawFd, iov: &[IoVec<&mut [u8]>], cmsg_buffer: Option<&
};
Ok(unsafe { RecvMsg {
- bytes: try!(Errno::result(ret)) as usize,
+ bytes: Errno::result(ret)? as usize,
cmsg_buffer,
address: sockaddr_storage_to_addr(&address,
mhdr.msg_namelen as usize).ok(),
@@ -890,13 +890,13 @@ pub fn recvfrom(sockfd: RawFd, buf: &mut [u8]) -> Result<(usize, SockAddr)> {
let addr: sockaddr_storage = mem::zeroed();
let mut len = mem::size_of::<sockaddr_storage>() as socklen_t;
- let ret = try!(Errno::result(libc::recvfrom(
+ let ret = Errno::result(libc::recvfrom(
sockfd,
buf.as_ptr() as *mut c_void,
buf.len() as size_t,
0,
mem::transmute(&addr),
- &mut len as *mut socklen_t)));
+ &mut len as *mut socklen_t))?;
sockaddr_storage_to_addr(&addr, len as usize)
.map(|addr| (ret as usize, addr))
@@ -1004,7 +1004,7 @@ pub fn getpeername(fd: RawFd) -> Result<SockAddr> {
let ret = libc::getpeername(fd, mem::transmute(&addr), &mut len);
- try!(Errno::result(ret));
+ Errno::result(ret)?;
sockaddr_storage_to_addr(&addr, len as usize)
}
@@ -1020,7 +1020,7 @@ pub fn getsockname(fd: RawFd) -> Result<SockAddr> {
let ret = libc::getsockname(fd, mem::transmute(&addr), &mut len);
- try!(Errno::result(ret));
+ Errno::result(ret)?;
sockaddr_storage_to_addr(&addr, len as usize)
}
diff --git a/src/sys/socket/sockopt.rs b/src/sys/socket/sockopt.rs
index 17119384..f166d997 100644
--- a/src/sys/socket/sockopt.rs
+++ b/src/sys/socket/sockopt.rs
@@ -89,7 +89,7 @@ macro_rules! getsockopt_impl {
let res = libc::getsockopt(fd, $level, $flag,
getter.ffi_ptr(),
getter.ffi_len());
- try!(Errno::result(res));
+ Errno::result(res)?;
Ok(getter.unwrap())
}
diff --git a/src/sys/stat.rs b/src/sys/stat.rs
index f3a2e7e3..e0367859 100644
--- a/src/sys/stat.rs
+++ b/src/sys/stat.rs
@@ -43,11 +43,11 @@ libc_bitflags! {
}
pub fn mknod<P: ?Sized + NixPath>(path: &P, kind: SFlag, perm: Mode, dev: dev_t) -> Result<()> {
- let res = try!(path.with_nix_path(|cstr| {
+ let res = path.with_nix_path(|cstr| {
unsafe {
libc::mknod(cstr.as_ptr(), kind.bits | perm.bits() as mode_t, dev)
}
- }));
+ })?;
Errno::result(res).map(drop)
}
@@ -79,26 +79,26 @@ pub fn umask(mode: Mode) -> Mode {
pub fn stat<P: ?Sized + NixPath>(path: &P) -> Result<FileStat> {
let mut dst = unsafe { mem::uninitialized() };
- let res = try!(path.with_nix_path(|cstr| {
+ let res = path.with_nix_path(|cstr| {
unsafe {
libc::stat(cstr.as_ptr(), &mut dst as *mut FileStat)
}
- }));
+ })?;
- try!(Errno::result(res));
+ Errno::result(res)?;
Ok(dst)
}
pub fn lstat<P: ?Sized + NixPath>(path: &P) -> Result<FileStat> {
let mut dst = unsafe { mem::uninitialized() };
- let res = try!(path.with_nix_path(|cstr| {
+ let res = path.with_nix_path(|cstr| {
unsafe {
libc::lstat(cstr.as_ptr(), &mut dst as *mut FileStat)
}
- }));
+ })?;
- try!(Errno::result(res));
+ Errno::result(res)?;
Ok(dst)
}
@@ -107,18 +107,18 @@ pub fn fstat(fd: RawFd) -> Result<FileStat> {
let mut dst = unsafe { mem::uninitialized() };
let res = unsafe { libc::fstat(fd, &mut dst as *mut FileStat) };
- try!(Errno::result(res));
+ Errno::result(res)?;
Ok(dst)
}
pub fn fstatat<P: ?Sized + NixPath>(dirfd: RawFd, pathname: &P, f: AtFlags) -> Result<FileStat> {
let mut dst = unsafe { mem::uninitialized() };
- let res = try!(pathname.with_nix_path(|cstr| {
+ let res = pathname.with_nix_path(|cstr| {
unsafe { libc::fstatat(dirfd, cstr.as_ptr(), &mut dst as *mut FileStat, f.bits() as libc::c_int) }
- }));
+ })?;
- try!(Errno::result(res));
+ Errno::result(res)?;
Ok(dst)
}
diff --git a/src/sys/statfs.rs b/src/sys/statfs.rs
index 6d4fafe9..e7ffae5e 100644
--- a/src/sys/statfs.rs
+++ b/src/sys/statfs.rs
@@ -6,9 +6,7 @@ use libc;
pub fn statfs<P: ?Sized + NixPath>(path: &P, stat: &mut libc::statfs) -> Result<()> {
unsafe {
Errno::clear();
- let res = try!(
- path.with_nix_path(|path| libc::statfs(path.as_ptr(), stat))
- );
+ let res = path.with_nix_path(|path| libc::statfs(path.as_ptr(), stat))?;
Errno::result(res).map(drop)
}
diff --git a/src/sys/statvfs.rs b/src/sys/statvfs.rs
index 845ae0db..de69ae51 100644
--- a/src/sys/statvfs.rs
+++ b/src/sys/statvfs.rs
@@ -126,9 +126,9 @@ pub fn statvfs<P: ?Sized + NixPath>(path: &P) -> Result<Statvfs> {
unsafe {
Errno::clear();
let mut stat: Statvfs = mem::uninitialized();
- let res = try!(
- path.with_nix_path(|path| libc::statvfs(path.as_ptr(), &mut stat.0))
- );
+ let res = path.with_nix_path(|path|
+ libc::statvfs(path.as_ptr(), &mut stat.0)
+ )?;
Errno::result(res).map(|_| stat)
}
diff --git a/src/sys/termios.rs b/src/sys/termios.rs
index 8a99c1ab..d8815baa 100644
--- a/src/sys/termios.rs
+++ b/src/sys/termios.rs
@@ -1050,7 +1050,7 @@ pub fn tcgetattr(fd: RawFd) -> Result<Termios> {
let res = unsafe { libc::tcgetattr(fd, &mut termios) };
- try!(Errno::result(res));
+ Errno::result(res)?;
Ok(termios.into())
}
diff --git a/src/sys/time.rs b/src/sys/time.rs
index e300cfe7..9671f531 100644
--- a/src/sys/time.rs
+++ b/src/sys/time.rs
@@ -235,20 +235,20 @@ impl fmt::Display for TimeSpec {
let sec = abs.tv_sec();
- try!(write!(f, "{}", sign));
+ write!(f, "{}", sign)?;
if abs.tv_nsec() == 0 {
if abs.tv_sec() == 1 {
- try!(write!(f, "{} second", sec));
+ write!(f, "{} second", sec)?;
} else {
- try!(write!(f, "{} seconds", sec));
+ write!(f, "{} seconds", sec)?;
}
} else if abs.tv_nsec() % 1_000_000 == 0 {
- try!(write!(f, "{}.{:03} seconds", sec, abs.tv_nsec() / 1_000_000));
+ write!(f, "{}.{:03} seconds", sec, abs.tv_nsec() / 1_000_000)?;
} else if abs.tv_nsec() % 1_000 == 0 {
- try!(write!(f, "{}.{:06} seconds", sec, abs.tv_nsec() / 1_000));
+ write!(f, "{}.{:06} seconds", sec, abs.tv_nsec() / 1_000)?;
} else {
- try!(write!(f, "{}.{:09} seconds", sec, abs.tv_nsec()));
+ write!(f, "{}.{:09} seconds", sec, abs.tv_nsec())?;
}
Ok(())
@@ -449,18 +449,18 @@ impl fmt::Display for TimeVal {
let sec = abs.tv_sec();
- try!(write!(f, "{}", sign));
+ write!(f, "{}", sign)?;
if abs.tv_usec() == 0 {
if abs.tv_sec() == 1 {
- try!(write!(f, "{} second", sec));
+ write!(f, "{} second", sec)?;
} else {
- try!(write!(f, "{} seconds", sec));
+ write!(f, "{} seconds", sec)?;
}
} else if abs.tv_usec() % 1000 == 0 {
- try!(write!(f, "{}.{:03} seconds", sec, abs.tv_usec() / 1000));
+ write!(f, "{}.{:03} seconds", sec, abs.tv_usec() / 1000)?;
} else {
- try!(write!(f, "{}.{:06} seconds", sec, abs.tv_usec()));
+ write!(f, "{}.{:06} seconds", sec, abs.tv_usec())?;
}
Ok(())
diff --git a/src/sys/wait.rs b/src/sys/wait.rs
index 038354b1..3f99757d 100644
--- a/src/sys/wait.rs
+++ b/src/sys/wait.rs
@@ -181,7 +181,7 @@ impl WaitStatus {
Ok(if exited(status) {
WaitStatus::Exited(pid, exit_status(status))
} else if signaled(status) {
- WaitStatus::Signaled(pid, try!(term_signal(status)), dumped_core(status))
+ WaitStatus::Signaled(pid, term_signal(status)?, dumped_core(status))
} else if stopped(status) {
cfg_if! {
if #[cfg(any(target_os = "android", target_os = "linux"))] {
@@ -190,14 +190,15 @@ impl WaitStatus {
Ok(if syscall_stop(status) {
WaitStatus::PtraceSyscall(pid)
} else if status_additional == 0 {
- WaitStatus::Stopped(pid, try!(stop_signal(status)))
+ WaitStatus::Stopped(pid, stop_signal(status)?)
} else {
- WaitStatus::PtraceEvent(pid, try!(stop_signal(status)), stop_additional(status))
+ WaitStatus::PtraceEvent(pid, stop_signal(status)?,
+ stop_additional(status))
})
}
} else {
fn decode_stopped(pid: Pid, status: i32) -> Result<WaitStatus> {
- Ok(WaitStatus::Stopped(pid, try!(stop_signal(status))))
+ Ok(WaitStatus::Stopped(pid, stop_signal(status)?))
}
}
}
@@ -227,7 +228,7 @@ pub fn waitpid<P: Into<Option<Pid>>>(pid: P, options: Option<WaitPidFlag>) -> Re
)
};
- match try!(Errno::result(res)) {
+ match Errno::result(res)? {
0 => Ok(StillAlive),
res => WaitStatus::from_raw(Pid::from_raw(res), status),
}
diff --git a/src/unistd.rs b/src/unistd.rs
index 07f1e6fd..f2ad55b2 100644
--- a/src/unistd.rs
+++ b/src/unistd.rs
@@ -384,7 +384,7 @@ fn dup3_polyfill(oldfd: RawFd, newfd: RawFd, flags: OFlag) -> Result<RawFd> {
return Err(Error::Sys(Errno::EINVAL));
}
- let fd = try!(dup2(oldfd, newfd));
+ let fd = dup2(oldfd, newfd)?;
if flags.contains(OFlag::O_CLOEXEC) {
if let Err(e) = fcntl(fd, F_SETFD(FdFlag::FD_CLOEXEC)) {
@@ -403,9 +403,9 @@ fn dup3_polyfill(oldfd: RawFd, newfd: RawFd, flags: OFlag) -> Result<RawFd> {
/// pages for additional details on possible failure cases.
#[inline]
pub fn chdir<P: ?Sized + NixPath>(path: &P) -> Result<()> {
- let res = try!(path.with_nix_path(|cstr| {
+ let res = path.with_nix_path(|cstr| {
unsafe { libc::chdir(cstr.as_ptr()) }
- }));
+ })?;
Errno::result(res).map(drop)
}
@@ -456,9 +456,9 @@ pub fn fchdir(dirfd: RawFd) -> Result<()> {
/// ```
#[inline]
pub fn mkdir<P: ?Sized + NixPath>(path: &P, mode: Mode) -> Result<()> {
- let res = try!(path.with_nix_path(|cstr| {
+ let res = path.with_nix_path(|cstr| {
unsafe { libc::mkdir(cstr.as_ptr(), mode.bits() as mode_t) }
- }));
+ })?;
Errno::result(res).map(drop)
}
@@ -499,9 +499,9 @@ pub fn mkdir<P: ?Sized + NixPath>(path: &P, mode: Mode) -> Result<()> {
/// ```
#[inline]
pub fn mkfifo<P: ?Sized + NixPath>(path: &P, mode: Mode) -> Result<()> {
- let res = try!(path.with_nix_path(|cstr| {
+ let res = path.with_nix_path(|cstr| {
unsafe { libc::mkfifo(cstr.as_ptr(), mode.bits() as mode_t) }
- }));
+ })?;
Errno::result(res).map(drop)
}
@@ -576,10 +576,10 @@ fn chown_raw_ids(owner: Option<Uid>, group: Option<Gid>) -> (libc::uid_t, libc::
/// only if `Some` owner/group is provided.
#[inline]
pub fn chown<P: ?Sized + NixPath>(path: &P, owner: Option<Uid>, group: Option<Gid>) -> Result<()> {
- let res = try!(path.with_nix_path(|cstr| {
+ let res = path.with_nix_path(|cstr| {
let (uid, gid) = chown_raw_ids(owner, group);
unsafe { libc::chown(cstr.as_ptr(), uid, gid) }
- }));
+ })?;
Errno::result(res).map(drop)
}
@@ -977,7 +977,7 @@ pub fn pipe() -> Result<(RawFd, RawFd)> {
let res = libc::pipe(fds.as_mut_ptr());
- try!(Errno::result(res));
+ Errno::result(res)?;
Ok((fds[0], fds[1]))
}
@@ -1004,7 +1004,7 @@ pub fn pipe2(flags: OFlag) -> Result<(RawFd, RawFd)> {
let res = unsafe { libc::pipe2(fds.as_mut_ptr(), flags.bits()) };
- try!(Errno::result(res));
+ Errno::result(res)?;
Ok((fds[0], fds[1]))
}
@@ -1026,9 +1026,9 @@ pub fn pipe2(flags: OFlag) -> Result<(RawFd, RawFd)> {
let res = unsafe { libc::pipe(fds.as_mut_ptr()) };
- try!(Errno::result(res));
+ Errno::result(res)?;
- try!(pipe2_setflags(fds[0], fds[1], flags));
+ pipe2_setflags(fds[0], fds[1], flags)?;
Ok((fds[0], fds[1]))
}
@@ -1067,11 +1067,11 @@ fn pipe2_setflags(fd1: RawFd, fd2: RawFd, flags: OFlag) -> Result<()> {
/// See also
/// [truncate(2)](http://pubs.opengroup.org/onlinepubs/9699919799/functions/truncate.html)
pub fn truncate<P: ?Sized + NixPath>(path: &P, len: off_t) -> Result<()> {
- let res = try!(path.with_nix_path(|cstr| {
+ let res = path.with_nix_path(|cstr| {
unsafe {
libc::truncate(cstr.as_ptr(), len)
}
- }));
+ })?;
Errno::result(res).map(drop)
}
@@ -1105,19 +1105,19 @@ pub fn isatty(fd: RawFd) -> Result<bool> {
///
/// See also [unlink(2)](http://pubs.opengroup.org/onlinepubs/9699919799/functions/unlink.html)
pub fn unlink<P: ?Sized + NixPath>(path: &P) -> Result<()> {
- let res = try!(path.with_nix_path(|cstr| {
+ let res = path.with_nix_path(|cstr| {
unsafe {
libc::unlink(cstr.as_ptr())
}
- }));
+ })?;
Errno::result(res).map(drop)
}
#[inline]
pub fn chroot<P: ?Sized + NixPath>(path: &P) -> Result<()> {
- let res = try!(path.with_nix_path(|cstr| {
+ let res = path.with_nix_path(|cstr| {
unsafe { libc::chroot(cstr.as_ptr()) }
- }));
+ })?;
Errno::result(res).map(drop)
}
@@ -1553,9 +1553,9 @@ pub mod acct {
///
/// See also [acct(2)](https://linux.die.net/man/2/acct)
pub fn enable<P: ?Sized + NixPath>(filename: &P) -> Result<()> {
- let res = try!(filename.with_nix_path(|cstr| {
+ let res = filename.with_nix_path(|cstr| {
unsafe { libc::acct(cstr.as_ptr()) }
- }));
+ })?;
Errno::result(res).map(drop)
}
@@ -1594,13 +1594,13 @@ pub mod acct {
/// ```
#[inline]
pub fn mkstemp<P: ?Sized + NixPath>(template: &P) -> Result<(RawFd, PathBuf)> {
- let mut path = try!(template.with_nix_path(|path| {path.to_bytes_with_nul().to_owned()}));
+ let mut path = template.with_nix_path(|path| {path.to_bytes_with_nul().to_owned()})?;
let p = path.as_mut_ptr() as *mut _;
let fd = unsafe { libc::mkstemp(p) };
let last = path.pop(); // drop the trailing nul
debug_assert!(last == Some(b'\0'));
let pathname = OsString::from_vec(path);
- try!(Errno::result(fd));
+ Errno::result(fd)?;
Ok((fd, PathBuf::from(pathname)))
}
@@ -1761,12 +1761,12 @@ pub fn fpathconf(fd: RawFd, var: PathconfVar) -> Result<Option<c_long>> {
/// unsupported (for option variables)
/// - `Err(x)`: an error occurred
pub fn pathconf<P: ?Sized + NixPath>(path: &P, var: PathconfVar) -> Result<Option<c_long>> {
- let raw = try!(path.with_nix_path(|cstr| {
+ let raw = path.with_nix_path(|cstr| {
unsafe {
Errno::clear();
libc::pathconf(cstr.as_ptr(), var as c_int)
}
- }));
+ })?;
if raw == -1 {
if errno::errno() == 0 {
Ok(None)
@@ -2228,13 +2228,13 @@ mod pivot_root {
pub fn pivot_root<P1: ?Sized + NixPath, P2: ?Sized + NixPath>(
new_root: &P1, put_old: &P2) -> Result<()> {
- let res = try!(try!(new_root.with_nix_path(|new_root| {
+ let res = new_root.with_nix_path(|new_root| {
put_old.with_nix_path(|put_old| {
unsafe {
libc::syscall(libc::SYS_pivot_root, new_root.as_ptr(), put_old.as_ptr())
}
})
- })));
+ })??;
Errno::result(res).map(drop)
}