Annotation of embedaddon/ntp/ports/winnt/libntp/getclock.c, revision 1.1

1.1     ! misho       1: /*
        !             2:  * getclock.c - Emulate Unix getclock(3) nanosecond interface for libntp/ntpd
        !             3:  */
        !             4: #include "config.h"
        !             5: #include "clockstuff.h"
        !             6: #include "ntp_stdlib.h"
        !             7: 
        !             8: /*
        !             9:  * getclock() is in libntp.  To use interpolation, 
        !            10:  * ports/winnt/ntpd/nt_clockstuff.c overrides GetSystemTimeAsFileTime 
        !            11:  * via the pointer get_sys_time_as_filetime.
        !            12:  */
        !            13: PGSTAFT get_sys_time_as_filetime;
        !            14: 
        !            15: int
        !            16: getclock(
        !            17:        int             clktyp,
        !            18:        struct timespec *ts
        !            19:        )
        !            20: {
        !            21:        union {
        !            22:                FILETIME ft;
        !            23:                ULONGLONG ull;
        !            24:        } uNow;
        !            25: 
        !            26:        if (clktyp != TIMEOFDAY) {
        !            27: #ifdef DEBUG
        !            28:                if (debug) {
        !            29:                        printf("getclock() supports only TIMEOFDAY clktyp\n");
        !            30:                }
        !            31: #endif
        !            32:                errno = EINVAL;
        !            33:                return -1;
        !            34:        }
        !            35: 
        !            36:        if (! get_sys_time_as_filetime)
        !            37:                get_sys_time_as_filetime = GetSystemTimeAsFileTime;
        !            38: 
        !            39:        (*get_sys_time_as_filetime)(&uNow.ft);
        !            40: 
        !            41:        /* 
        !            42:         * Convert the hecto-nano second time to timespec format
        !            43:         */
        !            44:        uNow.ull -= FILETIME_1970;
        !            45:        ts->tv_sec = (time_t)( uNow.ull / HECTONANOSECONDS);
        !            46:        ts->tv_nsec = (long)(( uNow.ull % HECTONANOSECONDS) * 100);
        !            47: 
        !            48:        return 0;
        !            49: }

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