[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 17:26:06 -0700 |
Hi Derek,
> From: Derek Robert Price
>
> Please bring this up on the bug-gnulib@gnu.org mailing list. They may
> know what we're missing or be interested in updating gettime.c to run
> on Windows.
OK. There'll be a delay while I get subscribed.
In the meantime please see what "windows-NT/gettime.c" might be below.
Untested and the constants may be off but the logic should be correct.
> Derek
Conrad
/* 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>
/* POSIX or Unix Epoch */
const static SYSTEMTIME s_ix_epoch =
{
1970, /* year */
1, /* month, Jan=1 */
4, /* day of week, Thursday=4 */
1, /* day of month */
0, /* hour */
0, /* minute */
0, /* second */
0 /* millisecond */
};
typedef union
{
FILETIME f;
ULARGE_INTEGER u;
} FT_ULI;
static FT_ULI ix_epoch;
/* Get the system time. */
int
gettime( struct timespec *ts )
{
FT_ULI now;
ULONGLONG diff_100_nsec;
const static div_100_nsec = 10000000l;
if ( ix_epoch.u.QuadPart == 0 )
{
SystemTimeToFileTime( &s_ix_epoch, &ix_epoch.f );
}
GetSystemTimeAsFileTime( &now.f );
/* FILETIME unit is 100 nanoseconds */
diff_100_nsec = now.u.QuadPart - ix_epoch.u.QuadPart;
ts->tv_sec = (time_t) ( diff_100_nsec / div_100_nsec );
ts->tv_nsec = (long) ( ( diff_100_nsec % div_100_nsec ) * 100l );
return 0;
}