addition of silc.css
[silc.git] / lib / silcutil / win32 / silcwin32util.c
1 /*
2
3   silcwin32util.c
4
5   Author: Pekka Riikonen <priikone@silcnet.org>
6
7   Copyright (C) 2001 Pekka Riikonen
8
9   This program is free software; you can redistribute it and/or modify
10   it under the terms of the GNU General Public License as published by
11   the Free Software Foundation; either version 2 of the License, or
12   (at your option) any later version.
13   
14   This program is distributed in the hope that it will be useful,
15   but WITHOUT ANY WARRANTY; without even the implied warranty of
16   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17   GNU General Public License for more details.
18
19 */
20 /* $Id$ */
21
22 #include "silcincludes.h"
23
24 #define FILETIME_1970 0x019db1ded53e8000
25 const BYTE DWLEN = sizeof(DWORD) * 8;
26
27 /* Return current time in struct timeval. Code ripped from some xntp
28    implementation on http://src.openresources.com. */
29
30 int silc_gettimeofday(struct timeval *tv)
31 {
32   FILETIME ft;
33   __int64 msec;
34   
35   GetSystemTimeAsFileTime(&ft);
36   msec = (__int64) ft.dwHighDateTime << DWLEN | ft.dwLowDateTime;
37   msec = (msec - FILETIME_1970) / 10;
38   tv->tv_sec  = (long) (msec / 1000000);
39   tv->tv_usec = (long) (msec % 1000000);
40
41   return 0;
42 }