summaryrefslogtreecommitdiffstats
path: root/contrib/ntp/libntp/tvtoa.c
blob: 19d4a94ed1d5ec4f5a87b881efb71a57ab5db90e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
/*
 * tvtoa - return an asciized representation of a struct timeval
 */

#include "lib_strbuf.h"

#if defined(VMS)
# include "ntp_fp.h"
#endif /* VMS */
#include "ntp_stdlib.h"
#include "ntp_unixtime.h"

#include <stdio.h>

char *
tvtoa(
	const struct timeval *tv
	)
{
	register char *buf;
	register u_long sec;
	register u_long usec;
	register int isneg;

	if (tv->tv_sec < 0 || tv->tv_usec < 0) {
		sec = -tv->tv_sec;
		usec = -tv->tv_usec;
		isneg = 1;
	} else {
		sec = tv->tv_sec;
		usec = tv->tv_usec;
		isneg = 0;
	}

	LIB_GETBUF(buf);

	(void) sprintf(buf, "%s%lu.%06lu", (isneg?"-":""), sec, usec);
	return buf;
}
OpenPOWER on IntegriCloud