Annotation of embedaddon/ntp/libntp/uglydate.c, revision 1.1

1.1     ! misho       1: /*
        !             2:  * uglydate - convert a time stamp to something barely readable
        !             3:  *           The string returned is 37 characters long.
        !             4:  */
        !             5: #include <stdio.h>
        !             6: 
        !             7: #include "ntp_fp.h"
        !             8: #include "ntp_unixtime.h"
        !             9: #include "lib_strbuf.h"
        !            10: #include "ntp_stdlib.h"
        !            11: 
        !            12: 
        !            13: char *
        !            14: uglydate(
        !            15:        l_fp *ts
        !            16:        )
        !            17: {
        !            18:        char *bp;
        !            19:        char *timep;
        !            20:        struct tm *tm;
        !            21:        time_t sec;
        !            22:        long msec;
        !            23:        int year;
        !            24: 
        !            25:        timep = ulfptoa(ts, 6);         /* returns max 17 characters */
        !            26:        LIB_GETBUF(bp);
        !            27:        sec = ts->l_ui - JAN_1970;
        !            28:        msec = ts->l_uf / 4294967;      /* fract / (2**32/1000) */
        !            29:        tm = gmtime(&sec);
        !            30:        if (ts->l_ui == 0) {
        !            31:                /*
        !            32:                 * Probably not a real good thing to do.  Oh, well.
        !            33:                 */
        !            34:                year = 0;
        !            35:                tm->tm_yday = 0;
        !            36:                tm->tm_hour = 0;
        !            37:                tm->tm_min = 0;
        !            38:                tm->tm_sec = 0;
        !            39:        } else {
        !            40:                year = tm->tm_year;
        !            41:                while (year >= 100)
        !            42:                    year -= 100;
        !            43:        }
        !            44:        snprintf(bp, LIB_BUFLENGTH,
        !            45:                 "%17s %02d:%03d:%02d:%02d:%02d.%03ld", timep, year,
        !            46:                 tm->tm_yday, tm->tm_hour, tm->tm_min, tm->tm_sec,
        !            47:                 msec);
        !            48: 
        !            49:        return bp;
        !            50: }

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>