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 /* Remember file descriptors are treated differently on windows ;) */
83 __inline int close(int socket) { return closesocket(socket); }
85 /* Convert formatted (xxx.xxx.xxx.xxx) string to in_addr struct */
86 CoreExport int inet_pton(int af, const char * src, void * dst);
88 /* Convert struct to formatted (xxx.xxx.xxx.xxx) string */
89 CoreExport const char * inet_ntop(int af, const void * src, char * dst, socklen_t cnt);
91 /* Safe printf functions aren't defined in VC2003 */
92 #define snprintf _snprintf
93 #define vsnprintf _vsnprintf
95 /* Recursive token function doesn't exist in VC++ */
96 CoreExport char * strtok_r(char *_String, const char *_Control, char **_Context);
98 /* Unix-style sleep (argument is in seconds) */
99 __inline void sleep(int seconds) { Sleep(seconds * 1000); }
101 /* IPV4 only convert string to address struct */
102 CoreExport int inet_aton(const char *, struct in_addr *);
104 /* Unix-style get running user id */
105 CoreExport int geteuid();
107 /* Handles colors in printf */
108 CoreExport int printf_c(const char * format, ...);
110 /* getopt() wrapper */
111 # define no_argument 0
112 # define required_argument 1
113 # define optional_argument 2
121 extern char optarg[514];
122 int getopt_long_only (int ___argc, char *const *___argv, const char *__shortopts, const struct option *__longopts, int *__longind);
124 /* Accept Handlers */
126 CoreExport int __accept_socket(SOCKET s, sockaddr * addr, int * addrlen, void * acceptevent);
127 CoreExport int __getsockname(SOCKET s, sockaddr * name, int * namelen, void * acceptevent);
128 CoreExport int __recvfrom(SOCKET s, char * buf, int len, int flags, struct sockaddr * from, int * fromlen, udp_overlap * ov);
131 #define dlopen(path, state) (void*)LoadLibrary(path)
132 #define dlsym(handle, export) (void*)GetProcAddress((HMODULE)handle, export)
133 #define dlclose(handle) FreeLibrary((HMODULE)handle)
134 const char * dlerror();
136 /* Unix-style directory searching functions */
137 #define chmod(filename, mode)
140 char d_name[MAX_PATH];
145 dirent dirent_pointer;
147 WIN32_FIND_DATA find_data;
151 CoreExport DIR * opendir(const char * path);
152 CoreExport dirent * readdir(DIR * handle);
153 CoreExport void closedir(DIR * handle);
155 CoreExport int gettimeofday(struct timeval * tv, void * tz);
157 /* Disable these stupid warnings.. */
158 #pragma warning(disable:4800)
159 #pragma warning(disable:4251)
160 #pragma warning(disable:4275)
161 #pragma warning(disable:4244) // warning C4244: '=' : conversion from 'long' to 'short', possible loss of data
162 #pragma warning(disable:4267) // warning C4267: 'argument' : conversion from 'size_t' to 'int', possible loss of data
163 #pragma warning(disable:4805) // warning C4805: '!=' : unsafe mix of type 'char' and type 'bool' in operation
164 #pragma warning(disable:4311) // warning C4311: 'type cast' : pointer truncation from 'accept_overlap *' to 'int'
165 #pragma warning(disable:4312) // warning C4312: 'type cast' : conversion from 'int' to 'HANDLE' of greater size
166 #pragma warning(disable:4355) // warning C4355: 'this' : used in base member initializer list
167 #pragma warning(disable:4996) // warning C4996: 'std::_Traits_helper::move_s' was declared deprecated
169 /* Mehhhh... typedefs. */
171 typedef unsigned char uint8_t;
172 typedef unsigned long long uint64_t;
173 typedef signed char int8_t;
174 typedef signed long int32_t;
175 typedef signed long long int64_t;
177 /* Shared memory allocation functions */
178 void * ::operator new(size_t iSize);
179 void ::operator delete(void * ptr);
197 /* Look up the nameserver in use from the registry on windows */
198 std::string FindNameServerWin();
200 /* Clear a windows console */
203 DWORD WindowsForkStart(InspIRCd* Instance);
205 void WindowsForkKillOwner(InspIRCd* Instance);
207 void ChangeWindowsSpecificPointers(InspIRCd* Instance);
209 bool ValidateWindowsDnsServer(ServerConfig* conf, const char* tag, const char* value, ValueItem &data);