Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for UTIME_NOW and UTIME_OMIT to TimeSpec #1103

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ exclude = [
]

[dependencies]
libc = { version = "0.2.60", features = [ "extra_traits" ] }
libc = { git = "https://github.com/rust-lang/libc", features = [ "extra_traits" ] }
bitflags = "1.0"
cfg-if = "0.1.2"
void = "1.0.2"
Expand Down
52 changes: 52 additions & 0 deletions src/sys/time.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,35 @@ impl TimeValLike for TimeSpec {
}
}

#[cfg(any(
target_env = "uclibc",
target_env = "wasi",
target_os = "android",
target_os = "emscripten",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can add Dragonfly. Besides that, what targets are missing from this list? Does it not cover everything?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Opened another PR: rust-lang/libc#1487

target_os = "freebsd",
target_os = "fuchsia",
target_os = "haiku",
target_os = "illumos",
target_os = "ios",
target_os = "linux",
target_os = "macos",
target_os = "netbsd",
target_os = "openbsd",
target_os = "solaris",
target_os = "wasi",
))]
impl TimeSpec {
/// Makes a new `TimeSpec` with the special UTIME_NOW constant
pub fn utime_now() -> TimeSpec {
TimeSpec(timespec { tv_sec: 0, tv_nsec: libc::UTIME_NOW })
}

/// Makes a new `TimeSpec` with the special UTIME_OMIT constant
pub fn utime_omit() -> TimeSpec {
TimeSpec(timespec { tv_sec: 0, tv_nsec: libc::UTIME_OMIT })
}
}

impl TimeSpec {
fn nanos_mod_sec(&self) -> c_long {
if self.tv_sec() < 0 && self.tv_nsec() > 0 {
Expand Down Expand Up @@ -485,6 +514,29 @@ mod test {
assert_eq!(a, -b);
}

#[test]
#[cfg(any(
target_env = "uclibc",
target_env = "wasi",
target_os = "android",
target_os = "emscripten",
target_os = "freebsd",
target_os = "fuchsia",
target_os = "haiku",
target_os = "illumos",
target_os = "ios",
target_os = "linux",
target_os = "macos",
target_os = "netbsd",
target_os = "openbsd",
target_os = "solaris",
target_os = "wasi",
))]
pub fn test_timespec_constants() {
assert_eq!(TimeSpec::utime_now().tv_nsec(), libc::UTIME_NOW);
assert_eq!(TimeSpec::utime_omit().tv_nsec(), libc::UTIME_OMIT);
}

#[test]
pub fn test_timespec_ord() {
assert!(TimeSpec::seconds(1) == TimeSpec::nanoseconds(1_000_000_000));
Expand Down