pastebin - collaborative debugging tool
rovema.kpaste.net RSS


timespec to nanoseconds
Posted by Anonymous on Tue 2nd Nov 2021 10:29
raw | new post

  1. signed long long timespec2ns(struct timespec *ts)
  2. {
  3.         signed long long ns;
  4.  
  5.         ns = ts->tv_nsec + (ts->tv_sec * NSEC_PER_SEC);
  6.        
  7.         return(ns);
  8. }
  9.  
  10. void ns2timespec(signed long long ns, struct timespec *ts)
  11. {
  12.         lldiv_t lld;
  13.  
  14.         lld = lldiv(ns, NSEC_PER_SEC);
  15.         ts->tv_sec  = lld.quot;
  16.         ts->tv_nsec = lld.rem;
  17. }

Submit a correction or amendment below (click here to make a fresh posting)
After submitting an amendment, you'll be able to view the differences between the old and new posts easily.

Syntax highlighting:

To highlight particular lines, prefix each line with {%HIGHLIGHT}




All content is user-submitted.
The administrators of this site (kpaste.net) are not responsible for their content.
Abuse reports should be emailed to us at