2 * InspIRCd -- Internet Relay Chat Daemon
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>
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.
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
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/>.
25 Wrapper Functions/Definitions
28 * Starting with PSAPI version 2 for Windows 7 and Windows Server 2008 R2, this function is defined as K32GetProcessMemoryInfo in Psapi.h and exported
29 * in Kernel32.lib and Kernel32.dll. However, you should always call this function as GetProcessMemoryInfo. To ensure correct resolution of symbols
30 * 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.
32 * We do this before anything to make sure it's done.
34 #define PSAPI_VERSION 1
36 #include "win32service.h"
38 /* This defaults to 64, way too small for an ircd! */
40 #define FD_SETSIZE 24000
42 /* Make builds smaller, leaner and faster */
44 #define WIN32_LEAN_AND_MEAN
46 /* Macros for exporting symbols - dependant on what is being compiled */
49 #define CoreExport __declspec(dllimport)
50 #define DllExport __declspec(dllexport)
52 #define CoreExport __declspec(dllexport)
53 #define DllExport __declspec(dllimport)
56 /* Redirect main() through a different method in win32service.cpp, to intercept service startup */
57 #define ENTRYPOINT CoreExport int smain(int argc, char** argv)
59 /* Disable the deprecation warnings.. it spams :P */
60 #define _CRT_SECURE_NO_DEPRECATE
62 /* Normal windows (platform-specific) includes */
64 #pragma comment(lib, "Ws2_32.lib")
67 #include <sys/types.h>
73 #define F_OK 0 /* test for existence of file */
74 #define X_OK (1<<0) /* test for execute or search permission */
75 #define W_OK (1<<1) /* test for write permission */
76 #define R_OK (1<<2) /* test for read permission */
78 // Windows defines these already.
83 /* strcasecmp is not defined on windows by default */
84 #define strcasecmp _stricmp
85 #define strncasecmp _strnicmp
87 /* Convert formatted (xxx.xxx.xxx.xxx) string to in_addr struct */
88 CoreExport int insp_inet_pton(int af, const char * src, void * dst);
90 /* Convert struct to formatted (xxx.xxx.xxx.xxx) string */
91 CoreExport const char * insp_inet_ntop(int af, const void * src, char * dst, socklen_t cnt);
93 /* inet_pton/ntop require at least NT 6.0 */
94 #define inet_pton insp_inet_pton
95 #define inet_ntop insp_inet_ntop
97 /* Safe printf functions aren't defined in VC++ */
98 #define snprintf _snprintf
99 #define vsnprintf _vsnprintf
102 #define va_copy(dest, src) (dest = src)
105 /* Unix-style sleep (argument is in seconds) */
106 __inline void sleep(int seconds) { Sleep(seconds * 1000); }
108 /* _popen, _pclose */
110 #define pclose _pclose
113 #define access _access
115 /* IPV4 only convert string to address struct */
116 __inline int inet_aton(const char *cp, struct in_addr *addr)
118 addr->s_addr = inet_addr(cp);
119 return (addr->s_addr == INADDR_NONE) ? 0 : 1;
122 /* getopt() wrapper */
123 #define no_argument 0
124 #define required_argument 1
125 #define optional_argument 2
134 extern char optarg[514];
135 int getopt_long(int ___argc, char *const *___argv, const char *__shortopts, const struct option *__longopts, int *__longind);
139 char d_name[MAX_PATH];
144 dirent dirent_pointer;
146 WIN32_FIND_DATAA find_data;
156 CoreExport DIR * opendir(const char * path);
157 CoreExport dirent * readdir(DIR * handle);
158 CoreExport void closedir(DIR * handle);
160 // warning: 'identifier' : class 'type' needs to have dll-interface to be used by clients of class 'type2'
161 // Normally, this is a huge problem, but due to our new/delete remap, we can ignore it.
162 #pragma warning(disable:4251)
164 // warning: DLL-interface classkey 'identifier' used as base for DLL-interface classkey 'identifier'
165 #pragma warning(disable:4275)
167 // warning: unreferenced formal parameter
168 // Unimportant for now, but for the next version, we should take a look at these again.
169 #pragma warning(disable:4100)
171 // warning: 'class' : assignment operator could not be generated
172 #pragma warning(disable:4512)
174 // warning C4127: conditional expression is constant
175 // This will be triggered like crazy because FOREACH_MOD and similar macros are wrapped in do { ... } while(0) constructs
176 #pragma warning(disable:4127)
178 // warning C4996: The POSIX name for this item is deprecated.
179 #pragma warning(disable:4996)
181 // warning C4244: conversion from 'x' to 'y', possible loss of data
182 #pragma warning(disable:4244)
184 // warning C4267: 'var' : conversion from 'size_t' to 'type', possible loss of data
185 #pragma warning(disable:4267)
187 // warning C4706: assignment within conditional expression
188 #pragma warning(disable:4706)
190 // warning C4355: 'this' : used in base member initializer list
191 // This warning is disabled by default since VC2012
193 #pragma warning(disable:4355)
196 /* Shared memory allocation functions */
197 void * ::operator new(size_t iSize);
198 void ::operator delete(void * ptr);
200 #define DISABLE_WRITEV
204 class CWin32Exception : public std::exception
208 CWin32Exception(const CWin32Exception& other);
209 virtual const char* what() const throw();
210 DWORD GetErrorCode();
213 char szErrorString[500];
217 // Same value as EXIT_STATUS_FORK (EXIT_STATUS_FORK is unused on Windows)
218 #define EXIT_STATUS_SERVICE 4