From 310b9d0e514d9e5e294f8012351a60e4fb21d7e2 Mon Sep 17 00:00:00 2001 From: Arvid Norberg Date: Mon, 20 Jul 2009 01:54:51 +0000 Subject: [PATCH] windows build fixes (and one msvc warning fix) --- include/libtorrent/config.hpp | 9 ++++++--- include/libtorrent/kademlia/node.hpp | 2 +- test/test_primitives.cpp | 8 +++++++- 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/include/libtorrent/config.hpp b/include/libtorrent/config.hpp index 72eb05499..06ef31d0c 100644 --- a/include/libtorrent/config.hpp +++ b/include/libtorrent/config.hpp @@ -36,8 +36,6 @@ POSSIBILITY OF SUCH DAMAGE. #include #include #include // for snprintf -#include // for _TRUNCATE (windows) -#include #ifndef WIN32 #define __STDC_FORMAT_MACROS @@ -128,12 +126,17 @@ POSSIBILITY OF SUCH DAMAGE. // this is the maximum number of characters in a // path element / filename on windows #define NAME_MAX 255 + inline int snprintf(char* buf, int len, char const* fmt, ...) { va_list lp; va_start(lp, fmt); - return vsnprintf_s(buf, len, _TRUNCATE, fmt, lp); + int ret = _vsnprintf(buf, len, fmt, lp); + va_end(lp); + if (ret < 0) { buf[len-1] = 0; ret = len-1; } + return ret; } + #define strtoll _strtoi64 #else #include diff --git a/include/libtorrent/kademlia/node.hpp b/include/libtorrent/kademlia/node.hpp index d385c3422..b2d5f6059 100644 --- a/include/libtorrent/kademlia/node.hpp +++ b/include/libtorrent/kademlia/node.hpp @@ -69,7 +69,7 @@ namespace libtorrent { namespace dht TORRENT_DECLARE_LOG(node); #endif -struct traversal_algorithm; +class traversal_algorithm; // this is the entry for every peer // the timestamp is there to make it possible diff --git a/test/test_primitives.cpp b/test/test_primitives.cpp index a38f3482a..3f37f919c 100644 --- a/test/test_primitives.cpp +++ b/test/test_primitives.cpp @@ -85,7 +85,7 @@ tuple feed_bytes(http_parser& parser, char const* str) tie(payload, protocol) = parser.incoming(recv_buf, error); ret.get<0>() += payload; ret.get<1>() += protocol; - ret.get<2>() += error; + ret.get<2>() |= error; // std::cerr << payload << ", " << protocol << ", " << chunk_size << std::endl; TORRENT_ASSERT(payload + protocol == chunk_size); } @@ -359,6 +359,12 @@ int test_main() { using namespace libtorrent; + // test snprintf + + char msg[10]; + snprintf(msg, sizeof(msg), "too %s format string", "long"); + TEST_CHECK(strcmp(msg, "too long ") == 0); + // test maybe_url_encode TEST_CHECK(maybe_url_encode("http://test:test@abc.com/abc<>abc") == "http://test:test@abc.com:80/abc%3c%3eabc");