1 /* $NetBSD: timexsup.h,v 1.2 2020/05/25 20:47:20 christos Exp $ */ 2 3 /* 4 * timexsup.h - 'struct timex' support functions 5 * 6 * Written by Juergen Perlinger (perlinger@ntp.org) for the NTP project. 7 * The contents of 'html/copyright.html' apply. 8 */ 9 #ifndef TIMEXSUP_H 10 #define TIMEXSUP_H 11 12 13 /* convert a 'long' time value (in usec or nsec) into seconds, expressed 14 * as a 'double'. If 'STA_NANO' is not defined, this will always convert 15 * from usec. ('STA_NANO' is Linux specific at the time of this 16 * writing.) 17 * 18 * If 'STA_NANO' is defined, it will be checked in 'status' to decide 19 * which time base (usec or nsec) applies for this conversion. 20 */ 21 extern double dbl_from_var_long(long lval, int status); 22 23 /* convert a 'long' time value in usec into seconds, expressed as 24 * 'double'. This function is there for pure symmetry right now -- it 25 * just casts and scales without any additional bells and whistles. 26 */ 27 extern double dbl_from_usec_long(long lval); 28 29 /* If MOD_NANO is defined, set the MOD_NANO bit in '*modes' and 30 * calculate the time stamp in nsec; otherwise, calculate the result in 31 * usec. 32 * 33 * Applies proper bounds checks and saturation on LONG_MAX/LONG_MIN to 34 * avoid undefined behaviour. 35 */ 36 extern long var_long_from_dbl(double dval, unsigned int *modes); 37 38 /* convert a 'double' time value (in seconds) into usec with proper 39 * bounds check and range clamp. 40 */ 41 extern long usec_long_from_dbl(double dval); 42 43 #endif 44 /* -*- that's all folks -*- */ 45