FreeBSD/contrib/ntp/sntp/utilities.c
/*
 * Converts a struct tv to a date string
 */
Converts a struct tv to a date string
Converts a struct tv to a date string
char *
tv_to_str(
	const struct timeval *tv
	)
{
	const size_t bufsize = 48;
	char *buf;
	time_t gmt_time, local_time;
	struct tm *p_tm_local;
	int hh, mm, lto;
	gmt_time = tv->tv_sec;
	local_time = mktime(gmtime(&gmt_time));
	p_tm_local = localtime(&gmt_time);
	lto = difftime(local_time, gmt_time);
	lto /= 60;
	hh = lto / 60;
	mm = abs(lto % 60);
	buf = emalloc(bufsize);
	snprintf(buf, bufsize,
		 "%d-%.2d-%.2d %.2d:%.2d:%.2d.%.6d (%+03d%02d)",
		 p_tm_local->tm_year + 1900,
		 p_tm_local->tm_mon + 1,
		 p_tm_local->tm_mday,
		 p_tm_local->tm_hour,
		 p_tm_local->tm_min,
		 p_tm_local->tm_sec,
		 (int)tv->tv_usec,
		 hh,
		 mm);
	return buf;
}
char * tv_to_str ( const struct timeval * tv ) { const size_t bufsize = 48 ; char * buf ; time_t gmt_time , local_time ; struct tm * p_tm_local ; int hh , mm , lto ; gmt_time = tv -> tv_sec ; local_time = mktime ( gmtime ( & gmt_time ) ) ; p_tm_local = localtime ( & gmt_time ) ; lto = difftime ( local_time , gmt_time ) ; lto /= 60 ; hh = lto / 60 ; mm = abs ( lto % 60 ) ; buf = emalloc ( bufsize ) ; snprintf ( buf , bufsize , " " , p_tm_local -> tm_year + 1900 , p_tm_local -> tm_mon + 1 , p_tm_local -> tm_mday , p_tm_local -> tm_hour , p_tm_local -> tm_min , p_tm_local -> tm_sec , ( int ) tv -> tv_usec , hh , mm ) ; return buf ; }
Converts a struct tv to a date string
Converts a struct tv to a date string
/*
	 * convert to struct tm in UTC, then intentionally feed
	 * that tm to mktime() which expects local time input, to
	 * derive the offset from UTC to local time.
	 */ /* Local timezone offsets should never cause an overflow.  Yeah. */