2010-07-31 17:09:31 -07:00
|
|
|
#include <linux/time.h>
|
2010-07-31 16:05:20 -07:00
|
|
|
|
|
|
|
#include <linux/version.h>
|
|
|
|
|
|
|
|
#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,26)
|
|
|
|
|
2010-08-30 00:24:53 -07:00
|
|
|
/* "set_normalized_timespec" is defined but not exported in kernels
|
2010-07-31 16:05:20 -07:00
|
|
|
* before 2.6.26. */
|
|
|
|
|
|
|
|
/**
|
|
|
|
* set_normalized_timespec - set timespec sec and nsec parts and normalize
|
|
|
|
*
|
|
|
|
* @ts: pointer to timespec variable to be set
|
|
|
|
* @sec: seconds to set
|
|
|
|
* @nsec: nanoseconds to set
|
|
|
|
*
|
|
|
|
* Set seconds and nanoseconds field of a timespec variable and
|
|
|
|
* normalize to the timespec storage format
|
|
|
|
*
|
|
|
|
* Note: The tv_nsec part is always in the range of
|
|
|
|
* 0 <= tv_nsec < NSEC_PER_SEC
|
|
|
|
* For negative values only the tv_sec field is negative !
|
|
|
|
*/
|
2010-08-30 00:24:53 -07:00
|
|
|
void set_normalized_timespec(struct timespec *ts,
|
2010-07-31 16:05:20 -07:00
|
|
|
time_t sec, long nsec)
|
|
|
|
{
|
|
|
|
while (nsec >= NSEC_PER_SEC) {
|
|
|
|
nsec -= NSEC_PER_SEC;
|
|
|
|
++sec;
|
|
|
|
}
|
|
|
|
while (nsec < 0) {
|
|
|
|
nsec += NSEC_PER_SEC;
|
|
|
|
--sec;
|
|
|
|
}
|
|
|
|
ts->tv_sec = sec;
|
|
|
|
ts->tv_nsec = nsec;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* linux kernel < 2.6.26 */
|