xref: /netbsd-src/external/bsd/ntp/dist/libntp/humandate.c (revision 7788a0781fe6ff2cce37368b4578a7ade0850cb1)
1 /*	$NetBSD: humandate.c,v 1.3 2012/02/01 07:46:22 kardel Exp $	*/
2 
3 /*
4  * humandate - convert an NTP (or the current) time to something readable
5  */
6 #include <stdio.h>
7 #include "ntp_fp.h"
8 #include "ntp_unixtime.h"	/* includes <sys/time.h> and <time.h> */
9 #include "lib_strbuf.h"
10 #include "ntp_stdlib.h"
11 
12 extern const char *months[];	/* prettydate.c */
13 
14 /* This is used in msyslog.c; we don't want to clutter up the log with
15    the year and day of the week, etc.; just the minimal date and time.  */
16 
17 const char *
18 humanlogtime(void)
19 {
20 	char *		bp;
21 	time_t		cursec;
22 	struct tm *	tm;
23 
24 	cursec = time(NULL);
25 	tm = localtime(&cursec);
26 	if (!tm)
27 		return "-- --- --:--:--";
28 
29 	LIB_GETBUF(bp);
30 
31 	snprintf(bp, LIB_BUFLENGTH, "%2d %s %02d:%02d:%02d",
32 		 tm->tm_mday, months[tm->tm_mon],
33 		 tm->tm_hour, tm->tm_min, tm->tm_sec);
34 
35 	return bp;
36 }
37