humandate.c revision 1.2
1/* $NetBSD: humandate.c,v 1.2 2010/12/04 23:08:34 christos 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 12extern 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 17const char * 18humanlogtime(void) 19{ 20 char *bp; 21 time_t cursec = time((time_t *) 0); 22 struct tm *tm; 23 24 tm = localtime(&cursec); 25 if (!tm) 26 return "-- --- --:--:--"; 27 28 LIB_GETBUF(bp); 29 30 (void) sprintf(bp, "%2d %s %02d:%02d:%02d", 31 tm->tm_mday, months[tm->tm_mon], 32 tm->tm_hour, tm->tm_min, tm->tm_sec); 33 34 return bp; 35} 36