Added SILC Server library.
[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 - 2005 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 /* XXX GNU regex may work on Win32 too!! */
24 char *silc_string_regexify(const char *string)
25 {
26   return strdup(string);
27 }
28
29 char *silc_string_regex_combine(const char *string1, const char *string2)
30 {
31   return strdup(string1);
32 }
33
34 int silc_string_regex_match(const char *regex, const char *string)
35 {
36   return TRUE;
37 }
38
39 int silc_string_match(const char *string1, const char *string2)
40 {
41   return TRUE;
42 }
43
44 #define FILETIME_1970 0x019db1ded53e8000
45 const BYTE DWLEN = sizeof(DWORD) * 8;
46
47 /* Return current time in struct timeval. Code ripped from some xntp
48    implementation on http://src.openresources.com. */
49
50 int silc_gettimeofday(struct timeval *tv)
51 {
52   FILETIME ft;
53   __int64 msec;
54   
55   GetSystemTimeAsFileTime(&ft);
56   msec = (__int64) ft.dwHighDateTime << DWLEN | ft.dwLowDateTime;
57   msec = (msec - FILETIME_1970) / 10;
58   tv->tv_sec  = (long) (msec / 1000000);
59   tv->tv_usec = (long) (msec % 1000000);
60
61   return 0;
62 }
63
64 char *silc_get_username(void)
65 {
66   DWORD maxlen = 128;
67   char username[128];
68   GetUserName(username, &maxlen);
69   return strdup(username);
70 }
71
72 char *silc_get_real_name(void)
73 {
74   return silc_get_username();
75 }
76
77 int silc_file_set_nonblock(int fd)
78 {
79   return fcntl(fd, F_SETFL, fcntl(fd, F_GETFL, 0) | O_NONBLOCK);
80 }