source: rtems/cpukit/posix/src/posixtimespecsubtract.c @ 39cefdd

4.104.114.84.95
Last change on this file since 39cefdd was 39cefdd, checked in by Ralf Corsepius <ralf.corsepius@…>, on 03/23/04 at 13:07:29

2004-03-23 Ralf Corsepius <ralf_corsepius@…>

  • posix/include/rtems/posix/cond.h, posix/include/rtems/posix/intr.h, posix/include/rtems/posix/key.h, posix/include/rtems/posix/mqueue.h, posix/include/rtems/posix/mutex.h, posix/include/rtems/posix/pthread.h, posix/include/rtems/posix/semaphore.h, posix/include/rtems/posix/threadsup.h, posix/include/rtems/posix/timer.h, posix/src/cond.c, posix/src/intr.c, posix/src/key.c, posix/src/keycreate.c, posix/src/keydelete.c, posix/src/keygetspecific.c, posix/src/keyrundestructors.c, posix/src/keysetspecific.c, posix/src/killinfo.c, posix/src/mqueue.c, posix/src/mqueuerecvsupp.c, posix/src/mqueuesendsupp.c, posix/src/mqueuetranslatereturncode.c, posix/src/mutex.c, posix/src/posixintervaltotimespec.c, posix/src/posixtimespecsubtract.c, posix/src/psignal.c, posix/src/pthread.c, posix/src/ptimer1.c, posix/src/semaphore.c, posix/src/sysconf.c: Convert to using c99 fixed size types.
  • Property mode set to 100644
File size: 1.1 KB
Line 
1/*
2 *  $Id$
3 */
4
5#if HAVE_CONFIG_H
6#include "config.h"
7#endif
8
9#include <assert.h>
10#include <time.h>
11#include <errno.h>
12
13#include <rtems/system.h>
14#include <rtems/score/isr.h>
15#include <rtems/score/thread.h>
16#include <rtems/score/tod.h>
17
18#include <rtems/seterr.h>
19#include <rtems/posix/time.h>
20
21/*PAGE
22 *
23 *  _POSIX_Timespec_subtract
24 */
25
26void _POSIX_Timespec_subtract(
27  const struct timespec *the_start,
28  const struct timespec *end,
29  struct timespec *result
30)
31{
32  struct timespec  start_struct = *the_start;
33  struct timespec *start = &start_struct;
34  uint32_t   nsecs_per_sec = TOD_NANOSECONDS_PER_SECOND;
35 
36  if (end->tv_nsec < start->tv_nsec) {
37    int seconds = (start->tv_nsec - end->tv_nsec) / nsecs_per_sec + 1;
38    start->tv_nsec -= nsecs_per_sec * seconds;
39    start->tv_sec += seconds;
40  }
41 
42  if (end->tv_nsec - start->tv_nsec > nsecs_per_sec) {
43    int seconds = (start->tv_nsec - end->tv_nsec) / nsecs_per_sec;
44    start->tv_nsec += nsecs_per_sec * seconds;
45    start->tv_sec -= seconds;
46  }
47 
48  result->tv_sec  = end->tv_sec - start->tv_sec;
49  result->tv_nsec = end->tv_nsec - start->tv_nsec;
50}
Note: See TracBrowser for help on using the repository browser.