SILC Runtime Toolkit 1.2 Beta 1
[runtime.git] / lib / silcutil / win32 / silcwin32util.c
1 /*
2
3   silcwin32util.c
4
5   Author: Pekka Riikonen <priikone@silcnet.org>
6
7   Copyright (C) 2001 - 2008 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
20 #include "silcruntime.h"
21
22 #define FILETIME_1970 0x019db1ded53e8000
23 const BYTE DWLEN = sizeof(DWORD) * 8;
24
25 /* Return current time in struct timeval. Code ripped from some xntp
26    implementation. */
27
28 int silc_gettimeofday(struct timeval *tv)
29 {
30   FILETIME ft;
31   __int64 usec;
32
33   GetSystemTimeAsFileTime(&ft);
34   usec = (__int64) ft.dwHighDateTime << DWLEN | ft.dwLowDateTime;
35   usec = (usec - FILETIME_1970) / 10;
36   tv->tv_sec  = (long) (usec / 1000000);
37   tv->tv_usec = (long) (usec % 1000000);
38
39   return 0;
40 }
41
42 char *silc_get_username(void)
43 {
44   DWORD maxlen = 128;
45   char username[128];
46   GetUserName(username, &maxlen);
47   return silc_strdup(username);
48 }
49
50 char *silc_get_real_name(void)
51 {
52   return silc_get_username();
53 }
54
55 int silc_file_set_nonblock(int fd)
56 {
57   return 0;
58 }