Skip to content

Commit a896ec5

Browse files
authored
Fix the preadv2 syscall on old 32-bit glibc versions. (#699)
Fix a typo, to use the correct syscall for `preadv2` on 32-bit platforms on old versions of GLIBC, so that the `flags` parameter may be used.
1 parent d7fd5ab commit a896ec5

File tree

2 files changed

+42
-1
lines changed

2 files changed

+42
-1
lines changed

src/backend/libc/c.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,7 @@ mod readwrite_pv64v2 {
339339
#[cfg(target_pointer_width = "32")]
340340
{
341341
libc::syscall(
342-
libc::SYS_preadv,
342+
libc::SYS_preadv2,
343343
fd,
344344
iov,
345345
iovcnt,

tests/io/read_write.rs

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,3 +198,44 @@ fn test_pwritev2() {
198198
.unwrap();
199199
assert_eq!(&buf, b"world");
200200
}
201+
202+
#[cfg(linux_kernel)]
203+
#[cfg(all(feature = "net", feature = "pipe"))]
204+
#[test]
205+
fn test_preadv2_nowait() {
206+
use rustix::io::{preadv2, ReadWriteFlags};
207+
use rustix::net::{socketpair, AddressFamily, SocketFlags, SocketType};
208+
use rustix::pipe::pipe;
209+
210+
let mut buf = [0_u8; 5];
211+
212+
let (reader, _writer) = socketpair(
213+
AddressFamily::UNIX,
214+
SocketType::STREAM,
215+
SocketFlags::CLOEXEC,
216+
None,
217+
)
218+
.unwrap();
219+
match preadv2(
220+
&reader,
221+
&mut [IoSliceMut::new(&mut buf)],
222+
u64::MAX,
223+
ReadWriteFlags::NOWAIT,
224+
) {
225+
Err(rustix::io::Errno::OPNOTSUPP | rustix::io::Errno::NOSYS) => {}
226+
Ok(_) => panic!("preadv2 unexpectedly succeeded"),
227+
Err(e) => panic!("preadv2 failed with an unexpected error: {:?}", e),
228+
}
229+
230+
let (reader, _writer) = pipe().unwrap();
231+
match preadv2(
232+
&reader,
233+
&mut [IoSliceMut::new(&mut buf)],
234+
u64::MAX,
235+
ReadWriteFlags::NOWAIT,
236+
) {
237+
Err(rustix::io::Errno::OPNOTSUPP | rustix::io::Errno::NOSYS) => {}
238+
Ok(_) => panic!("preadv2 unexpectedly succeeded"),
239+
Err(e) => panic!("preadv2 failed with an unexpected error: {:?}", e),
240+
}
241+
}

0 commit comments

Comments
 (0)