summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--c/src/exec/libcsupport/src/__gettod.c39
-rw-r--r--c/src/lib/libc/__gettod.c39
-rw-r--r--cpukit/libcsupport/src/__gettod.c39
3 files changed, 84 insertions, 33 deletions
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 <rtems.h>
#if !defined(RTEMS_UNIX)
@@ -27,6 +29,15 @@
#include <assert.h>
/*
+ * 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 <rtems.h>
#if !defined(RTEMS_UNIX)
@@ -27,6 +29,15 @@
#include <assert.h>
/*
+ * 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/cpukit/libcsupport/src/__gettod.c b/cpukit/libcsupport/src/__gettod.c
index e937ce1ca6..dc83c47ce4 100644
--- a/cpukit/libcsupport/src/__gettod.c
+++ b/cpukit/libcsupport/src/__gettod.c
@@ -1,3 +1,5 @@
+#define __RTEMS_VIOLATE_KERNEL_VISIBILITY__
+
#include <rtems.h>
#if !defined(RTEMS_UNIX)
@@ -27,6 +29,15 @@
#include <assert.h>
/*
+ * 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