/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 | | #include "common/types.h" |
6 | | #if WASMEDGE_OS_LINUX |
7 | | |
8 | | #include "host/wasi/clock.h" |
9 | | #include "linux.h" |
10 | | |
11 | | namespace WasmEdge { |
12 | | namespace Host { |
13 | | namespace WASI { |
14 | | |
15 | | WasiExpect<void> Clock::clockResGet(__wasi_clockid_t Id, |
16 | 0 | __wasi_timestamp_t &Resolution) noexcept { |
17 | 0 | timespec SysTimespec; |
18 | 0 | if (auto Res = ::clock_getres(toClockId(Id), &SysTimespec); |
19 | 0 | unlikely(Res != 0)) { |
20 | 0 | return WasiUnexpect(fromErrNo(errno)); |
21 | 0 | } |
22 | | |
23 | 0 | Resolution = fromTimespec(SysTimespec).le(); |
24 | 0 | return {}; |
25 | 0 | } |
26 | | |
27 | | WasiExpect<void> Clock::clockTimeGet(__wasi_clockid_t Id, __wasi_timestamp_t, |
28 | 0 | __wasi_timestamp_t &Time) noexcept { |
29 | 0 | timespec SysTimespec; |
30 | 0 | if (auto Res = ::clock_gettime(toClockId(Id), &SysTimespec); |
31 | 0 | unlikely(Res != 0)) { |
32 | 0 | return WasiUnexpect(fromErrNo(errno)); |
33 | 0 | } |
34 | | |
35 | 0 | Time = fromTimespec(SysTimespec).le(); |
36 | 0 | return {}; |
37 | 0 | } |
38 | | |
39 | | } // namespace WASI |
40 | | } // namespace Host |
41 | | } // namespace WasmEdge |
42 | | |
43 | | #endif |