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

Function test_readwrite

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

Source from the content-addressed store, hash-verified

125#[cfg(feature = "fs")]
126#[test]
127fn test_readwrite() {
128 use rustix::fs::{openat, seek, Mode, OFlags, SeekFrom, CWD};
129 use rustix::io::{read, write};
130
131 let tmp = tempfile::tempdir().unwrap();
132 let dir = openat(CWD, tmp.path(), OFlags::RDONLY, Mode::empty()).unwrap();
133 let file = openat(
134 &dir,
135 "file",
136 OFlags::RDWR | OFlags::CREATE | OFlags::TRUNC,
137 Mode::RUSR | Mode::WUSR,
138 )
139 .unwrap();
140
141 write(&file, b"hello").unwrap();
142 write(&file, b"world").unwrap();
143 seek(&file, SeekFrom::Start(0)).unwrap();
144 let mut buf = [0_u8; 5];
145 read(&file, &mut buf).unwrap();
146 assert_eq!(&buf, b"hello");
147 read(&file, &mut buf).unwrap();
148 assert_eq!(&buf, b"world");
149}
150
151#[cfg(feature = "fs")]
152#[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