1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * InspIRCd: (C) 2002-2009 InspIRCd Development Team
6 * See: http://wiki.inspircd.org/Credits
8 * This program is free but copyrighted software; see
9 * the file COPYING for details.
11 * ---------------------------------------------------
15 Wrapper Functions/Definitions
18 #ifndef INSPIRCD_WIN32WRAPPER_H
19 #define INSPIRCD_WIN32WRAPPER_H
22 * Starting with PSAPI version 2 for Windows 7 and Windows Server 2008 R2, this function is defined as K32GetProcessMemoryInfo in Psapi.h and exported
23 * in Kernel32.lib and Kernel32.dll. However, you should always call this function as GetProcessMemoryInfo. To ensure correct resolution of symbols
24 * for programs that will run on earlier versions ofWindows, add Psapi.lib to the TARGETLIBS macro and compile the program with PSAPI_VERSION=1.
26 * We do this before anything to make sure it's done.
28 #define PSAPI_VERSION 1
30 #ifndef CONFIGURE_BUILD
31 #include "win32service.h"
34 /* Define the WINDOWS macro. This means we're building on windows to the rest of the server.
35 I think this is more reasonable than using WIN32, especially if we're gonna be doing 64-bit compiles */
37 #define ENABLE_CRASHDUMPS 0
39 /* This defaults to 64, way too small for an ircd! */
40 /* CRT memory debugging */
42 #define _CRTDBG_MAP_ALLOC
47 #define FD_SETSIZE 24000
49 typedef unsigned __int16 uint16_t;
50 typedef unsigned __int32 uint32_t;
52 /* Make builds smaller, leaner and faster */
54 #define WIN32_LEAN_AND_MEAN
56 /* Not defined in windows */
59 /* Not defined in windows, parameter to shutdown() */
62 /* They just have to be *different*, don't they. */
63 #define PATH_MAX MAX_PATH
65 /* Begone shitty 'safe STL' warnings */
66 #define _SCL_SECURE_NO_WARNINGS
67 #define _CRT_SECURE_NO_WARNINGS
68 #define _AFX_SECURE_NO_WARNINGS
69 #define _ATL_SECURE_NO_WARNINGS
71 /* Macros for exporting symbols - dependant on what is being compiled */
74 #define CoreExport __declspec(dllimport)
75 #define DllExport __declspec(dllexport)
77 #define CoreExport __declspec(dllexport)
78 #define DllExport __declspec(dllimport)
81 /* Redirect main() through a different method in win32service.cpp, to intercept service startup */
82 #define ENTRYPOINT CoreExport int smain(int argc, char** argv)
84 /* Disable the deprecation warnings.. it spams :P */
85 #define _CRT_SECURE_NO_DEPRECATE
86 #define _SCL_SECURE_NO_DEPRECATE
90 /* Say we're building on windows 2000. Anyone running something older than this
91 * reeeeeeeally needs to upgrade! */
93 /* Normal windows (platform-specific) includes */
97 #include <sys/types.h>
106 #ifdef ENABLE_CRASHDUMPS
110 /* strcasecmp is not defined on windows by default */
111 #define strcasecmp _stricmp
113 /* this standard function is nonstarard. go figure. */
115 #define pclose _pclose
117 /* Error macros need to be redirected to winsock error codes, apart from on VS2010 *SIGH* */
119 #define ETIMEDOUT WSAETIMEDOUT
120 #define ECONNREFUSED WSAECONNREFUSED
121 #define EADDRINUSE WSAEADDRINUSE
122 #define EINPROGRESS WSAEWOULDBLOCK
123 #define EADDRNOTAVAIL WSAEADDRNOTAVAIL
126 /* Convert formatted (xxx.xxx.xxx.xxx) string to in_addr struct */
127 CoreExport int insp_inet_pton(int af, const char * src, void * dst);
129 /* Convert struct to formatted (xxx.xxx.xxx.xxx) string */
130 CoreExport const char * insp_inet_ntop(int af, const void * src, char * dst, socklen_t cnt);
132 /* we don't want to use windows' broken inet_pton and ntop */
133 #define inet_pton insp_inet_pton
134 #define inet_ntop insp_inet_ntop
136 /* Safe printf functions aren't defined in VC2003 */
137 #define snprintf _snprintf
138 #define vsnprintf _vsnprintf
140 /* Since when does the ISO C++ standard *remove* C functions?! */
141 #define mkdir(file,mode) _mkdir(file)
143 /* Unix-style sleep (argument is in seconds) */
144 __inline void sleep(int seconds) { Sleep(seconds * 1000); }
146 /* IPV4 only convert string to address struct */
147 CoreExport int inet_aton(const char *, struct in_addr *);
149 /* Unix-style get running user id */
150 CoreExport int geteuid();
152 /* Handles colors in printf */
153 CoreExport int printf_c(const char * format, ...);
155 /* getopt() wrapper */
156 # define no_argument 0
157 # define required_argument 1
158 # define optional_argument 2
167 extern char optarg[514];
168 int getopt_long_only (int ___argc, char *const *___argv, const char *__shortopts, const struct option *__longopts, int *__longind);
171 #define dlopen(path, state) (void*)LoadLibrary(path)
172 #define dlsym(handle, export) (void*)GetProcAddress((HMODULE)handle, export)
173 #define dlclose(handle) FreeLibrary((HMODULE)handle)
174 const char * dlerror();
176 /* Unix-style directory searching functions */
177 #define chmod(filename, mode)
181 char d_name[MAX_PATH];
186 dirent dirent_pointer;
188 WIN32_FIND_DATA find_data;
192 CoreExport DIR * opendir(const char * path);
193 CoreExport dirent * readdir(DIR * handle);
194 CoreExport void closedir(DIR * handle);
196 const int CLOCK_REALTIME = 0;
197 CoreExport int clock_gettime(int clock, struct timespec * tv);
199 /* Disable these stupid warnings.. */
200 #pragma warning(disable:4800)
201 #pragma warning(disable:4251)
202 #pragma warning(disable:4275)
203 #pragma warning(disable:4244) // warning C4244: '=' : conversion from 'long' to 'short', possible loss of data
204 #pragma warning(disable:4267) // warning C4267: 'argument' : conversion from 'size_t' to 'int', possible loss of data
205 #pragma warning(disable:4805) // warning C4805: '!=' : unsafe mix of type 'char' and type 'bool' in operation
206 #pragma warning(disable:4311) // warning C4311: 'type cast' : pointer truncation from 'accept_overlap *' to 'int'
207 #pragma warning(disable:4312) // warning C4312: 'type cast' : conversion from 'int' to 'HANDLE' of greater size
208 #pragma warning(disable:4355) // warning C4355: 'this' : used in base member initializer list
209 #pragma warning(disable:4996) // warning C4996: 'std::_Traits_helper::move_s' was declared deprecated
210 #pragma warning(disable:4706) // warning C4706: assignment within conditional expression
211 #pragma warning(disable:4201) // mmsystem.h generates this warning
213 /* Mehhhh... typedefs. */
215 typedef unsigned char uint8_t;
216 typedef unsigned long long uint64_t;
217 typedef signed char int8_t;
218 typedef signed long int32_t;
219 typedef signed long long int64_t;
220 typedef signed long ssize_t;
222 /* Shared memory allocation functions */
223 void * ::operator new(size_t iSize);
224 void ::operator delete(void * ptr);
230 /* Look up the nameserver in use from the registry on windows */
231 CoreExport std::string FindNameServerWin();
233 #define DISABLE_WRITEV
235 /* Clear a windows console */
236 CoreExport void ClearConsole();
238 CoreExport DWORD WindowsForkStart();
240 CoreExport void WindowsForkKillOwner();
242 CoreExport void ChangeWindowsSpecificPointers();
244 CoreExport void FindDNS(std::string& server);
246 CoreExport bool initwmi();
247 CoreExport void donewmi();
248 CoreExport int getcpu();