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