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

Function test_readwrite_uninit

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

Source from the content-addressed store, hash-verified

151#[cfg(feature = "fs")]
152#[test]
153fn test_readwrite_uninit() {
154 use core::mem::MaybeUninit;
155 use rustix::fs::{openat, seek, Mode, OFlags, SeekFrom, CWD};
156 use rustix::io::{read, write};
157
158 let tmp = tempfile::tempdir().unwrap();
159 let dir = openat(CWD, tmp.path(), OFlags::RDONLY, Mode::empty()).unwrap();
160 let file = openat(
161 &dir,
162 "file",
163 OFlags::RDWR | OFlags::CREATE | OFlags::TRUNC,
164 Mode::RUSR | Mode::WUSR,
165 )
166 .unwrap();
167
168 write(&file, b"hello").unwrap();
169 write(&file, b"world").unwrap();
170 seek(&file, SeekFrom::Start(0)).unwrap();
171 let mut buf = [MaybeUninit::uninit(); 5];
172 let (init, _) = read(&file, &mut buf).unwrap();
173 assert_eq!(&init, b"hello");
174 let (init, _) = read(&file, &mut buf).unwrap();
175 assert_eq!(&init, b"world");
176}
177
178#[cfg(all(target_os = "linux", target_env = "gnu"))]
179#[test]

Callers

nothing calls this directly

Calls 5

openatFunction · 0.50
writeFunction · 0.50
seekFunction · 0.50
readFunction · 0.50
pathMethod · 0.45

Tested by

no test coverage detected