]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/ntp/libntp/tvtoa.c
This commit was generated by cvs2svn to compensate for changes in r57422,
[FreeBSD/FreeBSD.git] / contrib / ntp / libntp / tvtoa.c
1 /*
2  * tvtoa - return an asciized representation of a struct timeval
3  */
4 #include <stdio.h>
5 #include <sys/time.h>
6
7 #include "lib_strbuf.h"
8 #if defined(VMS)
9 #include "ntp_fp.h"
10 #endif /* VMS */
11 #include "ntp_stdlib.h"
12 #include "ntp_unixtime.h"
13
14 char *
15 tvtoa(
16         const struct timeval *tv
17         )
18 {
19         register char *buf;
20         register u_long sec;
21         register u_long usec;
22         register int isneg;
23
24         if (tv->tv_sec < 0 || tv->tv_usec < 0) {
25                 sec = -tv->tv_sec;
26                 usec = -tv->tv_usec;
27                 isneg = 1;
28         } else {
29                 sec = tv->tv_sec;
30                 usec = tv->tv_usec;
31                 isneg = 0;
32         }
33
34         LIB_GETBUF(buf);
35
36         (void) sprintf(buf, "%s%lu.%06lu", (isneg?"-":""), sec, usec);
37         return buf;
38 }