windows build fixes (and one msvc warning fix)

This commit is contained in:
Arvid Norberg 2009-07-20 01:54:51 +00:00
parent c0b83375bf
commit 310b9d0e51
3 changed files with 14 additions and 5 deletions

View File

@ -36,8 +36,6 @@ POSSIBILITY OF SUCH DAMAGE.
#include <boost/config.hpp>
#include <boost/version.hpp>
#include <stdio.h> // for snprintf
#include <stdlib.h> // for _TRUNCATE (windows)
#include <stdarg.h>
#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 <limits.h>

View File

@ -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

View File

@ -85,7 +85,7 @@ tuple<int, int, bool> 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");