revert between 56095 -> 55830 in arch
[AROS.git] / compiler / posixc / clock_gettime.c
blob62917431d263e3cb5ffce43379aa07ae6965186b
1 /*
2 Copyright © 2008-2018, The AROS Development Team. All rights reserved.
3 $Id$
4 POSIX.1-2001 function clock_gettime().
5 */
7 #include <proto/exec.h>
8 #include <proto/timer.h>
9 #include <errno.h>
11 #include "__posixc_time.h"
13 /*****************************************************************************
14 NAME */
15 #include <time.h>
17 int clock_gettime (
19 /* SYNOPSIS */
20 clockid_t clk_id,
21 struct timespec *tp)
23 /* FUNCTION
24 retrieve the time of the specified clock clk_id.
26 INPUTS
27 clk_id - identifier of the particular clock on which to act
28 CLOCK_REALTIME
29 System-wide realtime clock. Setting this clock requires appropriate privileges.
30 CLOCK_MONOTONIC
31 Clock that cannot be set and represents monotonic time since some unspecified starting point.
32 CLOCK_PROCESS_CPUTIME_ID
33 High-resolution per-process timer from the CPU.
34 CLOCK_THREAD_CPUTIME_ID
35 Thread-specific CPU-time clock.
36 tp - structure to hold the retrieved time value
38 RESULT
39 0 on success, -1 on error
41 NOTES
42 Currently at most a resolution of milliseconds is supported.
44 EXAMPLE
46 BUGS
48 SEE ALSO
50 INTERNALS
52 ******************************************************************************/
54 struct PosixCIntBase *PosixCBase = (struct PosixCIntBase *)__aros_getbase_PosixCBase();
55 int retval = -1;
57 if (!TimerBase)
58 __init_timerbase(PosixCBase);
60 switch(clk_id)
62 case CLOCK_REALTIME:
64 if (TimerBase)
66 struct timeval tv;
67 GetSysTime(&tv);
68 tp->tv_sec = tv.tv_sec;
69 tp->tv_nsec = tv.tv_usec * 1000;
70 retval = 0;
72 else
74 errno = EACCES;
76 break;
79 case CLOCK_MONOTONIC:
81 if (TimerBase)
83 struct timeval tv;
84 GetUpTime(&tv);
85 tp->tv_sec = tv.tv_sec;
86 tp->tv_nsec = tv.tv_usec * 1000;
87 retval = 0;
89 else
91 errno = EACCES;
93 break;
96 default:
97 errno = EINVAL;
98 break;
102 return retval;
103 } /* clock_gettime() */