Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a standard way to convert a struct timeval into a struct timespec?

struct timeval represents and instant in time with two members, tv_sec (seconds) and tv_usec (microseconds). In this representation, tv_usec is not by itself an absolute time it is a sub second offset off of tv_sec.

struct timespec works the same way except that instead of microseconds it's offset (tv_nsec) is stored in nanosecond units.

The question is: Is there a standard way to convert between these two?

like image 573
dicroce Avatar asked Oct 24 '09 16:10

dicroce


1 Answers

In sys/time.h there are two macros that do what you want:

TIMEVAL_TO_TIMESPEC(X, Y)

and

TIMESPEC_TO_TIMEVAL(X, Y)

See the docs here: http://www.daemon-systems.org/man/TIMEVAL_TO_TIMESPEC.3.html

like image 66
CommanderHK Avatar answered Sep 28 '22 00:09

CommanderHK