Changeset 41be2e8 in rtems


Ignore:
Timestamp:
Sep 17, 1996, 9:31:30 PM (24 years ago)
Author:
Joel Sherrill <joel.sherrill@…>
Branches:
4.10, 4.11, 4.8, 4.9, 5, master
Children:
1d9d044
Parents:
aa48536
Message:

added routine _POSIX_Timespec_subtract

Files:
2 edited

Legend:

Unmodified
Added
Removed
  • c/src/exec/posix/src/time.c

    raa48536 r41be2e8  
    1414#include <rtems/posix/seterr.h>
    1515#include <rtems/posix/time.h>
     16
     17/*PAGE
     18 *
     19 *  _POSIX_Timespec_subtract
     20 */
     21
     22void _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}
    1647
    1748/*PAGE
  • cpukit/posix/src/time.c

    raa48536 r41be2e8  
    1414#include <rtems/posix/seterr.h>
    1515#include <rtems/posix/time.h>
     16
     17/*PAGE
     18 *
     19 *  _POSIX_Timespec_subtract
     20 */
     21
     22void _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}
    1647
    1748/*PAGE
Note: See TracChangeset for help on using the changeset viewer.