xref: /netbsd-src/external/bsd/ntp/dist/include/timexsup.h (revision cdfa2a7ef92791ba9db70a584a1d904730e6fb46)
1*cdfa2a7eSchristos /*	$NetBSD: timexsup.h,v 1.2 2020/05/25 20:47:20 christos Exp $	*/
2067f5680Schristos 
3067f5680Schristos /*
4067f5680Schristos  * timexsup.h - 'struct timex' support functions
5067f5680Schristos  *
6067f5680Schristos  * Written by Juergen Perlinger (perlinger@ntp.org) for the NTP project.
7067f5680Schristos  * The contents of 'html/copyright.html' apply.
8067f5680Schristos  */
9067f5680Schristos #ifndef TIMEXSUP_H
10067f5680Schristos #define TIMEXSUP_H
11067f5680Schristos 
12067f5680Schristos 
13067f5680Schristos /* convert a 'long' time value (in usec or nsec) into seconds, expressed
14067f5680Schristos  * as a 'double'. If 'STA_NANO' is not defined, this will always convert
15067f5680Schristos  * from usec. ('STA_NANO' is Linux specific at the time of this
16067f5680Schristos  * writing.)
17067f5680Schristos  *
18067f5680Schristos  * If 'STA_NANO' is defined, it will be checked in 'status' to decide
19067f5680Schristos  * which time base (usec or nsec) applies for this conversion.
20067f5680Schristos  */
21067f5680Schristos extern double dbl_from_var_long(long lval, int status);
22067f5680Schristos 
23067f5680Schristos /* convert a 'long' time value in usec into seconds, expressed as
24067f5680Schristos  * 'double'.  This function is there for pure symmetry right now -- it
25067f5680Schristos  * just casts and scales without any additional bells and whistles.
26067f5680Schristos  */
27067f5680Schristos extern double dbl_from_usec_long(long lval);
28067f5680Schristos 
29067f5680Schristos /* If MOD_NANO is defined, set the MOD_NANO bit in '*modes' and
30067f5680Schristos  * calculate the time stamp in nsec; otherwise, calculate the result in
31067f5680Schristos  * usec.
32067f5680Schristos  *
33067f5680Schristos  * Applies proper bounds checks and saturation on LONG_MAX/LONG_MIN to
34067f5680Schristos  * avoid undefined behaviour.
35067f5680Schristos  */
36067f5680Schristos extern long var_long_from_dbl(double dval, unsigned int *modes);
37067f5680Schristos 
38067f5680Schristos /* convert a 'double' time value (in seconds) into usec with proper
39067f5680Schristos  * bounds check and range clamp.
40067f5680Schristos  */
41067f5680Schristos extern long usec_long_from_dbl(double dval);
42067f5680Schristos 
43067f5680Schristos #endif
44067f5680Schristos /* -*- that's all folks -*- */
45