Skip to content

Instantly share code, notes, and snippets.

@enjoylife
Created December 27, 2012 00:15
Show Gist options
  • Save enjoylife/4384268 to your computer and use it in GitHub Desktop.
Save enjoylife/4384268 to your computer and use it in GitHub Desktop.
convert timespec structures to timeval and vice versa.
#ifndef TIMEVAL_TO_TIMESPEC
#define TIMEVAL_TO_TIMESPEC(tv, ts) \
do { \
(ts)->tv_sec = (tv)->tv_sec; \
(ts)->tv_nsec = (tv)->tv_usec * 1000; \
} while (0)
#endif
#ifndef TIMESPEC_TO_TIMEVAL
#define TIMESPEC_TO_TIMEVAL(tv, ts) \
do { \
(tv)->tv_sec = (ts)->tv_sec; \
(tv)->tv_usec = (ts)->tv_nsec / 1000; \
} while (0)
#endif
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment