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

Function test_readwrite_p

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

Source from the content-addressed store, hash-verified

47#[cfg(feature = "fs")]
48#[test]
49fn test_readwrite_p() {
50 use rustix::fs::{openat, Mode, OFlags, CWD};
51 use rustix::io::{pread, pwrite};
52
53 let tmp = tempfile::tempdir().unwrap();
54 let dir = openat(CWD, tmp.path(), OFlags::RDONLY, Mode::empty()).unwrap();
55 let file = openat(
56 &dir,
57 "file",
58 OFlags::RDWR | OFlags::CREATE | OFlags::TRUNC,
59 Mode::RUSR | Mode::WUSR,
60 )
61 .unwrap();
62
63 pwrite(&file, b"hello", 200).unwrap();
64 pwrite(&file, b"world", 300).unwrap();
65 let mut buf = [0_u8; 5];
66 pread(&file, &mut buf, 200).unwrap();
67 assert_eq!(&buf, b"hello");
68 pread(&file, &mut buf, 300).unwrap();
69 assert_eq!(&buf, b"world");
70}
71
72#[cfg(feature = "fs")]
73#[test]

Callers

nothing calls this directly

Calls 4

openatFunction · 0.50
pwriteFunction · 0.50
preadFunction · 0.50
pathMethod · 0.45

Tested by

no test coverage detected