]> git.proxmox.com Git - wasi-libc.git/blob - libc-bottom-half/cloudlibc/src/libc/time/clock_gettime.c
Wasi snapshot preview1 (#140)
[wasi-libc.git] / libc-bottom-half / cloudlibc / src / libc / time / clock_gettime.c
1 // Copyright (c) 2015-2016 Nuxi, https://nuxi.nl/
2 //
3 // SPDX-License-Identifier: BSD-2-Clause
4
5 #include <common/clock.h>
6 #include <common/time.h>
7
8 #include <wasi/api.h>
9 #include <errno.h>
10 #include <time.h>
11
12 #ifdef __wasilibc_unmodified_upstream
13 int clock_gettime(clockid_t clock_id, struct timespec *tp) {
14 #else
15 int __clock_gettime(clockid_t clock_id, struct timespec *tp) {
16 #endif
17 __wasi_timestamp_t ts;
18 __wasi_errno_t error = __wasi_clock_time_get(clock_id->id, 1, &ts);
19 if (error != 0) {
20 errno = error;
21 return -1;
22 }
23 *tp = timestamp_to_timespec(ts);
24 return 0;
25 }
26 #ifdef __wasilibc_unmodified_upstream
27 #else
28 extern __typeof(__clock_gettime) clock_gettime __attribute__((weak, alias("__clock_gettime")));
29 #endif