posixtimespecsubtract.c

来自「RTEMS (Real-Time Executive for Multiproc」· C语言 代码 · 共 51 行

C
51
字号
/* *  $Id: posixtimespecsubtract.c,v 1.4 2002/12/02 19:15:24 joel Exp $ */#if HAVE_CONFIG_H#include "config.h"#endif#include <assert.h>#include <time.h>#include <errno.h>#include <rtems/system.h>#include <rtems/score/isr.h>#include <rtems/score/thread.h>#include <rtems/score/tod.h>#include <rtems/seterr.h>#include <rtems/posix/time.h>/*PAGE * *  _POSIX_Timespec_subtract */void _POSIX_Timespec_subtract(  const struct timespec *the_start,  const struct timespec *end,  struct timespec *result){  struct timespec  start_struct = *the_start;  struct timespec *start = &start_struct;  unsigned32 nsecs_per_sec = TOD_NANOSECONDS_PER_SECOND;   if (end->tv_nsec < start->tv_nsec) {    int seconds = (start->tv_nsec - end->tv_nsec) / nsecs_per_sec + 1;    start->tv_nsec -= nsecs_per_sec * seconds;    start->tv_sec += seconds;  }   if (end->tv_nsec - start->tv_nsec > nsecs_per_sec) {    int seconds = (start->tv_nsec - end->tv_nsec) / nsecs_per_sec;    start->tv_nsec += nsecs_per_sec * seconds;    start->tv_sec -= seconds;  }   result->tv_sec  = end->tv_sec - start->tv_sec;  result->tv_nsec = end->tv_nsec - start->tv_nsec;}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?