diff options
author | Joel Sherrill <joel.sherrill@OARcorp.com> | 1996-09-17 21:31:30 +0000 |
---|---|---|
committer | Joel Sherrill <joel.sherrill@OARcorp.com> | 1996-09-17 21:31:30 +0000 |
commit | 41be2e8943d8737c0074c266aa9c463ab7faff05 (patch) | |
tree | ad007c9180e6557855cd3e4e2e36a95410c0b5e0 /cpukit | |
parent | Added code to insure that the post switch extension was executed and (diff) | |
download | rtems-41be2e8943d8737c0074c266aa9c463ab7faff05.tar.bz2 |
added routine _POSIX_Timespec_subtract
Diffstat (limited to 'cpukit')
-rw-r--r-- | cpukit/posix/src/time.c | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/cpukit/posix/src/time.c b/cpukit/posix/src/time.c index 125db4d16b..f184f200e8 100644 --- a/cpukit/posix/src/time.c +++ b/cpukit/posix/src/time.c @@ -16,6 +16,37 @@ /*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 */ |