/src/WasmEdge/lib/host/wasi/clock-linux.cpp
Line | Count | Source (jump to first uncovered line) |
1 | | // SPDX-License-Identifier: Apache-2.0 |
2 | | // SPDX-FileCopyrightText: 2019-2024 Second State INC |
3 | | |
4 | | #include "common/defines.h" |
5 | | #if WASMEDGE_OS_LINUX |
6 | | |
7 | | #include "host/wasi/clock.h" |
8 | | #include "linux.h" |
9 | | |
10 | | namespace WasmEdge { |
11 | | namespace Host { |
12 | | namespace WASI { |
13 | | |
14 | | WasiExpect<void> Clock::clockResGet(__wasi_clockid_t Id, |
15 | 0 | __wasi_timestamp_t &Resolution) noexcept { |
16 | 0 | timespec SysTimespec; |
17 | 0 | if (auto Res = ::clock_getres(toClockId(Id), &SysTimespec); |
18 | 0 | unlikely(Res != 0)) { |
19 | 0 | return WasiUnexpect(fromErrNo(errno)); |
20 | 0 | } |
21 | | |
22 | 0 | Resolution = fromTimespec(SysTimespec); |
23 | 0 | return {}; |
24 | 0 | } |
25 | | |
26 | | WasiExpect<void> Clock::clockTimeGet(__wasi_clockid_t Id, __wasi_timestamp_t, |
27 | 0 | __wasi_timestamp_t &Time) noexcept { |
28 | 0 | timespec SysTimespec; |
29 | 0 | if (auto Res = ::clock_gettime(toClockId(Id), &SysTimespec); |
30 | 0 | unlikely(Res != 0)) { |
31 | 0 | return WasiUnexpect(fromErrNo(errno)); |
32 | 0 | } |
33 | | |
34 | 0 | Time = fromTimespec(SysTimespec); |
35 | 0 | return {}; |
36 | 0 | } |
37 | | |
38 | | } // namespace WASI |
39 | | } // namespace Host |
40 | | } // namespace WasmEdge |
41 | | |
42 | | #endif |