Skip to content

Commit

Permalink
Refactor: Use cfg! instead of #[cfg]
Browse files Browse the repository at this point in the history
Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
  • Loading branch information
NobodyXu committed Apr 29, 2024
1 parent 804310f commit 60cac97
Showing 1 changed file with 19 additions and 20 deletions.
39 changes: 19 additions & 20 deletions src/unix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -414,26 +414,25 @@ mod linux {
let iovcnt: c_int = 1;
let offset: off_t = -1;

#[cfg(all(target_arch = "x86_64", target_pointer_width = "64"))]
let res = unsafe { syscall(SYS_preadv2, fd, iov, iovcnt, offset, 0 as off_t, RWF_NOWAIT) };

#[cfg(all(target_arch = "x86_64", target_pointer_width = "32"))]
let res = unsafe { syscall(SYS_preadv2, fd, iov, iovcnt, offset, RWF_NOWAIT) };

#[cfg(not(target_arch = "x86_64"))]
let res = unsafe {
syscall(
SYS_preadv2,
fd,
iov,
iovcnt,
offset as libc::c_long,
((offset as u64) >> 32) as libc::c_long,
RWF_NOWAIT,
)
};

res.try_into().unwrap()
if cfg!(all(target_arch = "x86_64", target_pointer_width = "64")) {
unsafe { syscall(SYS_preadv2, fd, iov, iovcnt, offset, 0 as off_t, RWF_NOWAIT) }
} else if cfg!(all(target_arch = "x86_64", target_pointer_width = "32")) {
unsafe { syscall(SYS_preadv2, fd, iov, iovcnt, offset, RWF_NOWAIT) }
} else {
unsafe {
syscall(
SYS_preadv2,
fd,
iov,
iovcnt,
offset as libc::c_long,
((offset as u64) >> 32) as libc::c_long,
RWF_NOWAIT,
)
}
}
.try_into()
.unwrap()
}

pub fn non_blocking_read(fd: c_int, buf: &mut [u8]) -> io::Result<usize> {
Expand Down

0 comments on commit 60cac97

Please sign in to comment.