source: rtems/cpukit/posix/src/posixtimespecsubtract.c @ f42b726

4.104.114.84.95
Last change on this file since f42b726 was f42b726, checked in by Joel Sherrill <joel.sherrill@…>, on Jan 24, 2001 at 2:17:28 PM

2001-01-24 Ralf Corsepius <corsepiu@…>

  • configure.in: Add src/config.h
  • src/Makefile.am: Add INCLUDES += -I. to pickup config.h
  • src/.cvsignore: Add config.h and stamp-h
  • src/*.c: Add config.h support.
  • 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  unsigned int 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.