2
0
mirror of https://github.com/openvswitch/ovs synced 2025-09-05 16:55:42 +00:00
Files
ovs/datapath/linux/compat/time.c
Jesse Gross 22bcc0e70b datapath: Rename linux-2.6 and compat-2.6 directories.
The linux-2.6 and compat-2.6 directories apply equally to the upcoming
Linux 3.0 release, so this drops the 2.6 suffix and updates Makefiles.

Signed-off-by: Jesse Gross <jesse@nicira.com>
Acked-by: Ben Pfaff <blp@nicira.com>
2011-06-24 14:37:49 -07:00

40 lines
956 B
C

#include <linux/time.h>
#include <linux/version.h>
#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,26)
/* "set_normalized_timespec" is defined but not exported in kernels
* 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 !
*/
void set_normalized_timespec(struct timespec *ts,
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 */