1 timespec(3HEAD)                     Headers                    timespec(3HEAD)
   2 
   3 NAME
   4      timespec, timeval, TIMESPEC_TO_TIMEVAL, TIMEVAL_TO_TIMESPEC - time
   5      structures and conversion
   6 
   7 SYNOPSIS
   8      #include <sys/time.h>
   9 
  10      void
  11      TIMESPEC_TO_TIMEVAL(struct timeval *tv, const struct timespec *ts);
  12 
  13      void
  14      TIMEVAL_TO_TIMESPEC(const struct timeval *tv, struct timespec *ts);
  15 
  16 DESCRIPTION
  17      The timeval and timespec structures are declared in the <time.h> and
  18      <sys/time.h> headers respectively:
  19 
  20            typedef struct timespec {
  21                    time_t          tv_sec;         /* seconds */
  22                    long            tv_nsec;        /* and nanoseconds */
  23            } timespec_t;
  24 
  25            struct timeval {
  26                    time_t          tv_sec;         /* seconds */
  27                    suseconds_t     tv_usec;        /* and microseconds */
  28            };
  29 
  30      In both cases, the tv_sec member represents elapsed time in whole
  31      seconds.  The tv_nsec and tv_usec members represent the rest of the
  32      elapsed time in nanoseconds and microseconds respectively, depending on
  33      the structure.
  34 
  35      The TIMEVAL_TO_TIMESPEC macro can be used to convert a struct timeval
  36      structure to a struct timespec structure, while the TIMESPEC_TO_TIMEVAL
  37      macro works in the opposite direction.
  38 
  39      When converting from a struct timespec to a struct timeval structure, the
  40      tv_nsec member is truncated, losing precision.  When converting from a
  41      struct timeval to a struct timespec structure, the tv_usec member is
  42      multiplied by 1000 to reach the precision of the target structure.  The
  43      tv_sec member is always preserved, no matter which conversion is
  44      performed.
  45 
  46      Note that the TIMEVAL_TO_TIMESPEC and TIMESPEC_TO_TIMEVAL macros are non-
  47      standard but are commonly found on UNIX and UNIX-like systems.
  48 
  49 INTERFACE STABILITY
  50      Committed
  51 
  52 MT-LEVEL
  53      MT-Safe
  54 
  55 SEE ALSO
  56      time.h(3HEAD)
  57 
  58 illumos                        September 6, 2020                       illumos