unwrap_or(-1)

This commit is contained in:
Paul Sajna
2018-03-05 14:57:04 -08:00
parent 151d873aba
commit 44e6c334e6
+17 -17
View File
@@ -4,17 +4,17 @@ use c_str;
use types::*;
pub fn brk(addr: *const c_void) -> {
syscall::brk(addr as usize)? as c_int
syscall::brk(addr as usize).unwrap_or(-1) as c_int
pub fn chdir(path: *const c_char) -> c_int {
let path = unsafe { c_str(path) };
syscall::chdir(path)? as c_int
syscall::chdir(path).unwrap_or(-1) as c_int
}
pub fn chown(path: *const c_char, owner: uid_t, group: gid_t) -> c_int {
let fd = syscall::open(cstr_to_slice(path));
syscall::fchown(fd as usize, owner as usize, group as usize)? as c_int
syscall::fchown(fd as usize, owner as usize, group as usize).unwrap_or(-1) as c_int
pub fn close(fd: c_int) -> c_int {
syscall::close(fd as usize);
@@ -22,11 +22,11 @@ pub fn close(fd: c_int) -> c_int {
}
pub fn dup(fd: c_int) -> c_int {
syscall::dup(fd as usize, &[])? as c_int
syscall::dup(fd as usize, &[]).unwrap_or(-1) as c_int
}
pub fn dup2(fd1: c_int, fd2) -> c_int {
syscall::dup2(fd1 as usize, fd2 as usize, &[])? as c_int
syscall::dup2(fd1 as usize, fd2 as usize, &[]).unwrap_or(-1) as c_int
}
pub fn exit(status: c_int) -> ! {
@@ -35,24 +35,24 @@ pub fn exit(status: c_int) -> ! {
}
pub fn fchown(fd: c_int, owner: uid_t, group: gid_t) -> c_int {
syscall::fchown(owner as usize, group as usize)? as c_int
syscall::fchown(owner as usize, group as usize).unwrap_or(-1) as c_int
}
pub fn fchdir(fd: c_int) -> c_int {
let result = fpath(fd as usize, &[]);
if result.is_ok() {
syscall::chdir(path)? as c_int
syscall::chdir(path).unwrap_or(-1) as c_int
} else {
-1
}
}
pub fn fsync(fd: c_int) -> c_int {
syscall::fsync(fd as usize)? as c_int
syscall::fsync(fd as usize).unwrap_or(-1) as c_int
}
pub fn ftruncate(fd: c_int, len: off_t) -> {
syscall::ftruncate(fd as usize, len as usize)? as c_int
syscall::ftruncate(fd as usize, len as usize).unwrap_or(-1) as c_int
}
pub fn getcwd(buf: *mut c_char, size: size_t) -> {
@@ -65,37 +65,37 @@ pub fn getcwd(buf: *mut c_char, size: size_t) -> {
}
pub fn getegid() -> gid_t {
syscall::getegid()? as gid_t
syscall::getegid().unwrap_or(-1) as gid_t
}
pub fn geteuid() -> uid_t {
syscall::geteuid()? as uid_t
syscall::geteuid().unwrap_or(-1) as uid_t
}
pub fn getgid() -> gid_t {
syscall::getgid()? as gid_t
syscall::getgid().unwrap_or(-1) as gid_t
}
pub fn getpgid(pid: pid_t) -> pid_t {
syscall::getpgid(pid as usize)? as pid_t
syscall::getpgid(pid as usize).unwrap_or(-1) as pid_t
}
pub fn getpid() -> pid_t {
syscall::getpid()? as pid_t
syscall::getpid().unwrap_or(-1) as pid_t
}
pub fn getppid() -> pid_t {
syscall::getppid()? as pid_t
syscall::getppid().unwrap_or(-1) as pid_t
}
pub fn getuid() -> uid_t {
syscall::getuid()? as pid_t
syscall::getuid().unwrap_or(-1) as pid_t
}
pub fn link(path1: const c_char, path2: const c_char) -> c_int {
let path1 = unsafe { c_str(path1) };
let path2 = unsafe { c_str(path2) };
syscall::link(path1, path2)? as c_int
syscall::link(path1, path2).unwrap_or(-1) as c_int
}
pub fn open(path: *const c_char, oflag: c_int, mode: mode_t) -> c_int {