MCPcopy Create free account
hub / github.com/bytecodealliance/rustix / test_readwrite_pv

Function test_readwrite_pv

tests/io/read_write.rs:10–45  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

8#[cfg(not(target_os = "cygwin"))] // no preadv/pwritev
9#[test]
10fn test_readwrite_pv() {
11 use rustix::fs::{openat, Mode, OFlags, CWD};
12 use rustix::io::{preadv, pwritev};
13
14 let tmp = tempfile::tempdir().unwrap();
15 let dir = openat(CWD, tmp.path(), OFlags::RDONLY, Mode::empty()).unwrap();
16 let file = openat(
17 &dir,
18 "file",
19 OFlags::RDWR | OFlags::CREATE | OFlags::TRUNC,
20 Mode::RUSR | Mode::WUSR,
21 )
22 .unwrap();
23
24 // For most targets, just call `pwritev`.
25 #[cfg(not(apple))]
26 {
27 pwritev(&file, &[IoSlice::new(b"hello")], 200).unwrap();
28 }
29 // macOS only has `pwritev` in newer versions; allow it to fail with
30 // `Errno::NOSYS`.
31 #[cfg(apple)]
32 {
33 match pwritev(&file, &[IoSlice::new(b"hello")], 200) {
34 Ok(_) => (),
35 Err(rustix::io::Errno::NOSYS) => return,
36 Err(err) => panic!("{:?}", err),
37 }
38 }
39 pwritev(&file, &[IoSlice::new(b"world")], 300).unwrap();
40 let mut buf = [0_u8; 5];
41 preadv(&file, &mut [IoSliceMut::new(&mut buf)], 200).unwrap();
42 assert_eq!(&buf, b"hello");
43 preadv(&file, &mut [IoSliceMut::new(&mut buf)], 300).unwrap();
44 assert_eq!(&buf, b"world");
45}
46
47#[cfg(feature = "fs")]
48#[test]

Callers

nothing calls this directly

Calls 4

openatFunction · 0.50
pwritevFunction · 0.50
preadvFunction · 0.50
pathMethod · 0.45

Tested by

no test coverage detected