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 12000
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 /* Disable the deprecation warnings.. it spams :P */
59 #define _CRT_SECURE_NO_DEPRECATE
60 #define _SCL_SECURE_NO_DEPRECATE
64 /* Say we're building on windows 2000. Anyone running something older than this
65 * reeeeeeeally needs to upgrade! */
67 #define _WIN32_WINNT 0x500
69 /* Normal windows (platform-specific) includes */
73 #include <sys/types.h>
80 #ifdef ENABLE_CRASHDUMPS
84 /* strcasecmp is not defined on windows by default */
85 #define strcasecmp _stricmp
87 /* Error macros need to be redirected to winsock error codes */
88 #define ETIMEDOUT WSAETIMEDOUT
89 #define ECONNREFUSED WSAECONNREFUSED
90 #define EADDRINUSE WSAEADDRINUSE
91 #define EINPROGRESS WSAEWOULDBLOCK
93 /* Convert formatted (xxx.xxx.xxx.xxx) string to in_addr struct */
94 CoreExport int inet_pton(int af, const char * src, void * dst);
96 /* Convert struct to formatted (xxx.xxx.xxx.xxx) string */
97 CoreExport const char * inet_ntop(int af, const void * src, char * dst, socklen_t cnt);
99 /* Safe printf functions aren't defined in VC2003 */
100 #define snprintf _snprintf
101 #define vsnprintf _vsnprintf
103 /* Recursive token function doesn't exist in VC++ */
104 CoreExport char * strtok_r(char *_String, const char *_Control, char **_Context);
106 /* Unix-style sleep (argument is in seconds) */
107 __inline void sleep(int seconds) { Sleep(seconds * 1000); }
109 /* IPV4 only convert string to address struct */
110 CoreExport int inet_aton(const char *, struct in_addr *);
112 /* Unix-style get running user id */
113 CoreExport int geteuid();
115 /* Handles colors in printf */
116 CoreExport int printf_c(const char * format, ...);
118 /* getopt() wrapper */
119 # define no_argument 0
120 # define required_argument 1
121 # define optional_argument 2
129 extern char optarg[514];
130 int getopt_long_only (int ___argc, char *const *___argv, const char *__shortopts, const struct option *__longopts, int *__longind);
133 #define dlopen(path, state) (void*)LoadLibrary(path)
134 #define dlsym(handle, export) (void*)GetProcAddress((HMODULE)handle, export)
135 #define dlclose(handle) FreeLibrary((HMODULE)handle)
136 const char * dlerror();
138 /* Unix-style directory searching functions */
139 #define chmod(filename, mode)
142 char d_name[MAX_PATH];
147 dirent dirent_pointer;
149 WIN32_FIND_DATA find_data;
153 CoreExport DIR * opendir(const char * path);
154 CoreExport dirent * readdir(DIR * handle);
155 CoreExport void closedir(DIR * handle);
157 CoreExport int gettimeofday(struct timeval * tv, void * tz);
159 /* Disable these stupid warnings.. */
160 #pragma warning(disable:4800)
161 #pragma warning(disable:4251)
162 #pragma warning(disable:4275)
163 #pragma warning(disable:4244) // warning C4244: '=' : conversion from 'long' to 'short', possible loss of data
164 #pragma warning(disable:4267) // warning C4267: 'argument' : conversion from 'size_t' to 'int', possible loss of data
165 #pragma warning(disable:4805) // warning C4805: '!=' : unsafe mix of type 'char' and type 'bool' in operation
166 #pragma warning(disable:4311) // warning C4311: 'type cast' : pointer truncation from 'accept_overlap *' to 'int'
167 #pragma warning(disable:4312) // warning C4312: 'type cast' : conversion from 'int' to 'HANDLE' of greater size
168 #pragma warning(disable:4355) // warning C4355: 'this' : used in base member initializer list
169 #pragma warning(disable:4996) // warning C4996: 'std::_Traits_helper::move_s' was declared deprecated
171 /* Mehhhh... typedefs. */
173 typedef unsigned char uint8_t;
174 typedef unsigned long long uint64_t;
175 typedef signed char int8_t;
176 typedef signed long int32_t;
177 typedef signed long long int64_t;
179 /* Shared memory allocation functions */
180 void * ::operator new(size_t iSize);
181 void ::operator delete(void * ptr);
199 /* Look up the nameserver in use from the registry on windows */
200 std::string FindNameServerWin();
202 /* Clear a windows console */
205 DWORD WindowsForkStart(InspIRCd* Instance);
207 void WindowsForkKillOwner(InspIRCd* Instance);
209 void ChangeWindowsSpecificPointers(InspIRCd* Instance);
211 bool ValidateWindowsDnsServer(ServerConfig* conf, const char* tag, const char* value, ValueItem &data);