summaryrefslogtreecommitdiffstats
path: root/c/src/exec/posix/src/posixtimespecsubtract.c
diff options
context:
space:
mode:
authorJoel Sherrill <joel.sherrill@OARcorp.com>1999-11-02 18:35:52 +0000
committerJoel Sherrill <joel.sherrill@OARcorp.com>1999-11-02 18:35:52 +0000
commit9f95a19a57f0f85212c320327636e93d70bbecc8 (patch)
treed62e1fc518777ce07e83994183d0d1b82a7f8a02 /c/src/exec/posix/src/posixtimespecsubtract.c
parentSplit condition variables into multiple files. (diff)
downloadrtems-9f95a19a57f0f85212c320327636e93d70bbecc8.tar.bz2
Split time.c into multiple files.
Diffstat (limited to 'c/src/exec/posix/src/posixtimespecsubtract.c')
-rw-r--r--c/src/exec/posix/src/posixtimespecsubtract.c46
1 files changed, 46 insertions, 0 deletions
diff --git a/c/src/exec/posix/src/posixtimespecsubtract.c b/c/src/exec/posix/src/posixtimespecsubtract.c
new file mode 100644
index 0000000000..eb5e21d83a
--- /dev/null
+++ b/c/src/exec/posix/src/posixtimespecsubtract.c
@@ -0,0 +1,46 @@
+/*
+ * $Id$
+ */
+
+#include <assert.h>
+#include <time.h>
+#include <errno.h>
+
+#include <rtems/system.h>
+#include <rtems/score/isr.h>
+#include <rtems/score/thread.h>
+#include <rtems/score/tod.h>
+
+#include <rtems/posix/seterr.h>
+#include <rtems/posix/time.h>
+
+/*PAGE
+ *
+ * _POSIX_Timespec_subtract
+ */
+
+void _POSIX_Timespec_subtract(
+ const struct timespec *the_start,
+ const struct timespec *end,
+ struct timespec *result
+)
+{
+ struct timespec start_struct = *the_start;
+ struct timespec *start = &start_struct;
+ unsigned int nsecs_per_sec = TOD_NANOSECONDS_PER_SECOND;
+
+ if (end->tv_nsec < start->tv_nsec) {
+ int seconds = (start->tv_nsec - end->tv_nsec) / nsecs_per_sec + 1;
+ start->tv_nsec -= nsecs_per_sec * seconds;
+ start->tv_sec += seconds;
+ }
+
+ if (end->tv_nsec - start->tv_nsec > nsecs_per_sec) {
+ int seconds = (start->tv_nsec - end->tv_nsec) / nsecs_per_sec;
+ start->tv_nsec += nsecs_per_sec * seconds;
+ start->tv_sec -= seconds;
+ }
+
+ result->tv_sec = end->tv_sec - start->tv_sec;
+ result->tv_nsec = end->tv_nsec - start->tv_nsec;
+}