datapath: Remove reciprocal_div compat code.
[sliver-openvswitch.git] / datapath / linux / compat / time.c
1 #include <linux/time.h>
2
3 #include <linux/version.h>
4
5 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,26)
6
7 /* "set_normalized_timespec" is defined but not exported in kernels
8  * before 2.6.26. */
9
10 /**
11  * set_normalized_timespec - set timespec sec and nsec parts and normalize
12  *
13  * @ts:         pointer to timespec variable to be set
14  * @sec:        seconds to set
15  * @nsec:       nanoseconds to set
16  *
17  * Set seconds and nanoseconds field of a timespec variable and
18  * normalize to the timespec storage format
19  *
20  * Note: The tv_nsec part is always in the range of
21  *      0 <= tv_nsec < NSEC_PER_SEC
22  * For negative values only the tv_sec field is negative !
23  */
24 void set_normalized_timespec(struct timespec *ts,
25                              time_t sec, long nsec)
26 {
27         while (nsec >= NSEC_PER_SEC) {
28                 nsec -= NSEC_PER_SEC;
29                 ++sec;
30         }
31         while (nsec < 0) {
32                 nsec += NSEC_PER_SEC;
33                 --sec;
34         }
35         ts->tv_sec = sec;
36         ts->tv_nsec = nsec;
37 }
38
39 #endif /* linux kernel < 2.6.26 */