source: rtems/cpukit/libcsupport/src/__gettod.c @ 0eae36c7

4.104.114.84.95
Last change on this file since 0eae36c7 was 0eae36c7, checked in by Joel Sherrill <joel.sherrill@…>, on 09/04/03 at 18:54:13

2003-09-04 Joel Sherrill <joel@…>

  • include/chain.h, include/clockdrv.h, include/console.h, include/iosupp.h, include/rtc.h, include/spurious.h, include/timerdrv.h, include/vmeintr.h, include/motorola/mc68230.h, include/rtems/libcsupport.h, include/rtems/libio.h, include/rtems/libio_.h, include/rtems/termiostypes.h, include/sys/termios.h, include/zilog/z8036.h, include/zilog/z8530.h, include/zilog/z8536.h, src/brk.c, src/gettod.c, src/sbrk.c, src/times.c, src/access.c, src/base_fs.c, src/cfgetispeed.c, src/cfgetospeed.c, src/cfsetispeed.c, src/cfsetospeed.c, src/chdir.c, src/chmod.c, src/chown.c, src/chroot.c, src/close.c, src/ctermid.c, src/dup.c, src/dup2.c, src/eval.c, src/fchdir.c, src/fchmod.c, src/fcntl.c, src/fdatasync.c, src/fpathconf.c, src/fs_null_handlers.c, src/fstat.c, src/fsync.c, src/ftruncate.c, src/getdents.c, src/getpwent.c, src/hosterr.c, src/ioctl.c, src/isatty.c, src/libio.c, src/libio_sockets.c, src/link.c, src/lseek.c, src/lstat.c, src/malloc.c, src/mallocfreespace.c, src/mkdir.c, src/mkfifo.c, src/mknod.c, src/mount.c, src/newlibc.c, src/no_libc.c, src/no_posix.c, src/open.c, src/pathconf.c, src/pipe.c, src/privateenv.c, src/read.c, src/readlink.c, src/rewinddir.c, src/rmdir.c, src/seekdir.c, src/stat.c, src/symlink.c, src/sync.c, src/tcdrain.c, src/tcflow.c, src/tcflush.c, src/tcgetattr.c, src/tcgetprgrp.c, src/tcsendbreak.c, src/tcsetattr.c, src/tcsetpgrp.c, src/telldir.c, src/termios.c, src/termiosinitialize.c, src/truncate.c, src/umask.c, src/unixlibc.c, src/unlink.c, src/unmount.c, src/utime.c, src/write.c: URL for license changed.
  • 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.rtems.com/license/LICENSE.
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.