source: rtems/c/src/lib/libc/__gettod.c @ 72650fcb

4.104.114.84.95
Last change on this file since 72650fcb was 9c49db4, checked in by Joel Sherrill <joel.sherrill@…>, on 01/08/01 at 18:26:44

2001-01-08 Ralf Corsepius <corsepiu@…>

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