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