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