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