1 | /* |
---|
2 | * gettimeofday() - SVR4 and BSD4.3 extension required by Newlib |
---|
3 | * |
---|
4 | * COPYRIGHT (c) 1989-1998. |
---|
5 | * On-Line Applications Research Corporation (OAR). |
---|
6 | * Copyright assigned to U.S. Government, 1994. |
---|
7 | * |
---|
8 | * The license and distribution terms for this file may be |
---|
9 | * found in the file LICENSE in this distribution or at |
---|
10 | * http://www.OARcorp.com/rtems/license.html. |
---|
11 | * |
---|
12 | * $Id$ |
---|
13 | */ |
---|
14 | |
---|
15 | #define __RTEMS_VIOLATE_KERNEL_VISIBILITY__ |
---|
16 | |
---|
17 | #include <rtems.h> |
---|
18 | |
---|
19 | #if !defined(RTEMS_UNIX) |
---|
20 | #ifdef RTEMS_NEWLIB |
---|
21 | #include <sys/reent.h> |
---|
22 | #endif |
---|
23 | |
---|
24 | #include <sys/time.h> |
---|
25 | #include <time.h> |
---|
26 | |
---|
27 | #include <errno.h> |
---|
28 | #include <assert.h> |
---|
29 | |
---|
30 | /* |
---|
31 | * Seconds from January 1, 1970 to January 1, 1988. Used to account for |
---|
32 | * differences between POSIX API and RTEMS core. |
---|
33 | */ |
---|
34 | |
---|
35 | #define POSIX_TIME_SECONDS_1970_THROUGH_1988 \ |
---|
36 | (((1987 - 1970 + 1) * TOD_SECONDS_PER_NON_LEAP_YEAR) + \ |
---|
37 | (4 * TOD_SECONDS_PER_DAY)) |
---|
38 | |
---|
39 | /* |
---|
40 | * NOTE: The solaris gettimeofday does not have a second parameter. |
---|
41 | */ |
---|
42 | |
---|
43 | int gettimeofday( |
---|
44 | struct timeval *tp, |
---|
45 | struct timezone *tzp |
---|
46 | ) |
---|
47 | { |
---|
48 | rtems_interrupt_level level; |
---|
49 | rtems_unsigned32 seconds; |
---|
50 | rtems_unsigned32 microseconds; |
---|
51 | |
---|
52 | if ( !tp ) { |
---|
53 | errno = EFAULT; |
---|
54 | return -1; |
---|
55 | } |
---|
56 | |
---|
57 | /* |
---|
58 | * POSIX does not seem to allow for not having a TOD so we just |
---|
59 | * grab the time of day. |
---|
60 | * |
---|
61 | * NOTE: XXX this routine should really be in the executive proper. |
---|
62 | */ |
---|
63 | |
---|
64 | rtems_interrupt_disable(level); |
---|
65 | seconds = _TOD_Seconds_since_epoch; |
---|
66 | microseconds = _TOD_Current.ticks; |
---|
67 | rtems_interrupt_enable(level); |
---|
68 | |
---|
69 | tp->tv_sec = seconds + POSIX_TIME_SECONDS_1970_THROUGH_1988; |
---|
70 | tp->tv_usec = microseconds * _TOD_Microseconds_per_tick; |
---|
71 | |
---|
72 | /* |
---|
73 | * newlib does not have timezone and daylight savings time |
---|
74 | * yet. When it does this needs to be fixed. |
---|
75 | */ |
---|
76 | |
---|
77 | #if 0 |
---|
78 | if ( tzp ) { |
---|
79 | tzp->tz_minuteswest = 0; /* at UTC */ |
---|
80 | tzp->tz_dsttime = 0; /* no daylight savings */ |
---|
81 | tzp->minuteswest = timezone / 60; /* from seconds to minutes */ |
---|
82 | tzp->dsttime = daylight; |
---|
83 | } |
---|
84 | #endif |
---|
85 | return 0; |
---|
86 | } |
---|
87 | |
---|
88 | #if defined(RTEMS_NEWLIB) |
---|
89 | |
---|
90 | /* |
---|
91 | * "Reentrant" version |
---|
92 | */ |
---|
93 | |
---|
94 | int _gettimeofday_r( |
---|
95 | struct _reent *ignored_reentrancy_stuff, |
---|
96 | struct timeval *tp, |
---|
97 | struct timezone *tzp |
---|
98 | ) |
---|
99 | { |
---|
100 | return gettimeofday( tp, tzp ); |
---|
101 | } |
---|
102 | |
---|
103 | /* |
---|
104 | * "System call" version |
---|
105 | */ |
---|
106 | |
---|
107 | int _gettimeofday( |
---|
108 | struct timeval *tp, |
---|
109 | struct timezone *tzp |
---|
110 | ) |
---|
111 | { |
---|
112 | return gettimeofday( tp, tzp ); |
---|
113 | } |
---|
114 | |
---|
115 | #endif /* defined(RTEMS_NEWLIB) */ |
---|
116 | |
---|
117 | #endif |
---|