1262617Sdelphij/****************************************************************************
2262617Sdelphij * Copyright (c) 2008,2010 Free Software Foundation, Inc.                   *
3262617Sdelphij *                                                                          *
4262617Sdelphij * Permission is hereby granted, free of charge, to any person obtaining a  *
5262617Sdelphij * copy of this software and associated documentation files (the            *
6262617Sdelphij * "Software"), to deal in the Software without restriction, including      *
7262617Sdelphij * without limitation the rights to use, copy, modify, merge, publish,      *
8262617Sdelphij * distribute, distribute with modifications, sublicense, and/or sell       *
9262617Sdelphij * copies of the Software, and to permit persons to whom the Software is    *
10262617Sdelphij * furnished to do so, subject to the following conditions:                 *
11262617Sdelphij *                                                                          *
12262617Sdelphij * The above copyright notice and this permission notice shall be included  *
13262617Sdelphij * in all copies or substantial portions of the Software.                   *
14262617Sdelphij *                                                                          *
15262617Sdelphij * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS  *
16262617Sdelphij * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF               *
17262617Sdelphij * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.   *
18262617Sdelphij * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,   *
19262617Sdelphij * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR    *
20262617Sdelphij * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR    *
21262617Sdelphij * THE USE OR OTHER DEALINGS IN THE SOFTWARE.                               *
22262617Sdelphij *                                                                          *
23262617Sdelphij * Except as contained in this notice, the name(s) of the above copyright   *
24262617Sdelphij * holders shall not be used in advertising or otherwise to promote the     *
25262617Sdelphij * sale, use or other dealings in this Software without prior written       *
26262617Sdelphij * authorization.                                                           *
27262617Sdelphij ****************************************************************************/
28262617Sdelphij
29262617Sdelphij#define WINVER 0x0501
30262617Sdelphij
31262617Sdelphij#include <curses.priv.h>
32262617Sdelphij
33262617Sdelphij#include <windows.h>
34262617Sdelphij
35262617SdelphijMODULE_ID("$Id: gettimeofday.c,v 1.2 2010/01/16 15:18:51 tom Exp $")
36262617Sdelphij
37262617Sdelphij#define JAN1970 116444736000000000LL	/* the value for 01/01/1970 00:00 */
38262617Sdelphij
39262617Sdelphijint
40262617Sdelphijgettimeofday(struct timeval *tv, void *tz GCC_UNUSED)
41262617Sdelphij{
42262617Sdelphij    union {
43262617Sdelphij	FILETIME ft;
44262617Sdelphij	long long since1601;	/* time since 1 Jan 1601 in 100ns units */
45262617Sdelphij    } data;
46262617Sdelphij
47262617Sdelphij    GetSystemTimeAsFileTime(&data.ft);
48262617Sdelphij    tv->tv_usec = (long) ((data.since1601 / 10LL) % 1000000LL);
49262617Sdelphij    tv->tv_sec = (long) ((data.since1601 - JAN1970) / 10000000LL);
50262617Sdelphij    return (0);
51262617Sdelphij}
52