InspIRCd  2.0
 All Classes Namespaces Functions Variables Typedefs Enumerations
inspircd_win32wrapper.h
1 /*
2  * InspIRCd -- Internet Relay Chat Daemon
3  *
4  * Copyright (C) 2007 Dennis Friis <peavey@inspircd.org>
5  * Copyright (C) 2007 Craig Edwards <craigedwards@brainbox.cc>
6  * Copyright (C) 2007 Robin Burchell <robin+git@viroteck.net>
7  *
8  * This file is part of InspIRCd. InspIRCd is free software: you can
9  * redistribute it and/or modify it under the terms of the GNU General Public
10  * License as published by the Free Software Foundation, version 2.
11  *
12  * This program is distributed in the hope that it will be useful, but WITHOUT
13  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
14  * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
15  * details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program. If not, see <http://www.gnu.org/licenses/>.
19  */
20 
21 
22 /* Windows Port
23  Wrapper Functions/Definitions
24  By Burlex */
25 
26 #ifndef INSPIRCD_WIN32WRAPPER_H
27 #define INSPIRCD_WIN32WRAPPER_H
28 
29 /*
30  * Starting with PSAPI version 2 for Windows 7 and Windows Server 2008 R2, this function is defined as K32GetProcessMemoryInfo in Psapi.h and exported
31  * in Kernel32.lib and Kernel32.dll. However, you should always call this function as GetProcessMemoryInfo. To ensure correct resolution of symbols
32  * for programs that will run on earlier versions of Windows, add Psapi.lib to the TARGETLIBS macro and compile the program with PSAPI_VERSION=1.
33  *
34  * We do this before anything to make sure it's done.
35  */
36 #define PSAPI_VERSION 1
37 
38 #include "win32service.h"
39 
40 /* This defaults to 64, way too small for an ircd! */
41 
42 #define FD_SETSIZE 24000
43 
44 /* Make builds smaller, leaner and faster */
45 #define VC_EXTRALEAN
46 #define WIN32_LEAN_AND_MEAN
47 
48 /* They just have to be *different*, don't they. */
49 #define PATH_MAX MAX_PATH
50 
51 /* Macros for exporting symbols - dependant on what is being compiled */
52 
53 #ifdef DLL_BUILD
54 #define CoreExport __declspec(dllimport)
55 #define DllExport __declspec(dllexport)
56 #else
57 #define CoreExport __declspec(dllexport)
58 #define DllExport __declspec(dllimport)
59 #endif
60 
61 /* Redirect main() through a different method in win32service.cpp, to intercept service startup */
62 #define ENTRYPOINT CoreExport int smain(int argc, char** argv)
63 
64 /* Disable the deprecation warnings.. it spams :P */
65 #define _CRT_SECURE_NO_DEPRECATE
66 
67 /* Normal windows (platform-specific) includes */
68 #include <winsock2.h>
69 #pragma comment(lib, "Ws2_32.lib")
70 #include <windows.h>
71 #include <ws2tcpip.h>
72 #include <sys/types.h>
73 #include <sys/stat.h>
74 #include <direct.h>
75 #include <process.h>
76 
77 /* strcasecmp is not defined on windows by default */
78 #define strcasecmp _stricmp
79 #define strncasecmp _strnicmp
80 
81 typedef int ssize_t;
82 
83 /* Convert formatted (xxx.xxx.xxx.xxx) string to in_addr struct */
84 CoreExport int insp_inet_pton(int af, const char * src, void * dst);
85 
86 /* Convert struct to formatted (xxx.xxx.xxx.xxx) string */
87 CoreExport const char * insp_inet_ntop(int af, const void * src, char * dst, socklen_t cnt);
88 
89 /* inet_pton/ntop require at least NT 6.0 */
90 #define inet_pton insp_inet_pton
91 #define inet_ntop insp_inet_ntop
92 
93 /* Safe printf functions aren't defined in VC++ */
94 #define snprintf _snprintf
95 #define vsnprintf _vsnprintf
96 
97 /* Unix-style sleep (argument is in seconds) */
98 __inline void sleep(int seconds) { Sleep(seconds * 1000); }
99 
100 /* _popen, _pclose */
101 #define popen _popen
102 #define pclose _pclose
103 
104 /* IPV4 only convert string to address struct */
105 __inline int inet_aton(const char *cp, struct in_addr *addr)
106 {
107  addr->s_addr = inet_addr(cp);
108  return (addr->s_addr == INADDR_NONE) ? 0 : 1;
109 };
110 
111 /* getopt() wrapper */
112 #define no_argument 0
113 #define required_argument 1
114 #define optional_argument 2
115 struct option
116 {
117  char *name;
118  int has_arg;
119  int *flag;
120  int val;
121 };
122 extern int optind;
123 extern char optarg[514];
124 int getopt_long(int ___argc, char *const *___argv, const char *__shortopts, const struct option *__longopts, int *__longind);
125 
126 struct dirent
127 {
128  char d_name[MAX_PATH];
129 };
130 
131 struct DIR
132 {
133  dirent dirent_pointer;
134  HANDLE find_handle;
135  WIN32_FIND_DATAA find_data;
136  bool first;
137 };
138 
139 struct timespec
140 {
141  time_t tv_sec;
142  long tv_nsec;
143 };
144 
145 CoreExport DIR * opendir(const char * path);
146 CoreExport dirent * readdir(DIR * handle);
147 CoreExport void closedir(DIR * handle);
148 
149 // warning: 'identifier' : class 'type' needs to have dll-interface to be used by clients of class 'type2'
150 // Normally, this is a huge problem, but due to our new/delete remap, we can ignore it.
151 #pragma warning(disable:4251)
152 
153 // warning: DLL-interface classkey 'identifier' used as base for DLL-interface classkey 'identifier'
154 #pragma warning(disable:4275)
155 
156 // warning: unreferenced formal parameter
157 // Unimportant for now, but for the next version, we should take a look at these again.
158 #pragma warning(disable:4100)
159 
160 // warning: 'class' : assignment operator could not be generated
161 #pragma warning(disable:4512)
162 
163 // warning C4127: conditional expression is constant
164 // This will be triggered like crazy because FOREACH_MOD and similar macros are wrapped in do { ... } while(0) constructs
165 #pragma warning(disable:4127)
166 
167 // warning C4996: The POSIX name for this item is deprecated.
168 #pragma warning(disable:4996)
169 
170 // warning C4244: conversion from 'x' to 'y', possible loss of data
171 #pragma warning(disable:4244)
172 
173 // warning C4267: 'var' : conversion from 'size_t' to 'type', possible loss of data
174 #pragma warning(disable:4267)
175 
176 // warning C4706: assignment within conditional expression
177 #pragma warning(disable:4706)
178 
179 // warning C4355: 'this' : used in base member initializer list
180 // This warning is disabled by default since VC2012
181 #if _MSC_VER < 1700
182 #pragma warning(disable:4355)
183 #endif
184 
185 /* Shared memory allocation functions */
186 void * ::operator new(size_t iSize);
187 void ::operator delete(void * ptr);
188 
189 #define DISABLE_WRITEV
190 
191 #include <exception>
192 
193 class CWin32Exception : public std::exception
194 {
195 public:
196  CWin32Exception();
197  CWin32Exception(const CWin32Exception& other);
198  virtual const char* what() const throw();
199  DWORD GetErrorCode();
200 
201 private:
202  char szErrorString[500];
203  DWORD dwErrorCode;
204 };
205 
206 #endif
207 
Definition: inspircd_win32wrapper.h:131
Definition: inspircd_win32wrapper.h:126
Definition: inspircd_win32wrapper.h:115
Definition: inspircd_win32wrapper.h:139
Definition: inspircd_win32wrapper.h:193