summaryrefslogtreecommitdiffstats
path: root/vendor/rustix/src/time/clock.rs
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/rustix/src/time/clock.rs')
-rw-r--r--vendor/rustix/src/time/clock.rs56
1 files changed, 56 insertions, 0 deletions
diff --git a/vendor/rustix/src/time/clock.rs b/vendor/rustix/src/time/clock.rs
new file mode 100644
index 000000000..32d888749
--- /dev/null
+++ b/vendor/rustix/src/time/clock.rs
@@ -0,0 +1,56 @@
+use crate::{imp, io};
+
+pub use imp::time::types::{Nsecs, Secs, Timespec};
+
+/// `clockid_t`
+#[cfg(any(not(target_os = "wasi")))]
+pub use imp::time::types::{ClockId, DynamicClockId};
+
+/// `clock_getres(id)`—Returns the resolution of a clock.
+///
+/// # References
+/// - [POSIX]
+/// - [Linux]
+///
+/// [POSIX]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/clock_getres.html
+/// [Linux]: https://man7.org/linux/man-pages/man2/clock_getres.2.html
+#[cfg(any(not(any(target_os = "redox", target_os = "wasi"))))]
+#[inline]
+#[must_use]
+pub fn clock_getres(id: ClockId) -> Timespec {
+ imp::time::syscalls::clock_getres(id)
+}
+
+/// `clock_gettime(id)`—Returns the current value of a clock.
+///
+/// This function uses `ClockId` which only contains clocks which are known to
+/// always be supported at runtime, allowing this function to be infallible.
+/// For a greater set of clocks and dynamic clock support, see
+/// [`clock_gettime_dynamic`].
+///
+/// # References
+/// - [POSIX]
+/// - [Linux]
+///
+/// [POSIX]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/clock_gettime.html
+/// [Linux]: https://man7.org/linux/man-pages/man2/clock_gettime.2.html
+#[cfg(not(target_os = "wasi"))]
+#[inline]
+#[must_use]
+pub fn clock_gettime(id: ClockId) -> Timespec {
+ imp::time::syscalls::clock_gettime(id)
+}
+
+/// Like [`clock_gettime`] but with support for dynamic clocks.
+///
+/// # References
+/// - [POSIX]
+/// - [Linux]
+///
+/// [POSIX]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/clock_gettime.html
+/// [Linux]: https://man7.org/linux/man-pages/man2/clock_gettime.2.html
+#[cfg(not(target_os = "wasi"))]
+#[inline]
+pub fn clock_gettime_dynamic(id: DynamicClockId<'_>) -> io::Result<Timespec> {
+ imp::time::syscalls::clock_gettime_dynamic(id)
+}