From ce691c51fd2f8b237ad741a9f333285f2ad1df1f Mon Sep 17 00:00:00 2001 From: Joel Sherrill Date: Thu, 18 Jun 1998 15:14:48 +0000 Subject: 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. --- c/src/exec/libcsupport/src/__gettod.c | 39 +++++++++++++++++++++++++---------- c/src/lib/libc/__gettod.c | 39 +++++++++++++++++++++++++---------- 2 files changed, 56 insertions(+), 22 deletions(-) (limited to 'c/src') diff --git a/c/src/exec/libcsupport/src/__gettod.c b/c/src/exec/libcsupport/src/__gettod.c index e937ce1ca6..dc83c47ce4 100644 --- a/c/src/exec/libcsupport/src/__gettod.c +++ b/c/src/exec/libcsupport/src/__gettod.c @@ -1,3 +1,5 @@ +#define __RTEMS_VIOLATE_KERNEL_VISIBILITY__ + #include #if !defined(RTEMS_UNIX) @@ -26,6 +28,15 @@ #include #include +/* + * Seconds from January 1, 1970 to January 1, 1988. Used to account for + * differences between POSIX API and RTEMS core. + */ + +#define POSIX_TIME_SECONDS_1970_THROUGH_1988 \ + (((1987 - 1970 + 1) * TOD_SECONDS_PER_NON_LEAP_YEAR) + \ + (4 * TOD_SECONDS_PER_DAY)) + /* * NOTE: The solaris gettimeofday does not have a second parameter. */ @@ -35,23 +46,29 @@ int gettimeofday( struct timezone *tzp ) { - rtems_status_code status; - rtems_clock_time_value time; + rtems_interrupt_level level; + rtems_unsigned32 seconds; + rtems_unsigned32 microseconds; if ( !tp ) { errno = EFAULT; return -1; } - /* "POSIX" does not seem to allow for not having a TOD */ - status = rtems_clock_get( RTEMS_CLOCK_GET_TIME_VALUE, &time ); - if ( status != RTEMS_SUCCESSFUL ) { - assert( 0 ); - return -1; - } - - tp->tv_sec = time.seconds; - tp->tv_usec = time.microseconds; + /* + * POSIX does not seem to allow for not having a TOD so we just + * grab the time of day. + * + * NOTE: XXX this routine should really be in the executive proper. + */ + + rtems_interrupt_disable(level); + seconds = _TOD_Seconds_since_epoch; + microseconds = _TOD_Current.ticks; + rtems_interrupt_enable(level); + + tp->tv_sec = seconds + POSIX_TIME_SECONDS_1970_THROUGH_1988; + tp->tv_usec = microseconds * _TOD_Microseconds_per_tick; /* * newlib does not have timezone and daylight savings time diff --git a/c/src/lib/libc/__gettod.c b/c/src/lib/libc/__gettod.c index e937ce1ca6..dc83c47ce4 100644 --- a/c/src/lib/libc/__gettod.c +++ b/c/src/lib/libc/__gettod.c @@ -1,3 +1,5 @@ +#define __RTEMS_VIOLATE_KERNEL_VISIBILITY__ + #include #if !defined(RTEMS_UNIX) @@ -26,6 +28,15 @@ #include #include +/* + * Seconds from January 1, 1970 to January 1, 1988. Used to account for + * differences between POSIX API and RTEMS core. + */ + +#define POSIX_TIME_SECONDS_1970_THROUGH_1988 \ + (((1987 - 1970 + 1) * TOD_SECONDS_PER_NON_LEAP_YEAR) + \ + (4 * TOD_SECONDS_PER_DAY)) + /* * NOTE: The solaris gettimeofday does not have a second parameter. */ @@ -35,23 +46,29 @@ int gettimeofday( struct timezone *tzp ) { - rtems_status_code status; - rtems_clock_time_value time; + rtems_interrupt_level level; + rtems_unsigned32 seconds; + rtems_unsigned32 microseconds; if ( !tp ) { errno = EFAULT; return -1; } - /* "POSIX" does not seem to allow for not having a TOD */ - status = rtems_clock_get( RTEMS_CLOCK_GET_TIME_VALUE, &time ); - if ( status != RTEMS_SUCCESSFUL ) { - assert( 0 ); - return -1; - } - - tp->tv_sec = time.seconds; - tp->tv_usec = time.microseconds; + /* + * POSIX does not seem to allow for not having a TOD so we just + * grab the time of day. + * + * NOTE: XXX this routine should really be in the executive proper. + */ + + rtems_interrupt_disable(level); + seconds = _TOD_Seconds_since_epoch; + microseconds = _TOD_Current.ticks; + rtems_interrupt_enable(level); + + tp->tv_sec = seconds + POSIX_TIME_SECONDS_1970_THROUGH_1988; + tp->tv_usec = microseconds * _TOD_Microseconds_per_tick; /* * newlib does not have timezone and daylight savings time -- cgit v1.2.3