diff --git a/omo/src/os/linux/file.rs b/omo/src/os/linux/file.rs index d771c28..a76e89f 100644 --- a/omo/src/os/linux/file.rs +++ b/omo/src/os/linux/file.rs @@ -10,7 +10,7 @@ pub fn open(path: &str, flags: u64, mode: u64) -> Result { flags, open_mode, ); - if fd == -1 { + if fd < 0 { Err(EmulatorError::IOError(io::Error::last_os_error())) } else { Ok(fd) @@ -19,7 +19,7 @@ pub fn open(path: &str, flags: u64, mode: u64) -> Result { pub fn read(fd: u64, buf: u64, size: u64) -> Result { 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) @@ -28,7 +28,7 @@ pub fn read(fd: u64, buf: u64, size: u64) -> Result { pub fn write(fd: u64, data: u64, len: u64) -> Result { 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) @@ -37,7 +37,7 @@ pub fn write(fd: u64, data: u64, len: u64) -> Result { pub fn close(fd: u64) -> Result { 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) @@ -46,7 +46,7 @@ pub fn close(fd: u64) -> Result { pub fn lseek(fd: u64, offset: u64, whence: u64) -> Result { 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) @@ -55,7 +55,7 @@ pub fn lseek(fd: u64, offset: u64, whence: u64) -> Result { pub fn fcntl(fd: u64, cmd: u64, arg: u64) -> Result { 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) @@ -69,7 +69,7 @@ pub fn readlink(path: &str, buf: u64, buf_size: u64) -> Result Result Result { 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) @@ -87,7 +87,7 @@ pub fn stat(path: &str, stat_buf: u64) -> Result { pub fn fstat(fd: u64, stat_buf: u64) -> Result { 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) @@ -96,7 +96,7 @@ pub fn fstat(fd: u64, stat_buf: u64) -> Result { pub fn lstat(path: &str, stat_buf: u64) -> Result { 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) @@ -111,7 +111,7 @@ pub fn fstatat64(dir_fd: u64, path: &str, stat_buf: u64, flags: u64) -> Result Result Result { 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)