How to convert from seconds to nanoseconds in a timeval struct?

I would suggest this:

uint64_t nanosec(struct timeval t) { /* Calculate nanoseconds in a timeval structure */ 
  return t.tv_sec * 1000000000 + t.tv_usec * 1000; 
}

Leave a Comment