]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - include/compat.h
Improve behaviour when running as root.
[user/henk/code/inspircd.git] / include / compat.h
1 /*
2  * InspIRCd -- Internet Relay Chat Daemon
3  *
4  *   Copyright (C) 2013 Peter Powell <petpow@saberuk.com>
5  *   Copyright (C) 2008 Thomas Stagner <aquanight@inspircd.org>
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 #pragma once
23
24 /**
25  * Some implementations of the C++11 standard library are incomplete so we use
26  * the implementation of the same types from C++ Technical Report 1 instead.
27  */
28 #if defined _LIBCPP_VERSION || defined _WIN32
29 # define TR1NS std
30 # include <array>
31 # include <functional>
32 # include <unordered_map>
33 # include <type_traits>
34 #else
35 # define TR1NS std::tr1
36 # include <tr1/array>
37 # include <tr1/functional>
38 # include <tr1/unordered_map>
39 # include <tr1/type_traits>
40 #endif
41
42 /**
43  * This macro enables the compile-time checking of printf format strings. This
44  * makes the compiler show a warning if the format of a printf arguments are
45  * incorrect.
46  */
47 #if defined __clang__ || defined __GNUC__
48 # define CUSTOM_PRINTF(stringpos, firstpos) __attribute__((format(printf, stringpos, firstpos)))
49 #else
50 # define CUSTOM_PRINTF(stringpos, firstpos)
51 #endif
52
53 /**
54  * These macros enable the use of the C++11 override control keywords in
55  * compilers which support them.
56  */
57 #if __cplusplus >= 201103L
58 # define HAS_CXX11_FINAL_OVERRIDE
59 #elif defined __clang__
60 # if __has_feature(cxx_override_control)
61 #  define HAS_CXX11_FINAL_OVERRIDE
62 # endif
63 #elif (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 7)
64 # if defined __GXX_EXPERIMENTAL_CXX0X__
65 #  define HAS_CXX11_FINAL_OVERRIDE
66 # endif
67 #elif _MSC_VER >= 1700
68 # define HAS_CXX11_FINAL_OVERRIDE
69 #endif
70
71 #if defined HAS_CXX11_FINAL_OVERRIDE
72 # define CXX11_FINAL final
73 # define CXX11_OVERRIDE override
74 #else
75 # define CXX11_FINAL
76 # define CXX11_OVERRIDE
77 #endif
78
79 /**
80  * This macro allows methods to be marked as deprecated. To use this, wrap the
81  * method declaration in the header file with the macro.
82  */
83 #if defined __clang__ || defined __GNUC__
84 # define DEPRECATED_METHOD(function) function __attribute__((deprecated))
85 #elif defined _MSC_VER
86 # define DEPRECATED_METHOD(function) __declspec(deprecated) function
87 #else
88 # define DEPRECATED_METHOD(function) function
89 #endif
90
91 /**
92  * Windows is very different to UNIX so we have to wrap certain features in
93  * order to build on Windows correctly.
94  */
95 #if defined _WIN32
96 # include "inspircd_win32wrapper.h"
97 # include "threadengines/threadengine_win32.h"
98 #else
99 # define ENTRYPOINT int main(int argc, char** argv)
100 # define DllExport __attribute__ ((visibility ("default")))
101 # define CoreExport __attribute__ ((visibility ("default")))
102 # include <unistd.h>
103 # include "threadengines/threadengine_pthread.h"
104 #endif