gettimeofday.c

来自「加密认证联合模式的源代码」· C语言 代码 · 共 30 行

C
30
字号

#include <windows.h>
#include <errno.h>

static unsigned long long filetime_to_unix_epoch( const FILETIME *ft )
{
    unsigned long long res = (unsigned long long) ft->dwHighDateTime << 32;
    res |= ft->dwLowDateTime;
    res /= 10;
    res -= 11644473600000000ULL;	/* from Win epoch to Unix epoch */
    return res;
}

int gettimeofday( struct timeval *tv, void *tz )
{
    FILETIME  ft;
    unsigned long long tim;

    if(!tv)
    {
        errno = EINVAL; return -1;
    }

    GetSystemTimeAsFileTime (&ft);
    tim = filetime_to_unix_epoch (&ft);
    tv->tv_sec  = (long) (tim / 1000000L);
    tv->tv_usec = (long) (tim % 1000000L);
    return 0;
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?