OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [rtems-20020807/] [cpukit/] [posix/] [src/] [posixtimespecsubtract.c] - Blame information for rev 1774

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 1026 ivang
/*
2
 *  posixtimespecsubtract.c,v 1.3 2001/01/24 14:17:28 joel Exp
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
 
26
void _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
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.