16 * This file is part of InspIRCd. InspIRCd is free software: you can
17 * redistribute it and/or modify it under the terms of the GNU General Public
18 * License as published by the Free Software Foundation, version 2.
19 *
20 * This program is distributed in the hope that it will be useful, but WITHOUT
21 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
22 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
23 * details.
24 *
25 * You should have received a copy of the GNU General Public License
26 * along with this program. If not, see <http://www.gnu.org/licenses/>.
27 */
28
29
30#pragma once
31
32/* Windows Port
33 Wrapper Functions/Definitions
34 By Burlex */
35/*
36 * Starting with PSAPI version 2 for Windows 7 and Windows Server 2008 R2, this function is defined as K32GetProcessMemoryInfo in Psapi.h and exported
37 * in Kernel32.lib and Kernel32.dll. However, you should always call this function as GetProcessMemoryInfo. To ensure correct resolution of symbols
38 * 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.
39 *
40 * We do this before anything to make sure it's done.
41 */
42#define PSAPI_VERSION 1
43
44#include "win32service.h"
45
46/* This defaults to 64, way too small for an ircd! */
47
48#define FD_SETSIZE 24000
49
50/* Make builds smaller, leaner and faster */
51#define VC_EXTRALEAN
52#define WIN32_LEAN_AND_MEAN
53
54/* Macros for exporting symbols - dependent on what is being compiled */
55
56#ifdef DLL_BUILD
57#define CoreExport __declspec(dllimport)
58#define DllExport __declspec(dllexport)
59#else
60#define CoreExport __declspec(dllexport)
61#define DllExport __declspec(dllimport)
62#endif
63
64/* Redirect main() through a different method in win32service.cpp, to intercept service startup */
65#define ENTRYPOINT CoreExport int smain(int argc, char** argv)
66
67/* Disable the deprecation warnings.. it spams :P */
68#define _CRT_SECURE_NO_DEPRECATE
69#define _WINSOCK_DEPRECATED_NO_WARNINGS
70
71// Windows doesn't support getopt_long so we use ya_getopt instead.
72#include "ya_getopt.h"
73
74/* Normal windows (platform-specific) includes */
75#include <winsock2.h>
76#pragma comment(lib, "Ws2_32.lib")
77#include <windows.h>
78#include <ws2tcpip.h>
79#include <sys/types.h>
80#include <sys/stat.h>
81#include <direct.h>
82#include <process.h>
83#include <io.h>
84
85#define F_OK 0 /* test for existence of file */
86#define X_OK (1<<0) /* test for execute or search permission */
87#define W_OK (1<<1) /* test for write permission */
88#define R_OK (1<<2) /* test for read permission */
89
90// Windows defines these already.
91#undef ERROR
92#undef min
93#undef max
94
95/* strcasecmp is not defined on windows by default */
96#define strcasecmp _stricmp
97#define strncasecmp _strnicmp
98
99typedef SSIZE_T ssize_t;
100
101/* _popen, _pclose */
102#define popen _popen
103#define pclose _pclose
104#define getpid _getpid
105
106// warning: 'identifier' : class 'type' needs to have dll-interface to be used by clients of class 'type2'
107// Normally, this is a huge problem, but due to our new/delete remap, we can ignore it.
108#pragma warning(disable:4251)
109
110// warning: DLL-interface classkey 'identifier' used as base for DLL-interface classkey 'identifier'
111#pragma warning(disable:4275)
112
113// warning: unreferenced formal parameter
114// Unimportant for now, but for the next version, we should take a look at these again.
115#pragma warning(disable:4100)
116
117// warning: 'class' : assignment operator could not be generated
118#pragma warning(disable:4512)
119
120// warning C4127: conditional expression is constant
121// This will be triggered like crazy because FOREACH_MOD and similar macros are wrapped in do { ... } while(0) constructs
122#pragma warning(disable:4127)
123
124// warning C4996: The POSIX name for this item is deprecated.
125#pragma warning(disable:4996)
126
127// warning C4244: conversion from 'x' to 'y', possible loss of data
128#pragma warning(disable:4244)
129
130// warning C4267: 'var' : conversion from 'size_t' to 'type', possible loss of data
131#pragma warning(disable:4267)
132
133// warning C4706: assignment within conditional expression
134#pragma warning(disable:4706)
135
136// warning C4800: 'type' : forcing value to bool 'true' or 'false' (performance warning)