• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #[cfg(not(any(target_os = "redox", target_os = "wasi")))]
2 #[test]
test_futimens()3 fn test_futimens() {
4     use rustix::fs::{cwd, fstat, futimens, openat, Mode, OFlags, Timespec, Timestamps};
5 
6     let tmp = tempfile::tempdir().unwrap();
7     let dir = openat(cwd(), tmp.path(), OFlags::RDONLY, Mode::empty()).unwrap();
8 
9     let foo = openat(
10         &dir,
11         "foo",
12         OFlags::CREATE | OFlags::WRONLY | OFlags::CLOEXEC,
13         Mode::empty(),
14     )
15     .unwrap();
16 
17     let times = Timestamps {
18         last_access: Timespec {
19             tv_sec: 44000,
20             tv_nsec: 45000,
21         },
22         last_modification: Timespec {
23             tv_sec: 46000,
24             tv_nsec: 47000,
25         },
26     };
27     futimens(&foo, &times).unwrap();
28 
29     let after = fstat(&foo).unwrap();
30 
31     assert_eq!(times.last_modification.tv_sec as u64, after.st_mtime as u64);
32     #[cfg(not(target_os = "netbsd"))]
33     assert_eq!(
34         times.last_modification.tv_nsec as u64,
35         after.st_mtime_nsec as u64
36     );
37     #[cfg(target_os = "netbsd")]
38     assert_eq!(
39         times.last_modification.tv_nsec as u64,
40         after.st_mtimensec as u64
41     );
42 }
43