File tree Expand file tree Collapse file tree 4 files changed +43
-0
lines changed Expand file tree Collapse file tree 4 files changed +43
-0
lines changed Original file line number Diff line number Diff line change 31
31
# ifdef __USE_POSIX199309
32
32
/* Identifier for system-wide realtime clock. */
33
33
# define CLOCK_REALTIME 0
34
+ # define CLOCK_MONOTONIC 1
34
35
35
36
/* Flag to indicate time is absolute. */
36
37
# define TIMER_ABSTIME 1
Original file line number Diff line number Diff line change @@ -277,6 +277,8 @@ extern int dysize (int __year) __THROW __attribute__ ((__const__));
277
277
__THROW. */
278
278
extern int nanosleep (__const struct timespec * __requested_time ,
279
279
struct timespec * __remaining );
280
+
281
+ extern int clock_gettime (clockid_t clock_id , struct timespec * tp );
280
282
# endif
281
283
282
284
# ifdef __USE_XOPEN_EXTENDED
Original file line number Diff line number Diff line change @@ -20,6 +20,7 @@ SRCFILES = \
20
20
glob.c \
21
21
isfdtype.c \
22
22
nanosleep.c \
23
+ clock_gettime.c \
23
24
posix_fallocate.c \
24
25
pread.c \
25
26
pwrite.c \
Original file line number Diff line number Diff line change
1
+ #include <errno.h>
2
+ #include <stdint.h>
3
+ #include <time.h>
4
+ #include <sys/time.h>
5
+
6
+ static inline int
7
+ realtime_gettime (struct timespec * tp )
8
+ {
9
+ struct timeval tv ;
10
+ int retval = __gettimeofday (& tv , NULL );
11
+ if (retval == 0 )
12
+ /* Convert into `timespec'. */
13
+ TIMEVAL_TO_TIMESPEC (& tv , tp );
14
+ return retval ;
15
+ }
16
+
17
+ /* Get current value of CLOCK and store it in TP. */
18
+
19
+ __typeof__ (clock_gettime ) __clock_gettime ;
20
+
21
+ int
22
+ __clock_gettime (clockid_t clock_id , struct timespec * tp )
23
+ {
24
+ int retval = -1 ;
25
+
26
+ switch (clock_id )
27
+ {
28
+ case CLOCK_MONOTONIC :
29
+ case CLOCK_REALTIME :
30
+ retval = realtime_gettime (tp );
31
+ break ;
32
+ default :
33
+ __set_errno (EINVAL );
34
+ break ;
35
+ }
36
+ return retval ;
37
+ }
38
+
39
+ weak_alias (__clock_gettime , clock_gettime )
You can’t perform that action at this time.
0 commit comments