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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [rtems/] [c/] [src/] [exec/] [posix/] [src/] [posixtimespecsubtract.c] - Blame information for rev 532

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

Line No. Rev Author Line
1 30 unneback
/*
2
 *  $Id: posixtimespecsubtract.c,v 1.2 2001-09-27 11:59:17 chris Exp $
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
}

powered by: WebSVN 2.1.0

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