added routine _POSIX_Timespec_subtract

This commit is contained in:
Joel Sherrill
1996-09-17 21:31:30 +00:00
parent aa48536498
commit 41be2e8943
2 changed files with 62 additions and 0 deletions

View File

@@ -14,6 +14,37 @@
#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;
}
/*PAGE
*
* _POSIX_Timespec_to_interval

View File

@@ -14,6 +14,37 @@
#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;
}
/*PAGE
*
* _POSIX_Timespec_to_interval