]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - win/inspircd_win32wrapper.h
OOPS! We try again, since I'm smoking craq. LF is 0x0a NOT CR.
[user/henk/code/inspircd.git] / win / inspircd_win32wrapper.h
1 /*       +------------------------------------+
2  *       | Inspire Internet Relay Chat Daemon |
3  *       +------------------------------------+
4  *
5  *  InspIRCd: (C) 2002-2007 InspIRCd Development Team
6  * See: http://www.inspircd.org/wiki/index.php/Credits
7  *
8  * This program is free but copyrighted software; see
9  *            the file COPYING for details.
10  *
11  * ---------------------------------------------------
12  */
13
14 /* Windows Port
15    Wrapper Functions/Definitions
16    By Burlex */
17
18 #ifndef INSPIRCD_WIN32WRAPPER_H
19 #define INSPIRCD_WIN32WRAPPER_H
20
21 /* Define the WINDOWS macro. This means we're building on windows to the rest of the server.
22    I think this is more reasonable than using WIN32, especially if we're gonna be doing 64-bit compiles */
23 #define WINDOWS 1
24
25 /* Make builds smaller, leaner and faster */
26 #define VC_EXTRALEAN
27
28 /* They just have to be *different*, don't they. */
29 #define PATH_MAX MAX_PATH
30
31 /* Begone shitty 'safe STL' warnings */
32 #define _SCL_SECURE_NO_WARNINGS
33 #define _CRT_SECURE_NO_WARNINGS
34 #define _AFX_SECURE_NO_WARNINGS
35 #define _ATL_SECURE_NO_WARNINGS
36
37 /* Macros for exporting symbols - dependant on what is being compiled */
38
39 #ifdef DLL_BUILD
40 #define CoreExport __declspec(dllimport)
41 #define DllExport __declspec(dllexport)
42 #else
43 #define CoreExport __declspec(dllexport)
44 #define DllExport __declspec(dllimport)
45 #endif
46
47 /* Disable the deprecation warnings.. it spams :P */
48 #define _CRT_SECURE_NO_DEPRECATE
49 #define _SCL_SECURE_NO_DEPRECATE
50
51 #include <string>
52
53 /* Say we're building on windows 2000. Anyone running something older than this
54  * reeeeeeeally needs to upgrade! */
55
56 #define _WIN32_WINNT 0x500
57
58 /* Normal windows (platform-specific) includes */
59 #include <winsock2.h>
60 #include <windows.h>
61 #include <ws2tcpip.h>
62 #include <sys/types.h>
63 #include <sys/stat.h>
64 #include <direct.h>
65 #include <process.h>
66 #include <stdio.h>
67 #include <algorithm>
68
69 /* strcasecmp is not defined on windows by default */
70 #define strcasecmp _stricmp
71
72 /* Error macros need to be redirected to winsock error codes */
73 #define ETIMEDOUT WSAETIMEDOUT
74 #define ECONNREFUSED WSAECONNREFUSED
75 #define EADDRINUSE WSAEADDRINUSE
76 #define EINPROGRESS WSAEWOULDBLOCK
77
78 /* Remember file descriptors are treated differently on windows ;) */
79 __inline int close(int socket) { return closesocket(socket); }
80
81 /* Convert formatted (xxx.xxx.xxx.xxx) string to in_addr struct */
82 CoreExport int inet_pton(int af, const char * src, void * dst);
83
84 /* Convert struct to formatted (xxx.xxx.xxx.xxx) string */
85 CoreExport const char * inet_ntop(int af, const void * src, char * dst, socklen_t cnt);
86
87 /* Safe printf functions aren't defined in VC2003 */
88 #define snprintf _snprintf
89 #define vsnprintf _vsnprintf
90
91 /* Recursive token function doesn't exist in VC++ */
92 CoreExport char * strtok_r(char *_String, const char *_Control, char **_Context);
93
94 /* Unix-style sleep (argument is in seconds) */
95 __inline void sleep(int seconds) { Sleep(seconds * 1000); }
96
97 /* IPV4 only convert string to address struct */
98 CoreExport int inet_aton(const char *, struct in_addr *);
99
100 /* Unix-style get running user id */
101 CoreExport int geteuid();
102
103 /* Handles colors in printf */
104 CoreExport int printf_c(const char * format, ...);
105
106 /* getopt() wrapper */
107 # define no_argument            0
108 # define required_argument      1
109 # define optional_argument      2
110 struct option
111 {
112         char *name;
113         int has_arg;
114         int *flag;
115         int val;
116 };
117 extern char optarg[514];
118 int getopt_long_only (int ___argc, char *const *___argv, const char *__shortopts, const struct option *__longopts, int *__longind);
119
120 /* Accept Handlers */
121 struct udp_overlap;
122 CoreExport int __accept_socket(SOCKET s, sockaddr * addr, int * addrlen, void * acceptevent);
123 CoreExport int __getsockname(SOCKET s, sockaddr * name, int * namelen, void * acceptevent);
124 CoreExport int __recvfrom(SOCKET s, char * buf, int len, int flags, struct sockaddr * from, int * fromlen, udp_overlap * ov);
125
126 /* Module Loading */
127 #define dlopen(path, state) (void*)LoadLibrary(path)
128 #define dlsym(handle, export) (void*)GetProcAddress((HMODULE)handle, export)
129 #define dlclose(handle) FreeLibrary((HMODULE)handle)
130 const char * dlerror();
131
132 /* Unix-style directory searching functions */
133 #define chmod(filename, mode)  
134 struct dirent
135 {
136         char d_name[MAX_PATH];
137 };
138
139 struct DIR
140 {
141         dirent dirent_pointer;
142         HANDLE find_handle;
143         WIN32_FIND_DATA find_data;
144         bool first;
145 };
146
147 CoreExport DIR * opendir(const char * path);
148 CoreExport dirent * readdir(DIR * handle);
149 CoreExport void closedir(DIR * handle);
150
151 /* Disable these stupid warnings.. */
152 #pragma warning(disable:4800)
153 #pragma warning(disable:4251)
154 #pragma warning(disable:4275)
155 #pragma warning(disable:4244)           // warning C4244: '=' : conversion from 'long' to 'short', possible loss of data
156 #pragma warning(disable:4267)           // warning C4267: 'argument' : conversion from 'size_t' to 'int', possible loss of data
157 #pragma warning(disable:4805)           // warning C4805: '!=' : unsafe mix of type 'char' and type 'bool' in operation
158 #pragma warning(disable:4311)           // warning C4311: 'type cast' : pointer truncation from 'accept_overlap *' to 'int'
159 #pragma warning(disable:4312)           // warning C4312: 'type cast' : conversion from 'int' to 'HANDLE' of greater size
160 #pragma warning(disable:4355)           // warning C4355: 'this' : used in base member initializer list
161 #pragma warning(disable:4996)           // warning C4996: 'std::_Traits_helper::move_s' was declared deprecated
162
163 /* Mehhhh... typedefs. */
164
165 typedef unsigned char uint8_t;
166 typedef unsigned long long uint64_t;
167 typedef signed char int8_t;
168 typedef signed long int32_t;
169 typedef signed long long int64_t;
170
171 /* Shared memory allocation functions */
172 void * ::operator new(size_t iSize);
173 void ::operator delete(void * ptr);
174
175 /* IPC Handlers */
176 class InspIRCd;
177
178 void InitIPC();
179 void CheckIPC(InspIRCd * Instance);
180 void CloseIPC();
181
182 /* Look up the nameserver in use from the registry on windows */
183 std::string FindNameServerWin();
184
185 /* Clear a windows console */
186 void ClearConsole();
187
188 #endif
189