1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * InspIRCd: (C) 2002-2007 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 /* Make builds smaller, leaner and faster */
28 #define WIN32_LEAN_AND_MEAN
30 /* Not defined in windows */
33 /* Not defined in windows, parameter to shutdown() */
36 /* They just have to be *different*, don't they. */
37 #define PATH_MAX MAX_PATH
39 /* Begone shitty 'safe STL' warnings */
40 #define _SCL_SECURE_NO_WARNINGS
41 #define _CRT_SECURE_NO_WARNINGS
42 #define _AFX_SECURE_NO_WARNINGS
43 #define _ATL_SECURE_NO_WARNINGS
45 /* Macros for exporting symbols - dependant on what is being compiled */
48 #define CoreExport __declspec(dllimport)
49 #define DllExport __declspec(dllexport)
51 #define CoreExport __declspec(dllexport)
52 #define DllExport __declspec(dllimport)
55 /* Disable the deprecation warnings.. it spams :P */
56 #define _CRT_SECURE_NO_DEPRECATE
57 #define _SCL_SECURE_NO_DEPRECATE
61 /* Say we're building on windows 2000. Anyone running something older than this
62 * reeeeeeeally needs to upgrade! */
64 #define _WIN32_WINNT 0x500
66 /* Normal windows (platform-specific) includes */
70 #include <sys/types.h>
77 #ifdef ENABLE_CRASHDUMPS
81 /* strcasecmp is not defined on windows by default */
82 #define strcasecmp _stricmp
84 /* Error macros need to be redirected to winsock error codes */
85 #define ETIMEDOUT WSAETIMEDOUT
86 #define ECONNREFUSED WSAECONNREFUSED
87 #define EADDRINUSE WSAEADDRINUSE
88 #define EINPROGRESS WSAEWOULDBLOCK
90 /* Convert formatted (xxx.xxx.xxx.xxx) string to in_addr struct */
91 CoreExport int inet_pton(int af, const char * src, void * dst);
93 /* Convert struct to formatted (xxx.xxx.xxx.xxx) string */
94 CoreExport const char * inet_ntop(int af, const void * src, char * dst, socklen_t cnt);
96 /* Safe printf functions aren't defined in VC2003 */
97 #define snprintf _snprintf
98 #define vsnprintf _vsnprintf
100 /* Recursive token function doesn't exist in VC++ */
101 CoreExport char * strtok_r(char *_String, const char *_Control, char **_Context);
103 /* Unix-style sleep (argument is in seconds) */
104 __inline void sleep(int seconds) { Sleep(seconds * 1000); }
106 /* IPV4 only convert string to address struct */
107 CoreExport int inet_aton(const char *, struct in_addr *);
109 /* Unix-style get running user id */
110 CoreExport int geteuid();
112 /* Handles colors in printf */
113 CoreExport int printf_c(const char * format, ...);
115 /* getopt() wrapper */
116 # define no_argument 0
117 # define required_argument 1
118 # define optional_argument 2
126 extern char optarg[514];
127 int getopt_long_only (int ___argc, char *const *___argv, const char *__shortopts, const struct option *__longopts, int *__longind);
130 #define dlopen(path, state) (void*)LoadLibrary(path)
131 #define dlsym(handle, export) (void*)GetProcAddress((HMODULE)handle, export)
132 #define dlclose(handle) FreeLibrary((HMODULE)handle)
133 const char * dlerror();
135 /* Unix-style directory searching functions */
136 #define chmod(filename, mode)
139 char d_name[MAX_PATH];
144 dirent dirent_pointer;
146 WIN32_FIND_DATA find_data;
150 CoreExport DIR * opendir(const char * path);
151 CoreExport dirent * readdir(DIR * handle);
152 CoreExport void closedir(DIR * handle);
154 CoreExport int gettimeofday(struct timeval * tv, void * tz);
156 /* Disable these stupid warnings.. */
157 #pragma warning(disable:4800)
158 #pragma warning(disable:4251)
159 #pragma warning(disable:4275)
160 #pragma warning(disable:4244) // warning C4244: '=' : conversion from 'long' to 'short', possible loss of data
161 #pragma warning(disable:4267) // warning C4267: 'argument' : conversion from 'size_t' to 'int', possible loss of data
162 #pragma warning(disable:4805) // warning C4805: '!=' : unsafe mix of type 'char' and type 'bool' in operation
163 #pragma warning(disable:4311) // warning C4311: 'type cast' : pointer truncation from 'accept_overlap *' to 'int'
164 #pragma warning(disable:4312) // warning C4312: 'type cast' : conversion from 'int' to 'HANDLE' of greater size
165 #pragma warning(disable:4355) // warning C4355: 'this' : used in base member initializer list
166 #pragma warning(disable:4996) // warning C4996: 'std::_Traits_helper::move_s' was declared deprecated
168 /* Mehhhh... typedefs. */
170 typedef unsigned char uint8_t;
171 typedef unsigned long long uint64_t;
172 typedef signed char int8_t;
173 typedef signed long int32_t;
174 typedef signed long long int64_t;
176 /* Shared memory allocation functions */
177 void * ::operator new(size_t iSize);
178 void ::operator delete(void * ptr);
196 /* Look up the nameserver in use from the registry on windows */
197 std::string FindNameServerWin();
199 /* Clear a windows console */
202 DWORD WindowsForkStart(InspIRCd* Instance);
204 void WindowsForkKillOwner(InspIRCd* Instance);
206 void ChangeWindowsSpecificPointers(InspIRCd* Instance);
208 bool ValidateWindowsDnsServer(ServerConfig* conf, const char* tag, const char* value, ValueItem &data);