4.104.114.84.95
Line | |
---|
1 | /* |
---|
2 | * $Id$ |
---|
3 | */ |
---|
4 | |
---|
5 | #include <assert.h> |
---|
6 | #include <time.h> |
---|
7 | #include <errno.h> |
---|
8 | |
---|
9 | #include <rtems/system.h> |
---|
10 | #include <rtems/score/isr.h> |
---|
11 | #include <rtems/score/thread.h> |
---|
12 | #include <rtems/score/tod.h> |
---|
13 | |
---|
14 | #include <rtems/posix/seterr.h> |
---|
15 | #include <rtems/posix/time.h> |
---|
16 | |
---|
17 | /*PAGE |
---|
18 | * |
---|
19 | * _POSIX_Timespec_subtract |
---|
20 | */ |
---|
21 | |
---|
22 | void _POSIX_Timespec_subtract( |
---|
23 | const struct timespec *the_start, |
---|
24 | const struct timespec *end, |
---|
25 | struct timespec *result |
---|
26 | ) |
---|
27 | { |
---|
28 | struct timespec start_struct = *the_start; |
---|
29 | struct timespec *start = &start_struct; |
---|
30 | unsigned int nsecs_per_sec = TOD_NANOSECONDS_PER_SECOND; |
---|
31 | |
---|
32 | if (end->tv_nsec < start->tv_nsec) { |
---|
33 | int seconds = (start->tv_nsec - end->tv_nsec) / nsecs_per_sec + 1; |
---|
34 | start->tv_nsec -= nsecs_per_sec * seconds; |
---|
35 | start->tv_sec += seconds; |
---|
36 | } |
---|
37 | |
---|
38 | if (end->tv_nsec - start->tv_nsec > nsecs_per_sec) { |
---|
39 | int seconds = (start->tv_nsec - end->tv_nsec) / nsecs_per_sec; |
---|
40 | start->tv_nsec += nsecs_per_sec * seconds; |
---|
41 | start->tv_sec -= seconds; |
---|
42 | } |
---|
43 | |
---|
44 | result->tv_sec = end->tv_sec - start->tv_sec; |
---|
45 | result->tv_nsec = end->tv_nsec - start->tv_nsec; |
---|
46 | } |
---|
Note: See
TracBrowser
for help on using the repository browser.