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