Usermode/lib{c,posix} - Adding clock_* POSIX functions
[tpg/acess2.git] / Usermode / Libraries / libposix.so_src / clocks.c
1 /*
2  * Acess2 POSIX Emulation
3  * - By John Hodge (thePowersGang)
4  *
5  * clocks.c
6  * - clock_* functions
7  */
8 #include <acess/sys.h>
9 #include <time.h>
10 #include <errno.h>
11
12 // === CODE ===
13 int clock_getres(clockid_t clk_id, struct timespec *res)
14 {
15         switch(clk_id)
16         {
17         case CLOCK_REALTIME:
18         case CLOCK_MONOTONIC:
19                 if( res ) {
20                         res->tv_sec = 0;
21                         res->tv_nsec = 1000*1000;
22                 }
23                 return 0;
24         }
25         errno = EINVAL;
26         return -1;
27 }
28
29 int clock_gettime(clockid_t clk_id, struct timespec *tp)
30 {
31         switch(clk_id)
32         {
33         case CLOCK_REALTIME:
34         case CLOCK_MONOTONIC:
35                 // TODO: True monotonic clock
36                 if( tp ) {
37                         int64_t ts = _SysTimestamp();
38                         tp->tv_sec = ts / 1000;
39                         tp->tv_nsec = (ts % 1000) * 1000*1000;
40                 }
41                 return 0;
42         }
43         errno = EINVAL;
44         return -1;
45 }
46
47 int clock_settime(clockid_t clk_id, const struct timespec *tp)
48 {
49         errno = EPERM;
50         return -1;
51 }

UCC git Repository :: git.ucc.asn.au