Skip to content

Commit

Permalink
improve readability of readv/writev
Browse files Browse the repository at this point in the history
  • Loading branch information
stlankes committed May 22, 2024
1 parent c937bfe commit bee63bd
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions src/syscalls/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -456,10 +456,10 @@ pub unsafe extern "C" fn sys_readv(fd: i32, iov: *const iovec, iovcnt: i32) -> i
}

let mut count: isize = 0;
let slice = unsafe { core::slice::from_raw_parts(iov, iovcnt.try_into().unwrap()) };
let iovec_buffers = unsafe { core::slice::from_raw_parts(iov, iovcnt.try_into().unwrap()) };

for i in slice {
let buf = unsafe { core::slice::from_raw_parts_mut(i.iov_base, i.iov_len) };
for iovec_buf in iovec_buffers {
let buf = unsafe { core::slice::from_raw_parts_mut(iovec_buf.iov_base, iovec_buf.iov_len) };

let len = crate::fd::read(fd, buf).map_or_else(
|e| -num::ToPrimitive::to_isize(&e).unwrap(),
Expand All @@ -472,7 +472,7 @@ pub unsafe extern "C" fn sys_readv(fd: i32, iov: *const iovec, iovcnt: i32) -> i

count += len;

if len < i.iov_len.try_into().unwrap() {
if len < iovec_buf.iov_len.try_into().unwrap() {
return count;
}
}
Expand Down Expand Up @@ -517,10 +517,10 @@ pub unsafe extern "C" fn sys_writev(fd: FileDescriptor, iov: *const iovec, iovcn
}

let mut count: isize = 0;
let slice = unsafe { core::slice::from_raw_parts(iov, iovcnt.try_into().unwrap()) };
let iovec_buffers = unsafe { core::slice::from_raw_parts(iov, iovcnt.try_into().unwrap()) };

for i in slice {
let buf = unsafe { core::slice::from_raw_parts(i.iov_base, i.iov_len) };
for iovec_buf in iovec_buffers {
let buf = unsafe { core::slice::from_raw_parts(iovec_buf.iov_base, iovec_buf.iov_len) };

let len = crate::fd::write(fd, buf).map_or_else(
|e| -num::ToPrimitive::to_isize(&e).unwrap(),
Expand All @@ -533,7 +533,7 @@ pub unsafe extern "C" fn sys_writev(fd: FileDescriptor, iov: *const iovec, iovcn

count += len;

if len < i.iov_len.try_into().unwrap() {
if len < iovec_buf.iov_len.try_into().unwrap() {
return count;
}
}
Expand Down

0 comments on commit bee63bd

Please sign in to comment.