1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * InspIRCd: (C) 2002-2008 InspIRCd Development Team
6 * See: http://www.inspircd.org/wiki/index.php/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
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 */
24 #define ENABLE_CRASHDUMPS 0
26 /* This defaults to 64, way too small for an ircd! */
27 #define FD_SETSIZE 24000
29 /* Make builds smaller, leaner and faster */
31 #define WIN32_LEAN_AND_MEAN
33 /* Not defined in windows */
36 /* Not defined in windows, parameter to shutdown() */
39 /* They just have to be *different*, don't they. */
40 #define PATH_MAX MAX_PATH
42 /* Begone shitty 'safe STL' warnings */
43 #define _SCL_SECURE_NO_WARNINGS
44 #define _CRT_SECURE_NO_WARNINGS
45 #define _AFX_SECURE_NO_WARNINGS
46 #define _ATL_SECURE_NO_WARNINGS
48 /* Macros for exporting symbols - dependant on what is being compiled */
51 #define CoreExport __declspec(dllimport)
52 #define DllExport __declspec(dllexport)
54 #define CoreExport __declspec(dllexport)
55 #define DllExport __declspec(dllimport)
58 /* Redirect main() through a different method in win32service.cpp, to intercept service startup */
59 #define ENTRYPOINT CoreExport int smain(int argc, char** argv)
61 /* Disable the deprecation warnings.. it spams :P */
62 #define _CRT_SECURE_NO_DEPRECATE
63 #define _SCL_SECURE_NO_DEPRECATE
67 /* Say we're building on windows 2000. Anyone running something older than this
68 * reeeeeeeally needs to upgrade! */
70 #define _WIN32_WINNT 0x500
72 /* Normal windows (platform-specific) includes */
76 #include <sys/types.h>
83 #ifdef ENABLE_CRASHDUMPS
87 /* strcasecmp is not defined on windows by default */
88 #define strcasecmp _stricmp
90 /* this standard function is nonstarard. go figure. */
92 #define pclose _pclose
94 /* Error macros need to be redirected to winsock error codes */
95 #define ETIMEDOUT WSAETIMEDOUT
96 #define ECONNREFUSED WSAECONNREFUSED
97 #define EADDRINUSE WSAEADDRINUSE
98 #define EINPROGRESS WSAEWOULDBLOCK
100 /* Convert formatted (xxx.xxx.xxx.xxx) string to in_addr struct */
101 CoreExport int inet_pton(int af, const char * src, void * dst);
103 /* Convert struct to formatted (xxx.xxx.xxx.xxx) string */
104 CoreExport const char * inet_ntop(int af, const void * src, char * dst, socklen_t cnt);
106 /* Safe printf functions aren't defined in VC2003 */
107 #define snprintf _snprintf
108 #define vsnprintf _vsnprintf
110 /* Since when does the ISO C++ standard *remove* C functions?! */
111 #define mkdir(file,mode) _mkdir(file)
113 /* Recursive token function doesn't exist in VC++ */
114 CoreExport char * strtok_r(char *_String, const char *_Control, char **_Context);
116 /* Unix-style sleep (argument is in seconds) */
117 __inline void sleep(int seconds) { Sleep(seconds * 1000); }
119 /* IPV4 only convert string to address struct */
120 CoreExport int inet_aton(const char *, struct in_addr *);
122 /* Unix-style get running user id */
123 CoreExport int geteuid();
125 /* Handles colors in printf */
126 CoreExport int printf_c(const char * format, ...);
128 /* getopt() wrapper */
129 # define no_argument 0
130 # define required_argument 1
131 # define optional_argument 2
139 extern char optarg[514];
140 int getopt_long_only (int ___argc, char *const *___argv, const char *__shortopts, const struct option *__longopts, int *__longind);
143 #define dlopen(path, state) (void*)LoadLibrary(path)
144 #define dlsym(handle, export) (void*)GetProcAddress((HMODULE)handle, export)
145 #define dlclose(handle) FreeLibrary((HMODULE)handle)
146 const char * dlerror();
148 /* Unix-style directory searching functions */
149 #define chmod(filename, mode)
153 char d_name[MAX_PATH];
158 dirent dirent_pointer;
160 WIN32_FIND_DATA find_data;
164 CoreExport DIR * opendir(const char * path);
165 CoreExport dirent * readdir(DIR * handle);
166 CoreExport void closedir(DIR * handle);
168 CoreExport int gettimeofday(struct timeval * tv, void * tz);
170 /* Disable these stupid warnings.. */
171 #pragma warning(disable:4800)
172 #pragma warning(disable:4251)
173 #pragma warning(disable:4275)
174 #pragma warning(disable:4244) // warning C4244: '=' : conversion from 'long' to 'short', possible loss of data
175 #pragma warning(disable:4267) // warning C4267: 'argument' : conversion from 'size_t' to 'int', possible loss of data
176 #pragma warning(disable:4805) // warning C4805: '!=' : unsafe mix of type 'char' and type 'bool' in operation
177 #pragma warning(disable:4311) // warning C4311: 'type cast' : pointer truncation from 'accept_overlap *' to 'int'
178 #pragma warning(disable:4312) // warning C4312: 'type cast' : conversion from 'int' to 'HANDLE' of greater size
179 #pragma warning(disable:4355) // warning C4355: 'this' : used in base member initializer list
180 #pragma warning(disable:4996) // warning C4996: 'std::_Traits_helper::move_s' was declared deprecated
181 #pragma warning(disable:4706) // warning C4706: assignment within conditional expression
182 #pragma warning(disable:4201) // mmsystem.h generates this warning
184 /* Mehhhh... typedefs. */
186 typedef unsigned char uint8_t;
187 typedef unsigned long long uint64_t;
188 typedef signed char int8_t;
189 typedef signed long int32_t;
190 typedef signed long long int64_t;
192 /* Shared memory allocation functions */
193 void * ::operator new(size_t iSize);
194 void ::operator delete(void * ptr);
201 /* Look up the nameserver in use from the registry on windows */
202 CoreExport std::string FindNameServerWin();
204 /* Clear a windows console */
205 CoreExport void ClearConsole();
207 CoreExport DWORD WindowsForkStart(InspIRCd* Instance);
209 CoreExport void WindowsForkKillOwner(InspIRCd* Instance);
211 CoreExport void ChangeWindowsSpecificPointers(InspIRCd* Instance);
213 CoreExport bool ValidateWindowsDnsServer(ServerConfig* conf, const char* tag, const char* value, ValueItem &data);
215 CoreExport bool initwmi();
216 CoreExport void donewmi();
217 CoreExport int getcpu();