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
61 #define _WINSOCK_DEPRECATED_NO_WARNINGS
63 /* Normal windows (platform-specific) includes */
65 #pragma comment(lib, "Ws2_32.lib")
68 #include <sys/types.h>
74 #define F_OK 0 /* test for existence of file */
75 #define X_OK (1<<0) /* test for execute or search permission */
76 #define W_OK (1<<1) /* test for write permission */
77 #define R_OK (1<<2) /* test for read permission */
79 // Windows defines these already.
84 /* strcasecmp is not defined on windows by default */
85 #define strcasecmp _stricmp
86 #define strncasecmp _strnicmp
88 typedef SSIZE_T ssize_t;
92 #define pclose _pclose
94 /* getopt() wrapper */
96 #define required_argument 1
97 #define optional_argument 2
106 extern char optarg[514];
107 int getopt_long(int ___argc, char *const *___argv, const char *__shortopts, const struct option *__longopts, int *__longind);
109 // warning: 'identifier' : class 'type' needs to have dll-interface to be used by clients of class 'type2'
110 // Normally, this is a huge problem, but due to our new/delete remap, we can ignore it.
111 #pragma warning(disable:4251)
113 // warning: DLL-interface classkey 'identifier' used as base for DLL-interface classkey 'identifier'
114 #pragma warning(disable:4275)
116 // warning: unreferenced formal parameter
117 // Unimportant for now, but for the next version, we should take a look at these again.
118 #pragma warning(disable:4100)
120 // warning: 'class' : assignment operator could not be generated
121 #pragma warning(disable:4512)
123 // warning C4127: conditional expression is constant
124 // This will be triggered like crazy because FOREACH_MOD and similar macros are wrapped in do { ... } while(0) constructs
125 #pragma warning(disable:4127)
127 // warning C4996: The POSIX name for this item is deprecated.
128 #pragma warning(disable:4996)
130 // warning C4244: conversion from 'x' to 'y', possible loss of data
131 #pragma warning(disable:4244)
133 // warning C4267: 'var' : conversion from 'size_t' to 'type', possible loss of data
134 #pragma warning(disable:4267)
136 // warning C4706: assignment within conditional expression
137 #pragma warning(disable:4706)
139 /* Shared memory allocation functions */
140 void * ::operator new(size_t iSize);
141 void ::operator delete(void * ptr);
145 class CWin32Exception : public std::exception
149 CWin32Exception(const CWin32Exception& other);
150 virtual const char* what() const throw();
151 DWORD GetErrorCode();
154 char szErrorString[500];
158 // Same value as EXIT_STATUS_FORK (EXIT_STATUS_FORK is unused on Windows)
159 #define EXIT_STATUS_SERVICE 4
164 void* iov_base; // Starting address
165 size_t iov_len; // Number of bytes to transfer
168 // Windows WSABUF with POSIX field names
171 // POSIX iovec has iov_base then iov_len, WSABUF in Windows has the fields in reverse order
172 u_long iov_len; // Number of bytes to transfer
173 char FAR* iov_base; // Starting address
176 inline ssize_t writev(int fd, const WindowsIOVec* iov, int count)
179 int ret = WSASend(fd, reinterpret_cast<LPWSABUF>(const_cast<WindowsIOVec*>(iov)), count, &sent, 0, NULL, NULL);
185 // This wrapper is just so we don't need to do #ifdef _WIN32 everywhere in the socket code. It is
186 // not actually used and does not need to be the same size as sockaddr_un on UNIX systems.
189 ADDRESS_FAMILY sun_family;