1 /* 2 * tvtoa - return an asciized representation of a struct timeval 3 */ 4 5 #include "lib_strbuf.h" 6 7 #if defined(VMS) 8 # include "ntp_fp.h" 9 #endif /* VMS */ 10 #include "ntp_stdlib.h" 11 #include "ntp_unixtime.h" 12 13 #include <stdio.h> 14 15 char * tvtoa(const struct timeval * tv)16tvtoa( 17 const struct timeval *tv 18 ) 19 { 20 register char *buf; 21 register u_long sec; 22 register u_long usec; 23 register int isneg; 24 25 if (tv->tv_sec < 0 || tv->tv_usec < 0) { 26 sec = -tv->tv_sec; 27 usec = -tv->tv_usec; 28 isneg = 1; 29 } else { 30 sec = tv->tv_sec; 31 usec = tv->tv_usec; 32 isneg = 0; 33 } 34 35 LIB_GETBUF(buf); 36 37 (void) sprintf(buf, "%s%lu.%06lu", (isneg?"-":""), sec, usec); 38 return buf; 39 } 40