2 * InspIRCd -- Internet Relay Chat Daemon
4 * Copyright (C) 2007 Dennis Friis <peavey@inspircd.org>
5 * Copyright (C) 2007 Craig Edwards <craigedwards@brainbox.cc>
6 * Copyright (C) 2007 Robin Burchell <robin+git@viroteck.net>
8 * This file is part of InspIRCd. InspIRCd is free software: you can
9 * redistribute it and/or modify it under the terms of the GNU General Public
10 * License as published by the Free Software Foundation, version 2.
12 * This program is distributed in the hope that it will be useful, but WITHOUT
13 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
14 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
23 Wrapper Functions/Definitions
26 #ifndef INSPIRCD_WIN32WRAPPER_H
27 #define INSPIRCD_WIN32WRAPPER_H
30 * Starting with PSAPI version 2 for Windows 7 and Windows Server 2008 R2, this function is defined as K32GetProcessMemoryInfo in Psapi.h and exported
31 * in Kernel32.lib and Kernel32.dll. However, you should always call this function as GetProcessMemoryInfo. To ensure correct resolution of symbols
32 * for programs that will run on earlier versions ofWindows, add Psapi.lib to the TARGETLIBS macro and compile the program with PSAPI_VERSION=1.
34 * We do this before anything to make sure it's done.
36 #define PSAPI_VERSION 1
38 #ifndef CONFIGURE_BUILD
39 #include "win32service.h"
42 /* Define the WINDOWS macro. This means we're building on windows to the rest of the server.
43 I think this is more reasonable than using WIN32, especially if we're gonna be doing 64-bit compiles */
45 #define ENABLE_CRASHDUMPS 0
47 /* This defaults to 64, way too small for an ircd! */
48 /* CRT memory debugging */
50 #define _CRTDBG_MAP_ALLOC
55 #define FD_SETSIZE 24000
57 typedef unsigned __int16 uint16_t;
58 typedef unsigned __int32 uint32_t;
60 /* Make builds smaller, leaner and faster */
62 #define WIN32_LEAN_AND_MEAN
64 /* Not defined in windows */
67 /* Not defined in windows, parameter to shutdown() */
70 /* They just have to be *different*, don't they. */
71 #define PATH_MAX MAX_PATH
73 /* Begone shitty 'safe STL' warnings */
74 #define _SCL_SECURE_NO_WARNINGS
75 #define _CRT_SECURE_NO_WARNINGS
76 #define _AFX_SECURE_NO_WARNINGS
77 #define _ATL_SECURE_NO_WARNINGS
79 /* Macros for exporting symbols - dependant on what is being compiled */
82 #define CoreExport __declspec(dllimport)
83 #define DllExport __declspec(dllexport)
85 #define CoreExport __declspec(dllexport)
86 #define DllExport __declspec(dllimport)
89 /* Redirect main() through a different method in win32service.cpp, to intercept service startup */
90 #define ENTRYPOINT CoreExport int smain(int argc, char** argv)
92 /* Disable the deprecation warnings.. it spams :P */
93 #define _CRT_SECURE_NO_DEPRECATE
94 #define _SCL_SECURE_NO_DEPRECATE
98 /* Say we're building on windows 2000. Anyone running something older than this
99 * reeeeeeeally needs to upgrade! */
101 /* Normal windows (platform-specific) includes */
102 #include <winsock2.h>
104 #include <ws2tcpip.h>
105 #include <sys/types.h>
106 #include <sys/stat.h>
114 #ifdef ENABLE_CRASHDUMPS
118 /* strcasecmp is not defined on windows by default */
119 #define strcasecmp _stricmp
121 /* this standard function is nonstarard. go figure. */
123 #define pclose _pclose
125 /* Error macros need to be redirected to winsock error codes, apart from on VS2010 *SIGH* */
127 #define ETIMEDOUT WSAETIMEDOUT
128 #define ECONNREFUSED WSAECONNREFUSED
129 #define EADDRINUSE WSAEADDRINUSE
130 #define EINPROGRESS WSAEWOULDBLOCK
131 #define EADDRNOTAVAIL WSAEADDRNOTAVAIL
134 /* Convert formatted (xxx.xxx.xxx.xxx) string to in_addr struct */
135 CoreExport int insp_inet_pton(int af, const char * src, void * dst);
137 /* Convert struct to formatted (xxx.xxx.xxx.xxx) string */
138 CoreExport const char * insp_inet_ntop(int af, const void * src, char * dst, socklen_t cnt);
140 /* we don't want to use windows' broken inet_pton and ntop */
141 #define inet_pton insp_inet_pton
142 #define inet_ntop insp_inet_ntop
144 /* Safe printf functions aren't defined in VC2003 */
145 #define snprintf _snprintf
146 #define vsnprintf _vsnprintf
148 /* Since when does the ISO C++ standard *remove* C functions?! */
149 #define mkdir(file,mode) _mkdir(file)
151 #define strncasecmp strnicmp
153 /* Unix-style sleep (argument is in seconds) */
154 __inline void sleep(int seconds) { Sleep(seconds * 1000); }
156 /* IPV4 only convert string to address struct */
157 CoreExport int inet_aton(const char *, struct in_addr *);
159 /* Unix-style get running user id */
160 CoreExport int geteuid();
162 /* Handles colors in printf */
163 CoreExport int printf_c(const char * format, ...);
165 /* getopt() wrapper */
166 # define no_argument 0
167 # define required_argument 1
168 # define optional_argument 2
177 extern char optarg[514];
178 int getopt_long(int ___argc, char *const *___argv, const char *__shortopts, const struct option *__longopts, int *__longind);
181 #define dlopen(path, state) (void*)LoadLibrary(path)
182 #define dlsym(handle, export) (void*)GetProcAddress((HMODULE)handle, export)
183 #define dlclose(handle) FreeLibrary((HMODULE)handle)
184 const char * dlerror();
186 /* Unix-style directory searching functions */
187 #define chmod(filename, mode)
191 char d_name[MAX_PATH];
196 dirent dirent_pointer;
198 WIN32_FIND_DATA find_data;
208 CoreExport DIR * opendir(const char * path);
209 CoreExport dirent * readdir(DIR * handle);
210 CoreExport void closedir(DIR * handle);
212 const int CLOCK_REALTIME = 0;
213 CoreExport int clock_gettime(int clock, struct timespec * tv);
215 /* Disable these stupid warnings.. */
216 #pragma warning(disable:4800)
217 #pragma warning(disable:4251)
218 #pragma warning(disable:4275)
219 #pragma warning(disable:4244) // warning C4244: '=' : conversion from 'long' to 'short', possible loss of data
220 #pragma warning(disable:4267) // warning C4267: 'argument' : conversion from 'size_t' to 'int', possible loss of data
221 #pragma warning(disable:4805) // warning C4805: '!=' : unsafe mix of type 'char' and type 'bool' in operation
222 #pragma warning(disable:4311) // warning C4311: 'type cast' : pointer truncation from 'accept_overlap *' to 'int'
223 #pragma warning(disable:4312) // warning C4312: 'type cast' : conversion from 'int' to 'HANDLE' of greater size
224 #pragma warning(disable:4355) // warning C4355: 'this' : used in base member initializer list
225 #pragma warning(disable:4996) // warning C4996: 'std::_Traits_helper::move_s' was declared deprecated
226 #pragma warning(disable:4706) // warning C4706: assignment within conditional expression
227 #pragma warning(disable:4201) // mmsystem.h generates this warning
229 /* Mehhhh... typedefs. */
231 typedef unsigned char uint8_t;
232 typedef unsigned long long uint64_t;
233 typedef signed char int8_t;
234 typedef signed long long int64_t;
235 typedef signed long ssize_t;
237 /* Shared memory allocation functions */
238 void * ::operator new(size_t iSize);
239 void ::operator delete(void * ptr);
245 /* Look up the nameserver in use from the registry on windows */
246 CoreExport std::string FindNameServerWin();
248 #define DISABLE_WRITEV
250 /* Clear a windows console */
251 CoreExport void ClearConsole();
253 CoreExport DWORD WindowsForkStart();
255 CoreExport void WindowsForkKillOwner();
257 CoreExport void ChangeWindowsSpecificPointers();
259 CoreExport void FindDNS(std::string& server);
261 CoreExport bool initwmi();
262 CoreExport void donewmi();
263 CoreExport int getcpu();
264 CoreExport int random();
265 CoreExport void srandom(unsigned seed);
266 CoreExport int gettimeofday(timeval *tv, void *);