source: rtems/c/src/lib/libc/__gettod.c @ ee733965

4.104.114.84.95
Last change on this file since ee733965 was 07a3253d, checked in by Joel Sherrill <joel.sherrill@…>, on 11/23/98 at 19:07:58

Added base version of file system infrastructure. This includes a major
overhaul of the RTEMS system call interface. This base file system is
the "In-Memory File System" aka IMFS.

The design and implementation was done by the following people:

+ Joel Sherrill (joel@…)
+ Jennifer Averett (jennifer@…)
+ Steve "Mr Mount" Salitasc (salitasc@…)
+ Kerwin Wade (wade@…)

PROBLEMS
========

+ It is VERY likely that merging this will break the UNIX port. This

can/will be fixed.

+ There is likely some reentrancy/mutual exclusion needed.

+ Eventually, there should be a "mini-IMFS" description table to

eliminate links, symlinks, etc to save memory. All you need to
have "classic RTEMS" functionality is technically directories
and device IO. All the rest could be left out to save memory.

  • 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-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
43int 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
94int _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
107int _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
Note: See TracBrowser for help on using the repository browser.