[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
RE: Windows Build Killer: lib/gettime.c
From: |
Conrad T. Pino |
Subject: |
RE: Windows Build Killer: lib/gettime.c |
Date: |
Tue, 11 May 2004 19:16:06 -0700 |
Another iteration of "windows-NT/gettime.c" idea:
/* gettime -- get the system clock
Copyright (C) 2002, 2004 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software Foundation,
Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
/* Written by Paul Eggert. */
/* Revised for Win32 API by Conrad T. Pino */
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#include "timespec.h"
#include <windows.h>
/* FILETIME unit is 100 nanoseconds */
const static long div_100_nsec = 10000000;
/* POSIX or Unix Epoch (1-Jan-1970 00:00) in FILETIME units */
const static ULONGLONG ix_epoch = 116444736000000000;
/* Get the system time. */
int
gettime( struct timespec *ts )
{
ULONGLONG diff_100_nsec;
union
{
FILETIME f;
ULARGE_INTEGER u;
} now;
GetSystemTimeAsFileTime( &now.f );
diff_100_nsec = now.u.QuadPart - ix_epoch;
ts->tv_sec = (time_t) ( diff_100_nsec / div_100_nsec );
ts->tv_nsec = (long) ( ( diff_100_nsec % div_100_nsec ) * 100l );
return 0;
}