| 306 | #[cfg(not(target_os = "cygwin"))] // no preadv/pwritev |
| 307 | #[test] |
| 308 | fn test_p_offsets() { |
| 309 | use rustix::fs::{openat, Mode, OFlags, CWD}; |
| 310 | use rustix::io::{pread, preadv, pwrite, pwritev}; |
| 311 | #[cfg(all(linux_raw_dep, not(target_os = "android")))] |
| 312 | use rustix::io::{preadv2, pwritev2, ReadWriteFlags}; |
| 313 | |
| 314 | let mut buf = [0_u8; 5]; |
| 315 | |
| 316 | let tmp = tempfile::tempdir().unwrap(); |
| 317 | let f = openat( |
| 318 | CWD, |
| 319 | tmp.path().join("file"), |
| 320 | OFlags::RDWR | OFlags::CREATE | OFlags::TRUNC, |
| 321 | Mode::RUSR | Mode::WUSR, |
| 322 | ) |
| 323 | .unwrap(); |
| 324 | |
| 325 | // Test that offset 0 works. |
| 326 | match pread(&f, &mut buf, 0_u64) { |
| 327 | Err(rustix::io::Errno::OPNOTSUPP | rustix::io::Errno::NOSYS) => {} |
| 328 | Ok(_) => {} |
| 329 | Err(e) => panic!("pread failed with an unexpected error: {:?}", e), |
| 330 | } |
| 331 | match pwrite(&f, &buf, 0_u64) { |
| 332 | Err(rustix::io::Errno::OPNOTSUPP | rustix::io::Errno::NOSYS) => {} |
| 333 | Ok(_) => {} |
| 334 | Err(e) => panic!("pwrite failed with an unexpected error: {:?}", e), |
| 335 | } |
| 336 | match preadv(&f, &mut [IoSliceMut::new(&mut buf)], 0_u64) { |
| 337 | Err(rustix::io::Errno::OPNOTSUPP | rustix::io::Errno::NOSYS) => {} |
| 338 | Ok(_) => {} |
| 339 | Err(e) => panic!("preadv failed with an unexpected error: {:?}", e), |
| 340 | } |
| 341 | match pwritev(&f, &[IoSlice::new(&buf)], 0_u64) { |
| 342 | Err(rustix::io::Errno::OPNOTSUPP | rustix::io::Errno::NOSYS) => {} |
| 343 | Ok(_) => {} |
| 344 | Err(e) => panic!("pwritev failed with an unexpected error: {:?}", e), |
| 345 | } |
| 346 | #[cfg(all(linux_raw_dep, not(target_os = "android")))] |
| 347 | { |
| 348 | match preadv2( |
| 349 | &f, |
| 350 | &mut [IoSliceMut::new(&mut buf)], |
| 351 | 0_u64, |
| 352 | ReadWriteFlags::empty(), |
| 353 | ) { |
| 354 | Err(rustix::io::Errno::OPNOTSUPP | rustix::io::Errno::NOSYS) => {} |
| 355 | Ok(_) => {} |
| 356 | Err(e) => panic!("preadv2 failed with an unexpected error: {:?}", e), |
| 357 | } |
| 358 | match pwritev2(&f, &[IoSlice::new(&buf)], 0_u64, ReadWriteFlags::empty()) { |
| 359 | Err(rustix::io::Errno::OPNOTSUPP | rustix::io::Errno::NOSYS) => {} |
| 360 | Ok(_) => {} |
| 361 | Err(e) => panic!("pwritev2 failed with an unexpected error: {:?}", e), |
| 362 | } |
| 363 | } |
| 364 | |
| 365 | // Test that negative offsets fail with `INVAL`. |