source: rtems/cpukit/libcsupport/src/__gettod.c @ ce691c51

4.104.114.84.95
Last change on this file since ce691c51 was ce691c51, checked in by Joel Sherrill <joel.sherrill@…>, on 06/18/98 at 15:14:48

Corrected so it returns the correct date. Previously was getting the number
of seconds since 1988 from RTEMS and not adding in the 1970-1988 correction
factor. Plus removed checks for data/time set since POSIX does not permit
this call to fail. GNAT 3.12 depends on this.

  • Property mode set to 100644
File size: 2.3 KB
Line 
1#define __RTEMS_VIOLATE_KERNEL_VISIBILITY__
2
3#include <rtems.h>
4
5#if !defined(RTEMS_UNIX)
6/*
7 *  RTEMS gettimeofday Implementation
8 *
9 *
10 *  COPYRIGHT (c) 1989-1998.
11 *  On-Line Applications Research Corporation (OAR).
12 *  Copyright assigned to U.S. Government, 1994.
13 *
14 *  The license and distribution terms for this file may be
15 *  found in the file LICENSE in this distribution or at
16 *  http://www.OARcorp.com/rtems/license.html.
17 *
18 *  $Id$
19 */
20
21#ifdef RTEMS_NEWLIB
22#include <sys/reent.h>
23#endif
24
25#include <sys/time.h>
26#include <time.h>
27
28#include <errno.h>
29#include <assert.h>
30
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
40/*
41 *  NOTE:  The solaris gettimeofday does not have a second parameter.
42 */
43
44int gettimeofday(
45  struct timeval  *tp,
46  struct timezone *tzp
47)
48{
49  rtems_interrupt_level level;
50  rtems_unsigned32      seconds;
51  rtems_unsigned32      microseconds;
52
53  if ( !tp ) {
54    errno = EFAULT;
55    return -1;
56  }
57
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;
72
73  /*
74   * newlib does not have timezone and daylight savings time
75   * yet.  When it does this needs to be fixed.
76   */
77
78#if 0
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  }
85#endif
86  return 0;
87}
88
89#if defined(RTEMS_NEWLIB)
90
91/*
92 *  "Reentrant" version
93 */
94
95int _gettimeofday_r(
96  struct _reent   *ignored_reentrancy_stuff,
97  struct timeval  *tp,
98  struct timezone *tzp
99)
100{
101  return gettimeofday( tp, tzp );
102}
103
104/*
105 *  "System call" version
106 */
107
108int _gettimeofday(
109  struct timeval  *tp,
110  struct timezone *tzp
111)
112{
113  return gettimeofday( tp, tzp );
114}
115
116#endif /* defined(RTEMS_NEWLIB) */
117
118#endif
Note: See TracBrowser for help on using the repository browser.