Added SILC Thread Queue API
[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 - 2007 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; version 2 of the License.
12
13   This program is distributed in the hope that it will be useful,
14   but WITHOUT ANY WARRANTY; without even the implied warranty of
15   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16   GNU General Public License for more details.
17
18 */
19 /* $Id$ */
20
21 #include "silc.h"
22
23 #define FILETIME_1970 0x019db1ded53e8000
24 const BYTE DWLEN = sizeof(DWORD) * 8;
25
26 /* Return current time in struct timeval. Code ripped from some xntp
27    implementation. */
28
29 int silc_gettimeofday(struct timeval *tv)
30 {
31   FILETIME ft;
32   __int64 usec;
33
34   GetSystemTimeAsFileTime(&ft);
35   usec = (__int64) ft.dwHighDateTime << DWLEN | ft.dwLowDateTime;
36   usec = (usec - FILETIME_1970) / 10;
37   tv->tv_sec  = (long) (usec / 1000000);
38   tv->tv_usec = (long) (usec % 1000000);
39
40   return 0;
41 }
42
43 char *silc_get_username(void)
44 {
45   DWORD maxlen = 128;
46   char username[128];
47   GetUserName(username, &maxlen);
48   return silc_strdup(username);
49 }
50
51 char *silc_get_real_name(void)
52 {
53   return silc_get_username();
54 }
55
56 int silc_file_set_nonblock(int fd)
57 {
58   return 0;
59 }