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

Function test_readwrite_p_uninit

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

Source from the content-addressed store, hash-verified

72#[cfg(feature = "fs")]
73#[test]
74fn test_readwrite_p_uninit() {
75 use core::mem::MaybeUninit;
76 use rustix::fs::{openat, Mode, OFlags, CWD};
77 use rustix::io::{pread, pwrite};
78
79 let tmp = tempfile::tempdir().unwrap();
80 let dir = openat(CWD, tmp.path(), OFlags::RDONLY, Mode::empty()).unwrap();
81 let file = openat(
82 &dir,
83 "file",
84 OFlags::RDWR | OFlags::CREATE | OFlags::TRUNC,
85 Mode::RUSR | Mode::WUSR,
86 )
87 .unwrap();
88
89 pwrite(&file, b"hello", 200).unwrap();
90 pwrite(&file, b"world", 300).unwrap();
91 let mut buf = [MaybeUninit::uninit(); 5];
92 let (init, _) = pread(&file, &mut buf, 200).unwrap();
93 assert_eq!(&init, b"hello");
94 let (init, _) = pread(&file, &mut buf, 300).unwrap();
95 assert_eq!(&init, b"world");
96}
97
98#[cfg(not(target_os = "espidf"))] // no readv/writev
99#[cfg(feature = "fs")]

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