diff options
Diffstat (limited to 'src/fcntl.rs')
-rw-r--r-- | src/fcntl.rs | 16 |
1 files changed, 8 insertions, 8 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) } |