summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Powell <petpow@saberuk.com>2013-05-07 03:55:29 +0100
committerattilamolnar <attilamolnar@hush.com>2013-05-07 05:00:33 +0200
commitb89aa87280767f47381b8a612f73f1d0fe682e2e (patch)
tree5d6ee39e4b091e90cb3ff6e629aa80d21e3e4ab4
parent8790551dc182cd8804ee7d8ef89ccb31067cc2a4 (diff)
Clean up cross-platform compatibility.
- Move compatibility macros to a new header file. - Sort system include files in alphabetical order. - Clean up signal handling (thanks to Adam).
-rw-r--r--include/compat.h93
-rw-r--r--include/inspircd.h75
-rw-r--r--src/inspircd.cpp16
-rw-r--r--win/inspircd_win32wrapper.h6
4 files changed, 117 insertions, 73 deletions
diff --git a/include/compat.h b/include/compat.h
new file mode 100644
index 000000000..d3d554b18
--- /dev/null
+++ b/include/compat.h
@@ -0,0 +1,93 @@
+/*
+ * InspIRCd -- Internet Relay Chat Daemon
+ *
+ * Copyright (C) 2013 Peter Powell <petpow@saberuk.com>
+ * Copyright (C) 2008 Thomas Stagner <aquanight@inspircd.org>
+ * Copyright (C) 2007 Robin Burchell <robin+git@viroteck.net>
+ *
+ * This file is part of InspIRCd. InspIRCd is free software: you can
+ * redistribute it and/or modify it under the terms of the GNU General Public
+ * License as published by the Free Software Foundation, version 2.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
+ * details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+
+#pragma once
+
+/**
+ * Some implementations of the C++11 standard library are incomplete so we use
+ * the implementation of the same types from C++ Technical Report 1 instead.
+ */
+#if defined _LIBCPP_VERSION || defined _WIN32
+# define TR1NS std
+# include <unordered_map>
+#else
+# define TR1NS std::tr1
+# include <tr1/unordered_map>
+#endif
+
+/**
+ * This macro enables the compile-time checking of printf format strings. This
+ * makes the compiler show a warning if the format of a printf arguments are
+ * incorrect.
+ */
+#if defined __clang__ || defined __GNUC__
+# define CUSTOM_PRINTF(stringpos, firstpos) __attribute__((format(printf, stringpos, firstpos)))
+#else
+# pragma message ("Warning! CUSTOM_PRINTF() does not work on your compiler!")
+# define CUSTOM_PRINTF(stringpos, firstpos)
+#endif
+
+/**
+ * These macros enable the use of the C++11 override control keywords in
+ * compilers which support them.
+ */
+#if defined __clang__
+# if __has_feature(cxx_override_control)
+# define HAS_CXX11_FINAL_OVERRIDE
+# endif
+#elif (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 7)
+# define HAS_CXX11_FINAL_OVERRIDE
+#elif _MSC_VER >= 1700
+# define HAS_CXX11_FINAL_OVERRIDE
+#endif
+
+#if defined HAS_CXX11_FINAL_OVERRIDE
+# define CXX11_FINAL final
+# define CXX11_OVERRIDE override
+#else
+# define CXX11_FINAL
+# define CXX11_OVERRIDE
+#endif
+
+/**
+ * This macro allows methods to be marked as deprecated. To use this, wrap the
+ * method declaration in the header file with the macro.
+ */
+#if defined __clang__ || defined __GNUC__
+# define DEPRECATED_METHOD(function) function __attribute__((deprecated))
+#elif defined _MSC_VER
+# define DEPRECATED_METHOD(function) __declspec(deprecated) function
+#else
+# pragma message ("Warning! DEPRECATED_METHOD() does not work on your compiler!")
+# define DEPRECATED_METHOD(function) function
+#endif
+
+/**
+ * Windows is very different to UNIX so we have to wrap certain features in
+ * order to build on Windows correctly.
+ */
+#if defined _WIN32
+# include "inspircd_win32wrapper.h"
+#else
+# include <unistd.h>
+# define DllExport
+# define CoreExport
+#endif
diff --git a/include/inspircd.h b/include/inspircd.h
index bc0b9cd1b..b0cd8f675 100644
--- a/include/inspircd.h
+++ b/include/inspircd.h
@@ -25,69 +25,31 @@
#pragma once
-#define _FILE_OFFSET_BITS 64
-#ifndef _LARGEFILE_SOURCE
-#define _LARGEFILE_SOURCE
-#endif
-
-#ifndef _WIN32
-#define DllExport
-#define CoreExport
-#else
-#include "inspircd_win32wrapper.h"
-/** Windows defines these already */
-#undef ERROR
-#endif
-
-#ifdef __GNUC__
-#define CUSTOM_PRINTF(STRING, FIRST) __attribute__((format(printf, STRING, FIRST)))
-#else
-#define CUSTOM_PRINTF(STRING, FIRST)
-#endif
-
-#if defined __clang__ || defined __GNUC__
-# define DEPRECATED_METHOD(function) function __attribute__((deprecated))
-#elif defined _MSC_VER
-# define DEPRECATED_METHOD(function) __declspec(deprecated) function
-#else
-# pragma message ("Warning! DEPRECATED_METHOD() does not work on your compiler!")
-# define DEPRECATED_METHOD(function) function
-#endif
-
-// Required system headers.
-#include <ctime>
-#include <cstdarg>
-#include <algorithm>
-#include <cmath>
-#include <cstring>
#include <climits>
+#include <cmath>
+#include <csignal>
+#include <cstdarg>
#include <cstdio>
-#ifndef _WIN32
-#include <unistd.h>
-#endif
+#include <cstring>
+#include <ctime>
-#if defined _LIBCPP_VERSION || defined _WIN32
-# define TR1NS std
-# include <unordered_map>
-#else
-# define TR1NS std::tr1
-# include <tr1/unordered_map>
-#endif
-#include <sstream>
-#include <string>
-#include <vector>
-#include <list>
+#include <algorithm>
+#include <bitset>
#include <deque>
+#include <list>
#include <map>
-#include <bitset>
#include <set>
-#include <time.h>
-#include "config.h"
+#include <sstream>
+#include <string>
+#include <vector>
+
+#include "compat.h"
#include "typedefs.h"
-#include "consolecolors.h"
CoreExport extern InspIRCd* ServerInstance;
+#include "config.h"
+#include "consolecolors.h"
#include "caller.h"
#include "cull_list.h"
#include "extensible.h"
@@ -112,11 +74,6 @@ CoreExport extern InspIRCd* ServerInstance;
#include "inspstring.h"
#include "protocol.h"
-#ifndef PATH_MAX
-#warning Potentially broken system, PATH_MAX undefined
-#define PATH_MAX 4096
-#endif
-
/**
* Used to define the maximum number of parameters a command may have.
*/
@@ -454,7 +411,7 @@ class CoreExport InspIRCd
/** Set to the current signal recieved
*/
- int s_signal;
+ static sig_atomic_t s_signal;
/** Protocol interface, overridden by server protocol modules
*/
diff --git a/src/inspircd.cpp b/src/inspircd.cpp
index 7b3d36e1c..775e6f130 100644
--- a/src/inspircd.cpp
+++ b/src/inspircd.cpp
@@ -62,7 +62,6 @@
#include "testsuite.h"
InspIRCd* ServerInstance = NULL;
-int* mysig = NULL;
/** Seperate from the other casemap tables so that code *can* still exclusively rely on RFC casemapping
* if it must.
@@ -322,8 +321,6 @@ InspIRCd::InspIRCd(int argc, char** argv) :
/* Default implementation does nothing */
this->PI = new ProtocolInterface;
- this->s_signal = 0;
-
// Create base manager classes early, so nothing breaks
this->Users = new UserManager;
@@ -787,10 +784,10 @@ int InspIRCd::Run()
GlobalCulls.Apply();
AtomicActions.Run();
- if (this->s_signal)
+ if (s_signal)
{
this->SignalHandler(s_signal);
- this->s_signal = 0;
+ s_signal = 0;
}
}
@@ -799,10 +796,6 @@ int InspIRCd::Run()
/**********************************************************************************/
-/**
- * An ircd in five lines! bwahahaha. ahahahahaha. ahahah *cough*.
- */
-
/* this returns true when all modules are satisfied that the user should be allowed onto the irc server
* (until this returns true, a user will block in the waiting state, waiting to connect up to the
* registration timeout maximum seconds)
@@ -814,9 +807,11 @@ bool InspIRCd::AllModulesReportReady(LocalUser* user)
return (res == MOD_RES_PASSTHRU);
}
+sig_atomic_t InspIRCd::s_signal = 0;
+
void InspIRCd::SetSignal(int signal)
{
- *mysig = signal;
+ s_signal = signal;
}
/* On posix systems, the flow of the program starts right here, with
@@ -828,7 +823,6 @@ void InspIRCd::SetSignal(int signal)
ENTRYPOINT
{
new InspIRCd(argc, argv);
- mysig = &ServerInstance->s_signal;
ServerInstance->Run();
delete ServerInstance;
return 0;
diff --git a/win/inspircd_win32wrapper.h b/win/inspircd_win32wrapper.h
index 9b18715cd..a1463b318 100644
--- a/win/inspircd_win32wrapper.h
+++ b/win/inspircd_win32wrapper.h
@@ -43,9 +43,6 @@
#define VC_EXTRALEAN
#define WIN32_LEAN_AND_MEAN
-/* They just have to be *different*, don't they. */
-#define PATH_MAX MAX_PATH
-
/* Macros for exporting symbols - dependant on what is being compiled */
#ifdef DLL_BUILD
@@ -72,6 +69,9 @@
#include <direct.h>
#include <process.h>
+/* Windows defines this already. */
+#undef ERROR
+
/* strcasecmp is not defined on windows by default */
#define strcasecmp _stricmp
#define strncasecmp _strnicmp