1*9fb66d81Schristos /*
2*9fb66d81Schristos * Copyright (c) 2021 Nicholas Marriott <nicholas.marriott@gmail.com>
3*9fb66d81Schristos *
4*9fb66d81Schristos * Permission to use, copy, modify, and distribute this software for any
5*9fb66d81Schristos * purpose with or without fee is hereby granted, provided that the above
6*9fb66d81Schristos * copyright notice and this permission notice appear in all copies.
7*9fb66d81Schristos *
8*9fb66d81Schristos * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9*9fb66d81Schristos * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10*9fb66d81Schristos * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11*9fb66d81Schristos * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12*9fb66d81Schristos * WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER
13*9fb66d81Schristos * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
14*9fb66d81Schristos * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15*9fb66d81Schristos */
16*9fb66d81Schristos
17*9fb66d81Schristos #include <sys/types.h>
18*9fb66d81Schristos #include <sys/time.h>
19*9fb66d81Schristos
20*9fb66d81Schristos #include "compat.h"
21*9fb66d81Schristos
22*9fb66d81Schristos #ifndef TIMEVAL_TO_TIMESPEC
23*9fb66d81Schristos #define TIMEVAL_TO_TIMESPEC(tv, ts) do { \
24*9fb66d81Schristos (ts)->tv_sec = (tv)->tv_sec; \
25*9fb66d81Schristos (ts)->tv_nsec = (tv)->tv_usec * 1000; \
26*9fb66d81Schristos } while (0)
27*9fb66d81Schristos #endif
28*9fb66d81Schristos
29*9fb66d81Schristos int
clock_gettime(int clock,struct timespec * ts)30*9fb66d81Schristos clock_gettime(int clock, struct timespec *ts)
31*9fb66d81Schristos {
32*9fb66d81Schristos struct timeval tv;
33*9fb66d81Schristos
34*9fb66d81Schristos gettimeofday(&tv, NULL);
35*9fb66d81Schristos TIMEVAL_TO_TIMESPEC(&tv, ts);
36*9fb66d81Schristos return 0;
37*9fb66d81Schristos }
38