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 */
28 /* They just have to be *different*, don't they. */
29 #define PATH_MAX MAX_PATH
31 /* Begone shitty 'safe STL' warnings */
32 #define _SCL_SECURE_NO_WARNINGS
33 #define _CRT_SECURE_NO_WARNINGS
34 #define _AFX_SECURE_NO_WARNINGS
35 #define _ATL_SECURE_NO_WARNINGS
37 /* Macros for exporting symbols - dependant on what is being compiled */
40 #define CoreExport __declspec(dllimport)
41 #define DllExport __declspec(dllexport)
43 #define CoreExport __declspec(dllexport)
44 #define DllExport __declspec(dllimport)
47 /* Disable the deprecation warnings.. it spams :P */
48 #define _CRT_SECURE_NO_DEPRECATE
49 #define _SCL_SECURE_NO_DEPRECATE
53 /* Say we're building on windows 2000. Anyone running something older than this
54 * reeeeeeeally needs to upgrade! */
56 #define _WIN32_WINNT 0x500
58 /* Normal windows (platform-specific) includes */
62 #include <sys/types.h>
69 /* printf_c support for printing ansi colors in console */
72 /* strcasecmp is not defined on windows by default */
73 #define strcasecmp _stricmp
75 /* Error macros need to be redirected to winsock error codes */
76 #define ETIMEDOUT WSAETIMEDOUT
77 #define ECONNREFUSED WSAECONNREFUSED
78 #define EADDRINUSE WSAEADDRINUSE
79 #define EINPROGRESS WSAEWOULDBLOCK
81 /* Remember file descriptors are treated differently on windows ;) */
82 __inline int close(int socket) { return closesocket(socket); }
84 /* Convert formatted (xxx.xxx.xxx.xxx) string to in_addr struct */
85 CoreExport int inet_pton(int af, const char * src, void * dst);
87 /* Convert struct to formatted (xxx.xxx.xxx.xxx) string */
88 CoreExport const char * inet_ntop(int af, const void * src, char * dst, socklen_t cnt);
90 /* Safe printf functions aren't defined in VC2003 */
91 #define snprintf _snprintf
92 #define vsnprintf _vsnprintf
94 /* Recursive token function doesn't exist in VC++ */
95 CoreExport char * strtok_r(char *_String, const char *_Control, char **_Context);
97 /* Unix-style sleep (argument is in seconds) */
98 __inline void sleep(int seconds) { Sleep(seconds * 1000); }
100 /* IPV4 only convert string to address struct */
101 CoreExport int inet_aton(const char *, struct in_addr *);
103 /* Unix-style get running user id */
104 CoreExport int geteuid();
106 /* getopt() wrapper */
107 # define no_argument 0
108 # define required_argument 1
109 # define optional_argument 2
117 extern char optarg[514];
118 int getopt_long_only (int ___argc, char *const *___argv, const char *__shortopts, const struct option *__longopts, int *__longind);
120 /* Accept Handlers */
122 CoreExport int __accept_socket(SOCKET s, sockaddr * addr, int * addrlen, void * acceptevent);
123 CoreExport int __getsockname(SOCKET s, sockaddr * name, int * namelen, void * acceptevent);
124 CoreExport int __recvfrom(SOCKET s, char * buf, int len, int flags, struct sockaddr * from, int * fromlen, udp_overlap * ov);
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 /* Disable these stupid warnings.. */
152 #pragma warning(disable:4800)
153 #pragma warning(disable:4251)
154 #pragma warning(disable:4275)
155 #pragma warning(disable:4244) // warning C4244: '=' : conversion from 'long' to 'short', possible loss of data
156 #pragma warning(disable:4267) // warning C4267: 'argument' : conversion from 'size_t' to 'int', possible loss of data
157 #pragma warning(disable:4805) // warning C4805: '!=' : unsafe mix of type 'char' and type 'bool' in operation
158 #pragma warning(disable:4311) // warning C4311: 'type cast' : pointer truncation from 'accept_overlap *' to 'int'
159 #pragma warning(disable:4312) // warning C4312: 'type cast' : conversion from 'int' to 'HANDLE' of greater size
160 #pragma warning(disable:4355) // warning C4355: 'this' : used in base member initializer list
161 #pragma warning(disable:4996) // warning C4996: 'std::_Traits_helper::move_s' was declared deprecated
163 /* Mehhhh... typedefs. */
165 typedef unsigned char uint8_t;
166 typedef unsigned long long uint64_t;
167 typedef signed char int8_t;
168 typedef signed long int32_t;
169 typedef signed long long int64_t;
171 /* Shared memory allocation functions */
172 void * ::operator new(size_t iSize);
173 void ::operator delete(void * ptr);
179 void CheckIPC(InspIRCd * Instance);
182 /* Look up the nameserver in use from the registry on windows */
183 std::string FindNameServerWin();
185 /* Clear a windows console */