diff options
author | Justus Winter <justus@sequoia-pgp.org> | 2019-03-21 15:24:41 +0100 |
---|---|---|
committer | Justus Winter <justus@sequoia-pgp.org> | 2019-03-21 15:24:41 +0100 |
commit | c0a170a65cdc587c76787c3fc988be77bf4f6675 (patch) | |
tree | 5f0c69b1526c0526882758579e19de0a80fbd0b4 /openpgp-ffi/tests/c-tests.rs | |
parent | e4998146b6e68360f81c9d44d5e57008613b5f73 (diff) |
openpgp-ffi: Use crate for futimes fiddling.
- The previous solution of using libc::futimes turned out to be not
portable because different platforms have differently sized
timestamps. Use a crate for that instead.
- Also, bring ffi's c-tests up-to-speed.
- Fixes #225.
Diffstat (limited to 'openpgp-ffi/tests/c-tests.rs')
-rw-r--r-- | openpgp-ffi/tests/c-tests.rs | 26 |
1 files changed, 5 insertions, 21 deletions
diff --git a/openpgp-ffi/tests/c-tests.rs b/openpgp-ffi/tests/c-tests.rs index 0ec26500..37c00231 100644 --- a/openpgp-ffi/tests/c-tests.rs +++ b/openpgp-ffi/tests/c-tests.rs @@ -1,4 +1,4 @@ -extern crate libc; +extern crate filetime; extern crate nettle; use std::cmp::min; @@ -6,11 +6,9 @@ use std::env::{self, var_os}; use std::ffi::OsStr; use std::fs; use std::io::{self, BufRead, Write}; -use std::os::unix::io::AsRawFd; use std::path::{Path, PathBuf}; use std::process::Command; use std::str::FromStr; -use std::time; use std::mem::replace; /// Hooks into Rust's test system to extract, compile and run c tests. @@ -213,27 +211,13 @@ fn build(include_dirs: &[PathBuf], ldpath: &Path, target_dir: &Path, for line in lines { writeln!(f, "{}", line)? } + drop(f); // Change the modification time of the c source to match the // rust source. - let mtime = meta_rs.modified().unwrap() - .duration_since(time::UNIX_EPOCH).unwrap(); - let timevals = [ - // Access time. - libc::timeval { - tv_sec: mtime.as_secs() as i64, - tv_usec: mtime.subsec_nanos() as i64 / 1000, - }, - // Modification time. - libc::timeval { - tv_sec: mtime.as_secs() as i64, - tv_usec: mtime.subsec_nanos() as i64 / 1000, - }, - ]; - let rc = unsafe { - libc::futimes(f.as_raw_fd(), timevals.as_ptr()) - }; - assert_eq!(rc, 0); + use filetime::FileTime; + let mtime = FileTime::from_last_modification_time(&meta_rs); + filetime::set_file_times(target_c, mtime.clone(), mtime).unwrap(); } let includes = |