From 3cdf9c87a8ad8b1167263f1249de3e544d98ffea Mon Sep 17 00:00:00 2001 From: Arvid Norberg Date: Tue, 27 Jan 2009 08:24:48 +0000 Subject: [PATCH] fixed build errors on Solaris --- ChangeLog | 1 + Jamfile | 18 ++++++++++++++---- docs/building.rst | 5 +++++ examples/client_test.cpp | 2 +- include/libtorrent/GeoIP.h | 6 +++--- include/libtorrent/alert_types.hpp | 24 ++++++++++++------------ include/libtorrent/bitfield.hpp | 20 ++++++++++---------- include/libtorrent/config.hpp | 2 ++ include/libtorrent/xml_parse.hpp | 2 +- src/enum_net.cpp | 18 +++++++++++------- src/file_storage.cpp | 2 +- src/http_parser.cpp | 3 ++- src/http_stream.cpp | 4 ++-- src/identify_client.cpp | 1 + src/kademlia/routing_table.cpp | 2 +- src/kademlia/rpc_manager.cpp | 4 ++-- src/lsd.cpp | 2 +- src/parse_url.cpp | 2 +- src/piece_picker.cpp | 2 +- src/session.cpp | 1 - src/torrent.cpp | 1 - src/torrent_handle.cpp | 1 - src/torrent_info.cpp | 13 +++++++++---- src/udp_tracker_connection.cpp | 6 +++--- src/upnp.cpp | 4 ++-- src/web_peer_connection.cpp | 3 ++- 26 files changed, 88 insertions(+), 61 deletions(-) diff --git a/ChangeLog b/ChangeLog index 651de45c2..1503eb23b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -49,6 +49,7 @@ release 0.14.2 be torrent_handle::piece_priorities) * fixed race condition when saving DHT state * fixed bugs related to lexical_cast being locale dependent + * added support for SunPro C++ compiler release 0.14.1 diff --git a/Jamfile b/Jamfile index 584217632..642aa78e2 100755 --- a/Jamfile +++ b/Jamfile @@ -70,6 +70,11 @@ rule linking ( properties * ) ; } + if solaris in $(properties) + { + result += libsocket libnsl ; + } + if on in $(properties) && ( gcc in $(properties) || darwin in $(properties) ) @@ -135,7 +140,8 @@ rule linking ( properties * ) { result += /boost/thread//boost_thread/shared /boost/filesystem//boost_filesystem/shared - /boost/system//boost_system/shared ; + /boost/system//boost_system/shared + ; } result += $(BOOST_ROOT) BOOST_ALL_NO_LIB ; } @@ -275,19 +281,22 @@ lib user32 : : User32 ; lib shell32 : : shell32 ; lib gdi32 : : gdi32 ; -local library-search-path = /opt/local/lib /usr/lib /usr/local/lib /sw/lib ; +local library-search-path = /opt/local/lib /usr/lib /usr/local/lib /sw/lib /usr/sfw/lib ; lib boost_filesystem : : boost_filesystem $(library-search-path) ; lib boost_thread : : boost_thread $(library-search-path) ; lib boost_system : : boost_system $(library-search-path) ; # openssl on linux/bsd/macos etc. -lib crypto : : crypto ; -lib ssl : : ssl ; +lib crypto : : crypto $(library-search-path) ; +lib ssl : : ssl $(library-search-path) ; # time functions used on linux require librt lib librt : : rt ; +lib libsocket : : libnsl socket shared $(library-search-path) ; +lib libnsl : : nsl shared $(library-search-path) ; + lib tcmalloc : : tcmalloc $(library-search-path) ; # libz @@ -390,6 +399,7 @@ ZLIB_SOURCES = local usage-requirements = ./include ./include/libtorrent + /usr/sfw/include shipped:./zlib release:NDEBUG debug:TORRENT_DEBUG diff --git a/docs/building.rst b/docs/building.rst index f37dd3362..142f947f1 100644 --- a/docs/building.rst +++ b/docs/building.rst @@ -195,6 +195,11 @@ the runtime, but on windows you can do both. Example:: symbol ``clock_gettime``, you have to give ``need-librt=yes`` on the bjam command line. This will make libtorrent link against ``librt``. +.. note:: + + When building on Solaris, you might have to specify ``stdlib=sun-stlport`` + on the bjam command line. + The build targets are put in a directory called bin, and under it they are sorted in directories depending on the toolset and build variant used. diff --git a/examples/client_test.cpp b/examples/client_test.cpp index b5a288131..3de5c55f4 100644 --- a/examples/client_test.cpp +++ b/examples/client_test.cpp @@ -232,7 +232,7 @@ std::string const& add_suffix(float val) for (int i = 0; i < num_prefix; ++i) { val /= 1000.f; - if (fabs(val) < 1000.f) + if (std::fabs(val) < 1000.f) { std::string& ret = to_string(val, 4); ret += prefix[i]; diff --git a/include/libtorrent/GeoIP.h b/include/libtorrent/GeoIP.h index d493eccb9..74d5c66c7 100644 --- a/include/libtorrent/GeoIP.h +++ b/include/libtorrent/GeoIP.h @@ -69,7 +69,7 @@ typedef enum { GEOIP_MEMORY_CACHE = 1, GEOIP_CHECK_CACHE = 2, GEOIP_INDEX_CACHE = 4, - GEOIP_MMAP_CACHE = 8, + GEOIP_MMAP_CACHE = 8 } GeoIPOptions; typedef enum { @@ -89,14 +89,14 @@ typedef enum { typedef enum { GEOIP_ANON_PROXY = 1, GEOIP_HTTP_X_FORWARDED_FOR_PROXY = 2, - GEOIP_HTTP_CLIENT_IP_PROXY = 3, + GEOIP_HTTP_CLIENT_IP_PROXY = 3 } GeoIPProxyTypes; typedef enum { GEOIP_UNKNOWN_SPEED = 0, GEOIP_DIALUP_SPEED = 1, GEOIP_CABLEDSL_SPEED = 2, - GEOIP_CORPORATE_SPEED = 3, + GEOIP_CORPORATE_SPEED = 3 } GeoIPNetspeedValues; extern char **GeoIPDBFileName; diff --git a/include/libtorrent/alert_types.hpp b/include/libtorrent/alert_types.hpp index ed6662f84..75298bdbb 100644 --- a/include/libtorrent/alert_types.hpp +++ b/include/libtorrent/alert_types.hpp @@ -258,9 +258,9 @@ namespace libtorrent tracker_error_alert(torrent_handle const& h , int times , int status - , std::string const& url + , std::string const& url_ , std::string const& msg_) - : tracker_alert(h, url) + : tracker_alert(h, url_) , times_in_row(times) , status_code(status) , msg(msg_) @@ -287,9 +287,9 @@ namespace libtorrent struct TORRENT_EXPORT tracker_warning_alert: tracker_alert { tracker_warning_alert(torrent_handle const& h - , std::string const& url + , std::string const& url_ , std::string const& msg_) - : tracker_alert(h, url) + : tracker_alert(h, url_) , msg(msg_) { TORRENT_ASSERT(!url.empty()); } @@ -311,8 +311,8 @@ namespace libtorrent scrape_reply_alert(torrent_handle const& h , int incomplete_ , int complete_ - , std::string const& url) - : tracker_alert(h, url) + , std::string const& url_) + : tracker_alert(h, url_) , incomplete(incomplete_) , complete(complete_) { TORRENT_ASSERT(!url.empty()); } @@ -335,9 +335,9 @@ namespace libtorrent struct TORRENT_EXPORT scrape_failed_alert: tracker_alert { scrape_failed_alert(torrent_handle const& h - , std::string const& url + , std::string const& url_ , std::string const& msg_) - : tracker_alert(h, url) + : tracker_alert(h, url_) , msg(msg_) { TORRENT_ASSERT(!url.empty()); } @@ -358,8 +358,8 @@ namespace libtorrent { tracker_reply_alert(torrent_handle const& h , int np - , std::string const& url) - : tracker_alert(h, url) + , std::string const& url_) + : tracker_alert(h, url_) , num_peers(np) { TORRENT_ASSERT(!url.empty()); } @@ -402,8 +402,8 @@ namespace libtorrent struct TORRENT_EXPORT tracker_announce_alert: tracker_alert { tracker_announce_alert(torrent_handle const& h - , std::string const& url, int event_) - : tracker_alert(h, url) + , std::string const& url_, int event_) + : tracker_alert(h, url_) , event(event_) { TORRENT_ASSERT(!url.empty()); } diff --git a/include/libtorrent/bitfield.hpp b/include/libtorrent/bitfield.hpp index 740b20ffe..db0ca1cd4 100644 --- a/include/libtorrent/bitfield.hpp +++ b/include/libtorrent/bitfield.hpp @@ -60,7 +60,7 @@ namespace libtorrent ~bitfield() { dealloc(); } void assign(char const* bytes, int bits) - { resize(bits); memcpy(m_bytes, bytes, (bits + 7) / 8); } + { resize(bits); std::memcpy(m_bytes, bytes, (bits + 7) / 8); } bool operator[](int index) const { return get_bit(index); } @@ -197,23 +197,23 @@ namespace libtorrent { if (old_size_bytes && b) m_bytes[old_size_bytes - 1] |= (0xff >> b); if (old_size_bytes < new_size_bytes) - memset(m_bytes + old_size_bytes, 0xff, new_size_bytes - old_size_bytes); + std::memset(m_bytes + old_size_bytes, 0xff, new_size_bytes - old_size_bytes); } else { if (old_size_bytes < new_size_bytes) - memset(m_bytes + old_size_bytes, 0x00, new_size_bytes - old_size_bytes); + std::memset(m_bytes + old_size_bytes, 0x00, new_size_bytes - old_size_bytes); } } void set_all() { - memset(m_bytes, 0xff, (m_size + 7) / 8); + std::memset(m_bytes, 0xff, (m_size + 7) / 8); } void clear_all() { - memset(m_bytes, 0x00, (m_size + 7) / 8); + std::memset(m_bytes, 0x00, (m_size + 7) / 8); } void resize(int bits) @@ -223,20 +223,20 @@ namespace libtorrent { if (m_own) { - m_bytes = (unsigned char*)realloc(m_bytes, bytes); + m_bytes = (unsigned char*)std::realloc(m_bytes, bytes); m_own = true; } else if (bits > m_size) { - unsigned char* tmp = (unsigned char*)malloc(bytes); - memcpy(tmp, m_bytes, (std::min)((m_size + 7)/ 8, bytes)); + unsigned char* tmp = (unsigned char*)std::malloc(bytes); + std::memcpy(tmp, m_bytes, (std::min)((m_size + 7)/ 8, bytes)); m_bytes = tmp; m_own = true; } } else { - m_bytes = (unsigned char*)malloc(bytes); + m_bytes = (unsigned char*)std::malloc(bytes); m_own = true; } m_size = bits; @@ -246,7 +246,7 @@ namespace libtorrent private: - void dealloc() { if (m_own) free(m_bytes); m_bytes = 0; } + void dealloc() { if (m_own) std::free(m_bytes); m_bytes = 0; } unsigned char* m_bytes; int m_size; // in bits bool m_own; diff --git a/include/libtorrent/config.hpp b/include/libtorrent/config.hpp index 326c675e3..00ab52483 100644 --- a/include/libtorrent/config.hpp +++ b/include/libtorrent/config.hpp @@ -77,6 +77,8 @@ POSSIBILITY OF SUCH DAMAGE. #define TORRENT_LINUX #elif defined WIN32 #define TORRENT_WINDOWS +#elif defined sun || defined __sun +#define TORRENT_SOLARIS #else #warning unkown OS, assuming BSD #define TORRENT_BSD diff --git a/include/libtorrent/xml_parse.hpp b/include/libtorrent/xml_parse.hpp index aaf71a816..4e53afeea 100644 --- a/include/libtorrent/xml_parse.hpp +++ b/include/libtorrent/xml_parse.hpp @@ -128,7 +128,7 @@ namespace libtorrent *(p-1) = '?'; tag_end = p - 1; } - else if (start + 5 < p && memcmp(start, "!--", 3) == 0 && memcmp(p-2, "--", 2) == 0) + else if (start + 5 < p && std::memcmp(start, "!--", 3) == 0 && std::memcmp(p-2, "--", 2) == 0) { start += 3; *(p-2) = 0; diff --git a/src/enum_net.cpp b/src/enum_net.cpp index 7f2a1fef7..babdd94b9 100644 --- a/src/enum_net.cpp +++ b/src/enum_net.cpp @@ -41,16 +41,20 @@ POSSIBILITY OF SUCH DAMAGE. #include #endif -#if defined TORRENT_BSD +#if defined TORRENT_BSD || defined TORRENT_SOLARIS #include #include #include #include #include -#include +#include #include #endif +#if defined TORRENT_BSD +#include +#endif + #if defined TORRENT_WINDOWS #ifndef WIN32_LEAN_AND_MEAN #define WIN32_LEAN_AND_MEAN @@ -83,7 +87,7 @@ namespace libtorrent { namespace { typedef asio::ip::address_v4::bytes_type bytes_t; bytes_t b; - memcpy(&b[0], ina, b.size()); + std::memcpy(&b[0], ina, b.size()); return address_v4(b); } @@ -91,7 +95,7 @@ namespace libtorrent { namespace { typedef asio::ip::address_v6::bytes_type bytes_t; bytes_t b; - memcpy(&b[0], ina6, b.size()); + std::memcpy(&b[0], ina6, b.size()); return address_v6(b); } @@ -244,11 +248,11 @@ namespace libtorrent { std::vector ret; // covers linux, MacOS X and BSD distributions -#if defined TORRENT_LINUX || defined TORRENT_BSD +#if defined TORRENT_LINUX || defined TORRENT_BSD || defined TORRENT_SOLARIS int s = socket(AF_INET, SOCK_DGRAM, 0); if (s < 0) { - ec = asio::error::fault; + ec = error_code(errno, asio::error::system_category); return ret; } ifconf ifc; @@ -300,7 +304,7 @@ namespace libtorrent #if defined TORRENT_BSD int current_size = item.ifr_addr.sa_len + IFNAMSIZ; -#elif defined TORRENT_LINUX +#elif defined TORRENT_LINUX || defined TORRENT_SOLARIS int current_size = sizeof(ifreq); #endif ifr += current_size; diff --git a/src/file_storage.cpp b/src/file_storage.cpp index 6765766e6..30de3bf22 100644 --- a/src/file_storage.cpp +++ b/src/file_storage.cpp @@ -285,7 +285,7 @@ namespace libtorrent i->offset = off; i->file_base = 0; char name[10]; - sprintf(name, "%d", padding_file); + std::sprintf(name, "%d", padding_file); i->path = *(i+1)->path.begin(); i->path /= "_____padding_file_"; i->path /= name; diff --git a/src/http_parser.cpp b/src/http_parser.cpp index eb717420f..226cf6bdf 100644 --- a/src/http_parser.cpp +++ b/src/http_parser.cpp @@ -34,6 +34,7 @@ POSSIBILITY OF SUCH DAMAGE. #include #include +#include #include "libtorrent/config.hpp" #include "libtorrent/http_parser.hpp" @@ -162,7 +163,7 @@ namespace libtorrent if (name == "content-length") { -#ifdef WIN32 +#ifdef TORRENT_WINDOWS m_content_length = _atoi64(value.c_str()); #else m_content_length = atoll(value.c_str()); diff --git a/src/http_stream.cpp b/src/http_stream.cpp index eaa636bf1..392935941 100644 --- a/src/http_stream.cpp +++ b/src/http_stream.cpp @@ -134,7 +134,7 @@ namespace libtorrent if (found_end) { m_buffer.push_back(0); - char* status = strchr(&m_buffer[0], ' '); + char* status = std::strchr(&m_buffer[0], ' '); if (status == 0) { (*h)(asio::error::operation_not_supported); @@ -144,7 +144,7 @@ namespace libtorrent } status++; - int code = atoi(status); + int code = std::atoi(status); if (code != 200) { (*h)(asio::error::operation_not_supported); diff --git a/src/identify_client.cpp b/src/identify_client.cpp index 93a243d98..895792884 100644 --- a/src/identify_client.cpp +++ b/src/identify_client.cpp @@ -34,6 +34,7 @@ POSSIBILITY OF SUCH DAMAGE. #include #include +#include #ifdef _MSC_VER #pragma warning(push, 1) diff --git a/src/kademlia/routing_table.cpp b/src/kademlia/routing_table.cpp index 5610b3853..d0dde5416 100644 --- a/src/kademlia/routing_table.cpp +++ b/src/kademlia/routing_table.cpp @@ -274,7 +274,7 @@ void routing_table::node_failed(node_id const& id) b.erase(i); - i = find_if(rb.begin(), rb.end(), bind(&node_entry::pinged, _1) == true); + i = std::find_if(rb.begin(), rb.end(), bind(&node_entry::pinged, _1) == true); if (i == rb.end()) i = rb.begin(); b.push_back(*i); rb.erase(i); diff --git a/src/kademlia/rpc_manager.cpp b/src/kademlia/rpc_manager.cpp index 264fd991f..eb8d8bff6 100644 --- a/src/kademlia/rpc_manager.cpp +++ b/src/kademlia/rpc_manager.cpp @@ -82,7 +82,7 @@ void intrusive_ptr_release(observer const* o) if (--o->m_refs == 0) { boost::pool<>& p = o->pool_allocator; - o->~observer(); + (const_cast(o))->~observer(); p.free(const_cast(o)); } } @@ -105,7 +105,7 @@ typedef mpl::max_element< rpc_manager::rpc_manager(fun const& f, node_id const& our_id , routing_table& table, send_fun const& sf) : m_pool_allocator(sizeof(mpl::deref::type)) - , m_next_transaction_id(rand() % max_transactions) + , m_next_transaction_id(std::rand() % max_transactions) , m_oldest_transaction_id(m_next_transaction_id) , m_incoming(f) , m_send(sf) diff --git a/src/lsd.cpp b/src/lsd.cpp index 495b0efd1..0e63d4856 100644 --- a/src/lsd.cpp +++ b/src/lsd.cpp @@ -175,7 +175,7 @@ void lsd::on_announce(udp::endpoint const& from, char* buffer sha1_hash ih(0); std::istringstream ih_sstr(ih_str); ih_sstr >> ih; - int port = atoi(port_str.c_str()); + int port = std::atoi(port_str.c_str()); if (!ih.is_all_zeros() && port != 0) { diff --git a/src/parse_url.cpp b/src/parse_url.cpp index 2d54277c3..c7e412c95 100644 --- a/src/parse_url.cpp +++ b/src/parse_url.cpp @@ -115,7 +115,7 @@ namespace libtorrent { hostname.assign(start, port_pos); ++port_pos; - port = atoi(std::string(port_pos, end).c_str()); + port = std::atoi(std::string(port_pos, end).c_str()); } else { diff --git a/src/piece_picker.cpp b/src/piece_picker.cpp index 370061205..590798726 100644 --- a/src/piece_picker.cpp +++ b/src/piece_picker.cpp @@ -1487,7 +1487,7 @@ namespace libtorrent // we're not using rarest first (only for the first // bucket, since that's where the currently downloading // pieces are) - int start_piece = rand() % m_piece_map.size(); + int start_piece = std::rand() % m_piece_map.size(); int piece = start_piece; while (num_blocks > 0) diff --git a/src/session.cpp b/src/session.cpp index 9db0ec52e..a0b239d8a 100644 --- a/src/session.cpp +++ b/src/session.cpp @@ -81,7 +81,6 @@ POSSIBILITY OF SUCH DAMAGE. using boost::shared_ptr; using boost::weak_ptr; using boost::bind; -using boost::mutex; using libtorrent::aux::session_impl; #ifdef TORRENT_MEMDEBUG diff --git a/src/torrent.cpp b/src/torrent.cpp index 23229c5f1..b92cd0ab9 100644 --- a/src/torrent.cpp +++ b/src/torrent.cpp @@ -84,7 +84,6 @@ using boost::tuples::tuple; using boost::tuples::get; using boost::tuples::make_tuple; using boost::bind; -using boost::mutex; using libtorrent::aux::session_impl; namespace diff --git a/src/torrent_handle.cpp b/src/torrent_handle.cpp index cbb28eec4..6fd246787 100644 --- a/src/torrent_handle.cpp +++ b/src/torrent_handle.cpp @@ -75,7 +75,6 @@ namespace std #endif using boost::bind; -using boost::mutex; using libtorrent::aux::session_impl; #ifdef BOOST_NO_EXCEPTIONS diff --git a/src/torrent_info.cpp b/src/torrent_info.cpp index cc13e42f4..82b16720b 100644 --- a/src/torrent_info.cpp +++ b/src/torrent_info.cpp @@ -164,20 +164,25 @@ namespace void trim_path_element(std::string& path_element) { +#ifdef FILENAME_MAX + const int max_path_len = FILENAME_MAX; +#else // on windows, NAME_MAX refers to Unicode characters // on linux it refers to bytes (utf-8 encoded) // TODO: Make this count Unicode characters instead of bytes on windows - if (path_element.size() > NAME_MAX) + const int max_path_len = NAME_MAX; +#endif + if (path_element.size() > max_path_len) { // truncate filenames that are too long. But keep extensions! std::string ext = fs::extension(path_element); if (ext.size() > 15) { - path_element.resize(NAME_MAX); + path_element.resize(max_path_len); } else { - path_element.resize(NAME_MAX - ext.size()); + path_element.resize(max_path_len - ext.size()); path_element += ext; } } @@ -446,7 +451,7 @@ namespace libtorrent // copy the info section m_info_section_size = section.second; m_info_section.reset(new char[m_info_section_size]); - memcpy(m_info_section.get(), section.first, m_info_section_size); + std::memcpy(m_info_section.get(), section.first, m_info_section_size); TORRENT_ASSERT(section.first[0] == 'd'); TORRENT_ASSERT(section.first[m_info_section_size-1] == 'e'); diff --git a/src/udp_tracker_connection.cpp b/src/udp_tracker_connection.cpp index 2458d1b2b..16f01ee13 100644 --- a/src/udp_tracker_connection.cpp +++ b/src/udp_tracker_connection.cpp @@ -321,7 +321,7 @@ namespace libtorrent char* ptr = buf; if (m_transaction_id == 0) - m_transaction_id = rand() ^ (rand() << 16); + m_transaction_id = std::rand() ^ (std::rand() << 16); detail::write_uint32(0x417, ptr); detail::write_uint32(0x27101980, ptr); // connection_id @@ -344,7 +344,7 @@ namespace libtorrent void udp_tracker_connection::send_udp_scrape() { if (m_transaction_id == 0) - m_transaction_id = rand() ^ (rand() << 16); + m_transaction_id = std::rand() ^ (std::rand() << 16); if (!m_socket.is_open()) return; // the operation was aborted @@ -482,7 +482,7 @@ namespace libtorrent void udp_tracker_connection::send_udp_announce() { if (m_transaction_id == 0) - m_transaction_id = rand() ^ (rand() << 16); + m_transaction_id = std::rand() ^ (std::rand() << 16); if (!m_socket.is_open()) return; // the operation was aborted diff --git a/src/upnp.cpp b/src/upnp.cpp index 147acff2b..5e1abdc39 100644 --- a/src/upnp.cpp +++ b/src/upnp.cpp @@ -956,7 +956,7 @@ namespace void find_error_code(int type, char const* string, error_code_parse_state& state) { if (state.exit) return; - if (type == xml_start_tag && !strcmp("errorCode", string)) + if (type == xml_start_tag && !std::strcmp("errorCode", string)) { state.in_error_code = true; } @@ -1088,7 +1088,7 @@ void upnp::on_upnp_map_response(error_code const& e { // The external port cannot be wildcarder // pick a random port - m.external_port = 40000 + (rand() % 10000); + m.external_port = 40000 + (std::rand() % 10000); m.action = mapping_t::action_add; ++m.failcount; update_map(d, mapping); diff --git a/src/web_peer_connection.cpp b/src/web_peer_connection.cpp index 42c728c7e..56e0eaf34 100644 --- a/src/web_peer_connection.cpp +++ b/src/web_peer_connection.cpp @@ -38,6 +38,7 @@ POSSIBILITY OF SUCH DAMAGE. #include #include #include +#include #include "libtorrent/web_peer_connection.hpp" #include "libtorrent/session.hpp" @@ -497,7 +498,7 @@ namespace libtorrent else { range_start = 0; - range_end = atol(m_parser.header("content-length").c_str()); + range_end = m_parser.content_length(); if (range_end == -1) { // we should not try this server again.