On Mon, Oct 14, 2002 at 01:00:07AM -0400, Bruce Momjian wrote:
> Denis A Ustimenko wrote:
> > On Sun, Oct 13, 2002 at 09:02:55PM -0700, Joe Conway wrote:
> > > Denis A Ustimenko wrote:
> > > >>Bruce, why have all precise time calculations been droped out in 1.206? 
> > > >>If there is no
> > > >>gettimeofday in win32?
> > > 
> > > gettimeofday was not portable to win32 (at least not that I could find) and 
> > > hence broke the win32 build of the clients.
> > > 
> > 
> > GetSystemTimeAsFileTime should help.
> > 
> > 
>http://msdn.microsoft.com/library/default.asp?url=/library/en-us/sysinfo/base/getsystemtimeasfiletime.asp
> 
> It's not clear to me how we could get this into something we can deal
> with like gettimeofday.
> 
> I looked at the Apache APR project, and they have a routine that returns
> the microseconds since 1970 for Unix:
>       

Here is my version of gettimeofday for win32. It was tested with Watcom C 11.0c. I 
think it can be used. I still belive that fine time calculation is the right way.

#include<stdio.h>
#ifdef _WIN32
#include<winsock.h>
#else
#include<sys/time.h>
#endif

main()
{
    struct timeval t;
    if (gettimeofday(&t,NULL)) {
        printf("error\n\r");
    } else {
        printf("the time is %ld.%ld\n\r", t.tv_sec, t.tv_usec);
    }
    fflush(stdout);
}

#ifdef _WIN32
int gettimeofday(struct timeval *tp, void *tzp)
{
    FILETIME time;
    __int64 tmp;

    if ( NULL == tp) return -1;

    GetSystemTimeAsFileTime(&time);

    tmp = time.dwHighDateTime;
    tmp <<= 32;
    tmp |= time.dwLowDateTime;
    tmp /= 10; // it was in 100 nanosecond periods
    tp->tv_sec = tmp / 1000000 - 11644473600L; // Windows Epoch begins at 12:00 AM 
01.01.1601
    tp->tv_usec = tmp % 1000000;
    return 0;
}
#endif



-- 
Regards
Denis

---------------------------(end of broadcast)---------------------------
TIP 4: Don't 'kill -9' the postmaster

Reply via email to