| 125 | #[cfg(feature = "fs")] |
| 126 | #[test] |
| 127 | fn 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] |