summaryrefslogtreecommitdiff
path: root/src/lib/evil/evil_main.c
diff options
context:
space:
mode:
authorVincent Torri <vincent.torri@gmail.com>2012-09-11 16:13:11 +0000
committerVincent Torri <vincent.torri@gmail.com>2012-09-11 16:13:11 +0000
commitcd69ef4c8a66e7155967a8b661a014856979cf31 (patch)
tree4a351ae4a4ca91abf29c85254b85ea8da71f74b0 /src/lib/evil/evil_main.c
parent59a9dfd11860888a35e96dfe51af63cea5cecfe1 (diff)
merge: add evil files
SVN revision: 76464
Diffstat (limited to 'src/lib/evil/evil_main.c')
-rw-r--r--src/lib/evil/evil_main.c74
1 files changed, 74 insertions, 0 deletions
diff --git a/src/lib/evil/evil_main.c b/src/lib/evil/evil_main.c
new file mode 100644
index 0000000..ee1eb1d
--- /dev/null
+++ b/src/lib/evil/evil_main.c
@@ -0,0 +1,74 @@
1#ifdef HAVE_CONFIG_H
2# include <config.h>
3#endif
4
5#ifndef WIN32_LEAN_AND_MEAN
6# define WIN32_LEAN_AND_MEAN
7#endif
8#include <winsock2.h>
9#undef WIN32_LEAN_AND_MEAN
10
11#include "Evil.h"
12#include "evil_private.h"
13
14
15static int _evil_init_count = 0;
16
17extern LONGLONG _evil_time_freq;
18extern LONGLONG _evil_time_count;
19extern long _evil_time_second;
20
21int
22evil_init(void)
23{
24 SYSTEMTIME st;
25 LARGE_INTEGER freq;
26 LARGE_INTEGER count;
27 WORD second = 59;
28
29 if (++_evil_init_count != 1)
30 return _evil_init_count;
31
32 if (!QueryPerformanceFrequency(&freq))
33 return 0;
34
35 _evil_time_freq = freq.QuadPart;
36
37 /* be sure that second + 1 != 0 */
38 while (second == 59)
39 {
40 GetSystemTime(&st);
41 second = st.wSecond;
42 }
43
44 /* retrieve the tick corresponding to the time we retrieve above */
45 while (1)
46 {
47 GetSystemTime(&st);
48 QueryPerformanceCounter(&count);
49 if (st.wSecond == second + 1)
50 break;
51 }
52
53 _evil_time_second = _evil_systemtime_to_time(st);
54 if (_evil_time_second < 0)
55 return --_evil_init_count;
56
57 _evil_time_count = count.QuadPart;
58
59 if (!evil_sockets_init())
60 return --_evil_init_count;
61
62 return _evil_init_count;
63}
64
65int
66evil_shutdown(void)
67{
68 if (--_evil_init_count != 0)
69 return _evil_init_count;
70
71 evil_sockets_shutdown();
72
73 return _evil_init_count;
74}