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 */
25 /* Make builds smaller, leaner and faster */
27 #define WIN32_LEAN_AND_MEAN
29 /* Not defined in windows */
32 /* They just have to be *different*, don't they. */
33 #define PATH_MAX MAX_PATH
35 /* Begone shitty 'safe STL' warnings */
36 #define _SCL_SECURE_NO_WARNINGS
37 #define _CRT_SECURE_NO_WARNINGS
38 #define _AFX_SECURE_NO_WARNINGS
39 #define _ATL_SECURE_NO_WARNINGS
41 /* Macros for exporting symbols - dependant on what is being compiled */
44 #define CoreExport __declspec(dllimport)
45 #define DllExport __declspec(dllexport)
47 #define CoreExport __declspec(dllexport)
48 #define DllExport __declspec(dllimport)
51 /* Disable the deprecation warnings.. it spams :P */
52 #define _CRT_SECURE_NO_DEPRECATE
53 #define _SCL_SECURE_NO_DEPRECATE
57 /* Say we're building on windows 2000. Anyone running something older than this
58 * reeeeeeeally needs to upgrade! */
60 #define _WIN32_WINNT 0x500
62 /* Normal windows (platform-specific) includes */
66 #include <sys/types.h>
73 /* strcasecmp is not defined on windows by default */
74 #define strcasecmp _stricmp
76 /* Error macros need to be redirected to winsock error codes */
77 #define ETIMEDOUT WSAETIMEDOUT
78 #define ECONNREFUSED WSAECONNREFUSED
79 #define EADDRINUSE WSAEADDRINUSE
80 #define EINPROGRESS WSAEWOULDBLOCK
82 /* Convert formatted (xxx.xxx.xxx.xxx) string to in_addr struct */
83 CoreExport int inet_pton(int af, const char * src, void * dst);
85 /* Convert struct to formatted (xxx.xxx.xxx.xxx) string */
86 CoreExport const char * inet_ntop(int af, const void * src, char * dst, socklen_t cnt);
88 /* Safe printf functions aren't defined in VC2003 */
89 #define snprintf _snprintf
90 #define vsnprintf _vsnprintf
92 /* Recursive token function doesn't exist in VC++ */
93 CoreExport char * strtok_r(char *_String, const char *_Control, char **_Context);
95 /* Unix-style sleep (argument is in seconds) */
96 __inline void sleep(int seconds) { Sleep(seconds * 1000); }
98 /* IPV4 only convert string to address struct */
99 CoreExport int inet_aton(const char *, struct in_addr *);
101 /* Unix-style get running user id */
102 CoreExport int geteuid();
104 /* Handles colors in printf */
105 CoreExport int printf_c(const char * format, ...);
107 /* getopt() wrapper */
108 # define no_argument 0
109 # define required_argument 1
110 # define optional_argument 2
118 extern char optarg[514];
119 int getopt_long_only (int ___argc, char *const *___argv, const char *__shortopts, const struct option *__longopts, int *__longind);
122 #define dlopen(path, state) (void*)LoadLibrary(path)
123 #define dlsym(handle, export) (void*)GetProcAddress((HMODULE)handle, export)
124 #define dlclose(handle) FreeLibrary((HMODULE)handle)
125 const char * dlerror();
127 /* Unix-style directory searching functions */
128 #define chmod(filename, mode)
131 char d_name[MAX_PATH];
136 dirent dirent_pointer;
138 WIN32_FIND_DATA find_data;
142 CoreExport DIR * opendir(const char * path);
143 CoreExport dirent * readdir(DIR * handle);
144 CoreExport void closedir(DIR * handle);
146 CoreExport int gettimeofday(struct timeval * tv, void * tz);
148 /* Disable these stupid warnings.. */
149 #pragma warning(disable:4800)
150 #pragma warning(disable:4251)
151 #pragma warning(disable:4275)
152 #pragma warning(disable:4244) // warning C4244: '=' : conversion from 'long' to 'short', possible loss of data
153 #pragma warning(disable:4267) // warning C4267: 'argument' : conversion from 'size_t' to 'int', possible loss of data
154 #pragma warning(disable:4805) // warning C4805: '!=' : unsafe mix of type 'char' and type 'bool' in operation
155 #pragma warning(disable:4311) // warning C4311: 'type cast' : pointer truncation from 'accept_overlap *' to 'int'
156 #pragma warning(disable:4312) // warning C4312: 'type cast' : conversion from 'int' to 'HANDLE' of greater size
157 #pragma warning(disable:4355) // warning C4355: 'this' : used in base member initializer list
158 #pragma warning(disable:4996) // warning C4996: 'std::_Traits_helper::move_s' was declared deprecated
160 /* Mehhhh... typedefs. */
162 typedef unsigned char uint8_t;
163 typedef unsigned long long uint64_t;
164 typedef signed char int8_t;
165 typedef signed long int32_t;
166 typedef signed long long int64_t;
168 /* Shared memory allocation functions */
169 void * ::operator new(size_t iSize);
170 void ::operator delete(void * ptr);
188 /* Look up the nameserver in use from the registry on windows */
189 std::string FindNameServerWin();
191 /* Clear a windows console */
194 DWORD WindowsForkStart(InspIRCd* Instance);
196 void WindowsForkKillOwner(InspIRCd* Instance);
198 void ChangeWindowsSpecificPointers(InspIRCd* Instance);
200 bool ValidateWindowsDnsServer(ServerConfig* conf, const char* tag, const char* value, ValueItem &data);