Skip to content

Commit

Permalink
fix error code grab in raw syscall
Browse files Browse the repository at this point in the history
  • Loading branch information
templexxx committed Nov 3, 2022
1 parent c979fed commit 2ce8ad6
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions omo/src/os/linux/file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ pub fn open(path: &str, flags: u64, mode: u64) -> Result<i64, EmulatorError> {
flags,
open_mode,
);
if fd == -1 {
if fd < 0 {
Err(EmulatorError::IOError(io::Error::last_os_error()))
} else {
Ok(fd)
Expand All @@ -19,7 +19,7 @@ pub fn open(path: &str, flags: u64, mode: u64) -> Result<i64, EmulatorError> {

pub fn read(fd: u64, buf: u64, size: u64) -> Result<i64, EmulatorError> {
let size = syscall_3(LinuxSysCalls::Read as u64, fd, buf, size);
if size == -1 {
if size < 0 {
Err(EmulatorError::IOError(io::Error::last_os_error()))
} else {
Ok(size)
Expand All @@ -28,7 +28,7 @@ pub fn read(fd: u64, buf: u64, size: u64) -> Result<i64, EmulatorError> {

pub fn write(fd: u64, data: u64, len: u64) -> Result<i64, EmulatorError> {
let size = syscall_3(LinuxSysCalls::Write as u64, fd, data, len);
if size == -1 {
if size < 0 {
Err(EmulatorError::IOError(io::Error::last_os_error()))
} else {
Ok(size)
Expand All @@ -37,7 +37,7 @@ pub fn write(fd: u64, data: u64, len: u64) -> Result<i64, EmulatorError> {

pub fn close(fd: u64) -> Result<i64, EmulatorError> {
let ret = syscall_1(LinuxSysCalls::Close as u64, fd);
if ret == -1 {
if ret < 0 {
Err(EmulatorError::IOError(io::Error::last_os_error()))
} else {
Ok(ret)
Expand All @@ -46,7 +46,7 @@ pub fn close(fd: u64) -> Result<i64, EmulatorError> {

pub fn lseek(fd: u64, offset: u64, whence: u64) -> Result<i64, EmulatorError> {
let off = syscall_3(LinuxSysCalls::Lseek as u64, fd, offset, whence);
if off == -1 {
if off < 0 {
Err(EmulatorError::IOError(io::Error::last_os_error()))
} else {
Ok(off)
Expand All @@ -55,7 +55,7 @@ pub fn lseek(fd: u64, offset: u64, whence: u64) -> Result<i64, EmulatorError> {

pub fn fcntl(fd: u64, cmd: u64, arg: u64) -> Result<i64, EmulatorError> {
let ret = syscall_3(LinuxSysCalls::Fcntl as u64, fd, cmd, arg);
if ret == -1 {
if ret < 0 {
Err(EmulatorError::IOError(io::Error::last_os_error()))
} else {
Ok(ret)
Expand All @@ -69,7 +69,7 @@ pub fn readlink(path: &str, buf: u64, buf_size: u64) -> Result<i64, EmulatorErro
buf,
buf_size,
);
if ret == -1 {
if ret < 0 {
Err(EmulatorError::IOError(io::Error::last_os_error()))
} else {
Ok(ret)
Expand All @@ -78,7 +78,7 @@ pub fn readlink(path: &str, buf: u64, buf_size: u64) -> Result<i64, EmulatorErro

pub fn stat(path: &str, stat_buf: u64) -> Result<i64, EmulatorError> {
let ret = syscall_2(LinuxSysCalls::Stat as u64, path.as_ptr() as u64, stat_buf);
if ret == -1 {
if ret < 0 {
Err(EmulatorError::IOError(io::Error::last_os_error()))
} else {
Ok(ret)
Expand All @@ -87,7 +87,7 @@ pub fn stat(path: &str, stat_buf: u64) -> Result<i64, EmulatorError> {

pub fn fstat(fd: u64, stat_buf: u64) -> Result<i64, EmulatorError> {
let ret = syscall_2(LinuxSysCalls::Fstat as u64, fd, stat_buf);
if ret == -1 {
if ret < 0 {
Err(EmulatorError::IOError(io::Error::last_os_error()))
} else {
Ok(ret)
Expand All @@ -96,7 +96,7 @@ pub fn fstat(fd: u64, stat_buf: u64) -> Result<i64, EmulatorError> {

pub fn lstat(path: &str, stat_buf: u64) -> Result<i64, EmulatorError> {
let ret = syscall_2(LinuxSysCalls::Lstat as u64, path.as_ptr() as u64, stat_buf);
if ret == -1 {
if ret < 0 {
Err(EmulatorError::IOError(io::Error::last_os_error()))
} else {
Ok(ret)
Expand All @@ -111,7 +111,7 @@ pub fn fstatat64(dir_fd: u64, path: &str, stat_buf: u64, flags: u64) -> Result<i
stat_buf,
flags,
);
if ret == -1 {
if ret < 0 {
Err(EmulatorError::IOError(io::Error::last_os_error()))
} else {
Ok(ret)
Expand All @@ -120,7 +120,7 @@ pub fn fstatat64(dir_fd: u64, path: &str, stat_buf: u64, flags: u64) -> Result<i

pub fn ioctl(fd: u64, cmd: u64, arg: u64) -> Result<i64, EmulatorError> {
let ret = syscall_3(LinuxSysCalls::Ioctl as u64, fd, cmd, arg);
if ret == -1 {
if ret < 0 {
Err(EmulatorError::IOError(io::Error::last_os_error()))
} else {
Ok(ret)
Expand Down

0 comments on commit 2ce8ad6

Please sign in to comment.