summaryrefslogtreecommitdiffstats
path: root/third_party/rust/zeitstempel/src/linux.rs
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 17:32:43 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 17:32:43 +0000
commit6bf0a5cb5034a7e684dcc3500e841785237ce2dd (patch)
treea68f146d7fa01f0134297619fbe7e33db084e0aa /third_party/rust/zeitstempel/src/linux.rs
parentInitial commit. (diff)
downloadthunderbird-6bf0a5cb5034a7e684dcc3500e841785237ce2dd.tar.xz
thunderbird-6bf0a5cb5034a7e684dcc3500e841785237ce2dd.zip
Adding upstream version 1:115.7.0.upstream/1%115.7.0upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'third_party/rust/zeitstempel/src/linux.rs')
-rw-r--r--third_party/rust/zeitstempel/src/linux.rs24
1 files changed, 24 insertions, 0 deletions
diff --git a/third_party/rust/zeitstempel/src/linux.rs b/third_party/rust/zeitstempel/src/linux.rs
new file mode 100644
index 0000000000..e8fb8500ca
--- /dev/null
+++ b/third_party/rust/zeitstempel/src/linux.rs
@@ -0,0 +1,24 @@
+const NS_PER_S: u64 = 1_000_000_000;
+
+fn timespec_to_ns(ts: libc::timespec) -> u64 {
+ (ts.tv_sec as u64) * NS_PER_S + (ts.tv_nsec as u64)
+}
+
+/// The time from a clock that cannot be set
+/// and represents monotonic time since some unspecified starting point,
+/// that also includes any time that the system is suspended.
+///
+/// See [`clock_gettime`].
+///
+/// [`clock_gettime`]: https://manpages.debian.org/buster/manpages-dev/clock_gettime.3.en.html
+pub fn now_including_suspend() -> u64 {
+ let mut ts = libc::timespec {
+ tv_sec: 0,
+ tv_nsec: 0,
+ };
+ unsafe {
+ libc::clock_gettime(libc::CLOCK_BOOTTIME, &mut ts);
+ }
+
+ timespec_to_ns(ts)
+}