]> git.proxmox.com Git - wasi-libc.git/blob - libc-bottom-half/cloudlibc/src/libc/sys/times/times.c
c2564e1dd31a4c1085777893275ccaf3d31ba0c3
[wasi-libc.git] / libc-bottom-half / cloudlibc / src / libc / sys / times / times.c
1 // Copyright (c) 2015-2016 Nuxi, https://nuxi.nl/
2 //
3 // SPDX-License-Identifier: BSD-2-Clause
4
5 #include <common/time.h>
6
7 #include <sys/times.h>
8
9 #include <assert.h>
10 #include <wasi/core.h>
11
12 static_assert(CLOCKS_PER_SEC == NSEC_PER_SEC,
13 "Timestamp should need no conversion");
14
15 clock_t times(struct tms *buffer) {
16 // Obtain user time.
17 __wasi_timestamp_t usertime = 0;
18 (void)__wasi_clock_time_get(__WASI_CLOCK_PROCESS_CPUTIME_ID, 0, &usertime);
19 *buffer = (struct tms){.tms_utime = usertime};
20
21 // Obtain real time.
22 __wasi_timestamp_t realtime = 0;
23 (void)__wasi_clock_time_get(__WASI_CLOCK_MONOTONIC, 0, &realtime);
24 return realtime;
25 }