From 50ae1838e643d61966bad3490753fb4f4c378b83 Mon Sep 17 00:00:00 2001 From: arvidn Date: Tue, 20 Nov 2018 16:05:40 +0100 Subject: [PATCH] wrap inclusion of windows.h with appropriate defines --- include/libtorrent/Makefile.am | 1 + include/libtorrent/aux_/path.hpp | 5 +- .../libtorrent/aux_/win_crypto_provider.hpp | 2 +- include/libtorrent/aux_/windows.hpp | 50 +++++++++++++++++++ include/libtorrent/file.hpp | 5 +- src/allocator.cpp | 2 +- src/enum_net.cpp | 5 +- src/escape_string.cpp | 5 +- src/path.cpp | 5 +- src/platform_util.cpp | 2 +- test/main.cpp | 2 +- 11 files changed, 60 insertions(+), 24 deletions(-) create mode 100644 include/libtorrent/aux_/windows.hpp diff --git a/include/libtorrent/Makefile.am b/include/libtorrent/Makefile.am index 940143616..58197810e 100644 --- a/include/libtorrent/Makefile.am +++ b/include/libtorrent/Makefile.am @@ -218,6 +218,7 @@ nobase_include_HEADERS = \ aux_/torrent_impl.hpp \ aux_/instantiate_connection.hpp \ aux_/range.hpp \ + aux_/windows.hpp \ \ extensions/smart_ban.hpp \ extensions/ut_metadata.hpp \ diff --git a/include/libtorrent/aux_/path.hpp b/include/libtorrent/aux_/path.hpp index 2cd7301c3..3d852d13e 100644 --- a/include/libtorrent/aux_/path.hpp +++ b/include/libtorrent/aux_/path.hpp @@ -48,10 +48,7 @@ POSSIBILITY OF SUCH DAMAGE. #ifdef TORRENT_WINDOWS // windows part -#ifndef WIN32_LEAN_AND_MEAN -#define WIN32_LEAN_AND_MEAN -#endif -#include +#include "libtorrent/aux_/windows.hpp" #include #include #else diff --git a/include/libtorrent/aux_/win_crypto_provider.hpp b/include/libtorrent/aux_/win_crypto_provider.hpp index 4ad67103e..51cdc1f2f 100644 --- a/include/libtorrent/aux_/win_crypto_provider.hpp +++ b/include/libtorrent/aux_/win_crypto_provider.hpp @@ -36,9 +36,9 @@ POSSIBILITY OF SUCH DAMAGE. #include "libtorrent/config.hpp" #include "libtorrent/error_code.hpp" #include "libtorrent/aux_/throw.hpp" +#include "libtorrent/aux_/windows.hpp" #include "libtorrent/aux_/disable_warnings_push.hpp" -#include #include #include "libtorrent/aux_/disable_warnings_pop.hpp" diff --git a/include/libtorrent/aux_/windows.hpp b/include/libtorrent/aux_/windows.hpp new file mode 100644 index 000000000..ce6fafd9c --- /dev/null +++ b/include/libtorrent/aux_/windows.hpp @@ -0,0 +1,50 @@ +/* + +Copyright (c) 2018, Arvid Norberg, Steven Siloti +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions +are met: + + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in + the documentation and/or other materials provided with the distribution. + * Neither the name of the author nor the names of its + contributors may be used to endorse or promote products derived + from this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +POSSIBILITY OF SUCH DAMAGE. + +*/ + +#ifndef TORRENT_WINDOWS_HPP_INCLUDED +#define TORRENT_WINDOWS_HPP_INCLUDED + +#ifndef WIN32_LEAN_AND_MEAN +#define WIN32_LEAN_AND_MEAN +#endif +#ifndef VC_EXTRALEAN +#define VC_EXTRALEAN +#endif +#ifndef STRICT +#define STRICT +#endif +#include + +#endif // TORRENT_WINDOWS_HPP_INCLUDED + + + diff --git a/include/libtorrent/file.hpp b/include/libtorrent/file.hpp index 11a399d3d..8cbeac990 100644 --- a/include/libtorrent/file.hpp +++ b/include/libtorrent/file.hpp @@ -49,10 +49,7 @@ POSSIBILITY OF SUCH DAMAGE. #ifdef TORRENT_WINDOWS // windows part -#ifndef WIN32_LEAN_AND_MEAN -#define WIN32_LEAN_AND_MEAN -#endif -#include +#include "libtorrent/aux_/windows.hpp" #include #include #else diff --git a/src/allocator.cpp b/src/allocator.cpp index e338f553f..690da303b 100644 --- a/src/allocator.cpp +++ b/src/allocator.cpp @@ -47,7 +47,7 @@ POSSIBILITY OF SUCH DAMAGE. #ifdef TORRENT_WINDOWS // windows.h must be included after stdlib.h under mingw -#include +#include "libtorrent/aux_/windows.hpp" #endif #ifdef TORRENT_MINGW diff --git a/src/enum_net.cpp b/src/enum_net.cpp index 54a06aa7a..8090f8b5a 100644 --- a/src/enum_net.cpp +++ b/src/enum_net.cpp @@ -70,10 +70,7 @@ POSSIBILITY OF SUCH DAMAGE. #endif // TORRENT_USE_SYSCTL #if TORRENT_USE_GETIPFORWARDTABLE || TORRENT_USE_GETADAPTERSADDRESSES -#ifndef WIN32_LEAN_AND_MEAN -#define WIN32_LEAN_AND_MEAN -#endif -#include +#include "libtorrent/aux_/windows.hpp" #include #endif diff --git a/src/escape_string.cpp b/src/escape_string.cpp index f22b16bb1..91c86971a 100644 --- a/src/escape_string.cpp +++ b/src/escape_string.cpp @@ -39,10 +39,7 @@ POSSIBILITY OF SUCH DAMAGE. #include #ifdef TORRENT_WINDOWS -#ifndef WIN32_LEAN_AND_MEAN -#define WIN32_LEAN_AND_MEAN -#endif -#include +#include "libtorrent/aux_/windows.hpp" #endif #if TORRENT_USE_ICONV diff --git a/src/path.cpp b/src/path.cpp index 991d94e52..0855055e2 100644 --- a/src/path.cpp +++ b/src/path.cpp @@ -90,10 +90,7 @@ POSSIBILITY OF SUCH DAMAGE. #include "libtorrent/utf8.hpp" #include "libtorrent/aux_/win_util.hpp" -#ifndef WIN32_LEAN_AND_MEAN -#define WIN32_LEAN_AND_MEAN -#endif -#include +#include "libtorrent/aux_/windows.hpp" #include #ifndef TORRENT_MINGW #include // for _getcwd, _mkdir diff --git a/src/platform_util.cpp b/src/platform_util.cpp index 546957351..ad0a64706 100644 --- a/src/platform_util.cpp +++ b/src/platform_util.cpp @@ -55,7 +55,7 @@ const rlim_t rlim_infinity = RLIM_INFINITY; #endif #if defined TORRENT_WINDOWS -#include +#include "libtorrent/aux_/windows.hpp" #endif #include "libtorrent/aux_/disable_warnings_pop.hpp" diff --git a/test/main.cpp b/test/main.cpp index 72e834d05..c38a3bf63 100644 --- a/test/main.cpp +++ b/test/main.cpp @@ -51,7 +51,7 @@ POSSIBILITY OF SUCH DAMAGE. #include #ifdef _WIN32 -#include // fot SetErrorMode +#include "libtorrent/aux_/windows.hpp" // fot SetErrorMode #include // for _dup and _dup2 #include // for _getpid #include