diff options
author | roberto <roberto@FreeBSD.org> | 1999-12-09 13:01:21 +0000 |
---|---|---|
committer | roberto <roberto@FreeBSD.org> | 1999-12-09 13:01:21 +0000 |
commit | ef64b99e8412f2273dd2e8b3291c2f78ffc4667f (patch) | |
tree | fc0cfa1aab0ff6b228f511b410733ef4f35d1ead /contrib/ntp/libntp/uglydate.c | |
download | FreeBSD-src-ef64b99e8412f2273dd2e8b3291c2f78ffc4667f.zip FreeBSD-src-ef64b99e8412f2273dd2e8b3291c2f78ffc4667f.tar.gz |
Virgin import of ntpd 4.0.98f
Diffstat (limited to 'contrib/ntp/libntp/uglydate.c')
-rw-r--r-- | contrib/ntp/libntp/uglydate.c | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/contrib/ntp/libntp/uglydate.c b/contrib/ntp/libntp/uglydate.c new file mode 100644 index 0000000..fcd3d9f --- /dev/null +++ b/contrib/ntp/libntp/uglydate.c @@ -0,0 +1,50 @@ +/* + * uglydate - convert a time stamp to something barely readable + * The string returned is 37 characters long. + */ +#include <stdio.h> + +#include "ntp_fp.h" +#include "ntp_unixtime.h" +#include "lib_strbuf.h" +#include "ntp_stdlib.h" +#ifndef TM_IN_SYS_TIME +#include <time.h> +#endif + +char * +uglydate( + l_fp *ts + ) +{ + char *bp; + char *timep; + struct tm *tm; + time_t sec; + long msec; + int year; + + timep = ulfptoa(ts, 6); /* returns max 17 characters */ + LIB_GETBUF(bp); + sec = ts->l_ui - JAN_1970; + msec = ts->l_uf / 4294967; /* fract / (2**32/1000) */ + tm = gmtime(&sec); + if (ts->l_ui == 0) { + /* + * Probably not a real good thing to do. Oh, well. + */ + year = 0; + tm->tm_yday = 0; + tm->tm_hour = 0; + tm->tm_min = 0; + tm->tm_sec = 0; + } else { + year = tm->tm_year; + while (year >= 100) + year -= 100; + } + (void) sprintf(bp, "%17s %02d:%03d:%02d:%02d:%02d.%03ld", + timep, year, tm->tm_yday, tm->tm_hour, tm->tm_min, + tm->tm_sec, msec); + return bp; +} |