minor cleanup (#997)

minor cleanup
This commit is contained in:
Alden Torres 2016-08-12 19:24:03 -04:00 committed by Arvid Norberg
parent 74c8054e8d
commit a966458f8c
5 changed files with 33 additions and 46 deletions

View File

@ -304,7 +304,7 @@ namespace libtorrent
// a list of hostname and port pairs, representing DHT nodes to be added
// to the session (if DHT is enabled). The hostname may be an IP address.
std::vector<std::pair<std::string, int> > dht_nodes;
std::vector<std::pair<std::string, int>> dht_nodes;
std::string name;
// the path where the torrent is or will be stored.
@ -343,7 +343,7 @@ namespace libtorrent
// to avoid race conditions. For instance it may be important to have the
// plugin catch events that happen very early on after the torrent is
// created.
std::vector<boost::function<boost::shared_ptr<torrent_plugin>(torrent_handle const&, void*)> >
std::vector<boost::function<boost::shared_ptr<torrent_plugin>(torrent_handle const&, void*)>>
extensions;
// the default tracker id to be used when announcing to trackers. By

View File

@ -98,7 +98,7 @@ namespace libtorrent
char buf[MAX_SYMLINK_PATH];
std::string f = convert_to_native(path);
int char_read = readlink(f.c_str(),buf,MAX_SYMLINK_PATH);
int char_read = readlink(f.c_str(), buf, MAX_SYMLINK_PATH);
if (char_read < 0) return "";
if (char_read < MAX_SYMLINK_PATH) buf[char_read] = 0;
else buf[0] = 0;
@ -112,7 +112,6 @@ namespace libtorrent
TORRENT_UNUSED(p);
return "";
#else
std::string path = convert_to_native(p);
return get_symlink_path_impl(p.c_str());
#endif
}

View File

@ -62,12 +62,9 @@ POSSIBILITY OF SUCH DAMAGE.
#include "libtorrent/config.hpp"
#include "libtorrent/alloca.hpp"
#include "libtorrent/allocator.hpp" // page_size
#include "libtorrent/file.hpp"
#include "libtorrent/error_code.hpp"
#include "libtorrent/aux_/max_path.hpp" // for TORRENT_MAX_PATH
#include <cstring>
#include <vector>
#ifdef TORRENT_DEBUG_FILE_LEAKS
#include <set>
@ -78,8 +75,6 @@ POSSIBILITY OF SUCH DAMAGE.
#include "libtorrent/aux_/escape_string.hpp"
#include "libtorrent/assert.hpp"
#include <boost/scoped_ptr.hpp>
#ifdef TORRENT_DISK_STATS
#include "libtorrent/io.hpp"
#endif
@ -167,7 +162,7 @@ namespace
int preadv(HANDLE fd, libtorrent::file::iovec_t const* bufs, int num_bufs, std::int64_t file_offset)
{
OVERLAPPED* ol = TORRENT_ALLOCA(OVERLAPPED, num_bufs);
memset(ol, 0, sizeof(OVERLAPPED) * num_bufs);
std::memset(ol, 0, sizeof(OVERLAPPED) * num_bufs);
HANDLE* h = TORRENT_ALLOCA(HANDLE, num_bufs);
@ -237,7 +232,7 @@ done:
int pwritev(HANDLE fd, libtorrent::file::iovec_t const* bufs, int num_bufs, std::int64_t file_offset)
{
OVERLAPPED* ol = TORRENT_ALLOCA(OVERLAPPED, num_bufs);
memset(ol, 0, sizeof(OVERLAPPED) * num_bufs);
std::memset(ol, 0, sizeof(OVERLAPPED) * num_bufs);
HANDLE* h = TORRENT_ALLOCA(HANDLE, num_bufs);
@ -498,7 +493,7 @@ namespace libtorrent
ec.assign(GetLastError(), system_category());
#else
std::string n = convert_to_native(f);
int ret = mkdir(n.c_str(), 0777);
int ret = ::mkdir(n.c_str(), 0777);
if (ret < 0 && errno != EEXIST)
ec.assign(errno, system_category());
#endif
@ -763,11 +758,11 @@ namespace libtorrent
std::string remove_extension(std::string const& f)
{
char const* slash = strrchr(f.c_str(), '/');
char const* slash = std::strrchr(f.c_str(), '/');
#ifdef TORRENT_WINDOWS
slash = (std::max)((char const*)strrchr(f.c_str(), '\\'), slash);
slash = (std::max)((char const*)std::strrchr(f.c_str(), '\\'), slash);
#endif
char const* ext = strrchr(f.c_str(), '.');
char const* ext = std::strrchr(f.c_str(), '.');
// if we don't have an extension, just return f
if (ext == nullptr || ext == &f[0] || (slash != nullptr && ext < slash)) return f;
return f.substr(0, ext - &f[0]);
@ -871,9 +866,9 @@ namespace libtorrent
{
if (f == nullptr) return f;
char const* sep = strrchr(f, '/');
char const* sep = std::strrchr(f, '/');
#ifdef TORRENT_WINDOWS
char const* altsep = strrchr(f, '\\');
char const* altsep = std::strrchr(f, '\\');
if (sep == 0 || altsep > sep) sep = altsep;
#endif
if (sep == nullptr) return f;
@ -884,9 +879,9 @@ namespace libtorrent
{
if (f.empty()) return "";
char const* first = f.c_str();
char const* sep = strrchr(first, '/');
char const* sep = std::strrchr(first, '/');
#if defined(TORRENT_WINDOWS) || defined(TORRENT_OS2)
char const* altsep = strrchr(first, '\\');
char const* altsep = std::strrchr(first, '\\');
if (sep == 0 || altsep > sep) sep = altsep;
#endif
if (sep == nullptr) return f;
@ -1007,14 +1002,14 @@ namespace libtorrent
continue;
}
int element_len = read_cur - last_read_sep;
if (element_len == 1 && memcmp(last_read_sep, ".", 1) == 0)
if (element_len == 1 && std::memcmp(last_read_sep, ".", 1) == 0)
{
--write_cur;
++read_cur;
last_read_sep = read_cur;
continue;
}
if (element_len == 2 && memcmp(last_read_sep, "..", 2) == 0)
if (element_len == 2 && std::memcmp(last_read_sep, "..", 2) == 0)
{
// find the previous path separator
if (last_write_sep > &ret[0])
@ -1194,7 +1189,7 @@ namespace libtorrent
}
#else
memset(&m_dirent, 0, sizeof(dirent));
std::memset(&m_dirent, 0, sizeof(dirent));
m_name[0] = 0;
// the path passed to opendir() may not
@ -1204,7 +1199,7 @@ namespace libtorrent
p.resize(path.size()-1);
p = convert_to_native(p);
m_handle = opendir(p.c_str());
m_handle = ::opendir(p.c_str());
if (m_handle == nullptr)
{
ec.assign(errno, system_category());
@ -1285,7 +1280,7 @@ namespace libtorrent
{
overlapped_t()
{
memset(&ol, 0, sizeof(ol));
std::memset(&ol, 0, sizeof(ol));
ol.hEvent = CreateEvent(0, true, false, 0);
}
~overlapped_t()
@ -1678,7 +1673,7 @@ typedef struct _FILE_ALLOCATED_RANGE_BUFFER {
std::size_t offset = 0;
for (int i = 0; i < num_bufs; ++i)
{
memcpy(dst + offset, bufs[i].iov_base, bufs[i].iov_len);
std::memcpy(dst + offset, bufs[i].iov_base, bufs[i].iov_len);
offset += bufs[i].iov_len;
}
}
@ -1688,7 +1683,7 @@ typedef struct _FILE_ALLOCATED_RANGE_BUFFER {
std::size_t offset = 0;
for (int i = 0; i < num_bufs; ++i)
{
memcpy(bufs[i].iov_base, src + offset, bufs[i].iov_len);
std::memcpy(bufs[i].iov_base, src + offset, bufs[i].iov_len);
offset += bufs[i].iov_len;
}
}
@ -1697,7 +1692,7 @@ typedef struct _FILE_ALLOCATED_RANGE_BUFFER {
, file::iovec_t* tmp)
{
int const buf_size = bufs_size(bufs, num_bufs);
char* buf = static_cast<char*>(malloc(buf_size));
char* buf = static_cast<char*>(std::malloc(buf_size));
if (!buf) return false;
tmp->iov_base = buf;
tmp->iov_len = buf_size;
@ -1710,14 +1705,14 @@ typedef struct _FILE_ALLOCATED_RANGE_BUFFER {
, char* const buf, bool const copy)
{
if (copy) scatter_copy(bufs, num_bufs, buf);
free(buf);
std::free(buf);
}
bool coalesce_write_buffers(file::iovec_t const*& bufs, int& num_bufs
, file::iovec_t* tmp)
{
int const buf_size = bufs_size(bufs, num_bufs);
char* buf = static_cast<char*>(malloc(buf_size));
char* buf = static_cast<char*>(std::malloc(buf_size));
if (!buf) return false;
gather_copy(bufs, num_bufs, buf);
tmp->iov_base = buf;
@ -1940,7 +1935,7 @@ typedef struct _FILE_ALLOCATED_RANGE_BUFFER {
#endif
if (flags & file::coalesce_buffers)
free(tmp.iov_base);
std::free(tmp.iov_base);
#endif
#if TORRENT_USE_FDATASYNC \
@ -2360,4 +2355,3 @@ typedef struct _FILE_ALLOCATED_RANGE_BUFFER {
}
#endif
}

View File

@ -301,7 +301,7 @@ namespace aux {
return SSL_TLSEXT_ERR_OK;
}
} // anonymous namesoace
} // anonymous namespace
#endif
session_impl::session_impl(io_service& ios)
@ -4630,7 +4630,7 @@ namespace aux {
{
boost::shared_ptr<torrent_plugin> tp(e->new_torrent(
torrent_ptr->get_handle(), userdata));
if (tp) torrent_ptr->add_extension(tp);
if (tp) torrent_ptr->add_extension(std::move(tp));
}
}
#endif
@ -4675,14 +4675,10 @@ namespace aux {
torrent_ptr->start(params);
#ifndef TORRENT_DISABLE_EXTENSIONS
typedef std::vector<boost::function<
boost::shared_ptr<torrent_plugin>(torrent_handle const&, void*)> >
torrent_plugins_t;
for (torrent_plugins_t::const_iterator i = params.extensions.begin()
, end(params.extensions.end()); i != end; ++i)
for (auto& ext : params.extensions)
{
torrent_ptr->add_extension((*i)(handle, params.userdata));
boost::shared_ptr<torrent_plugin> tp(ext(handle, params.userdata));
if (tp) torrent_ptr->add_extension(std::move(tp));
}
add_extensions_to_torrent(torrent_ptr, params.userdata);

View File

@ -1429,7 +1429,7 @@ namespace libtorrent
{
int block_offset = p.block_index * block_size();
int block = (std::min)(torrent_file().piece_size(
p.piece_index) - block_offset, int(block_size()));
p.piece_index) - block_offset, block_size());
TORRENT_ASSERT(block > 0);
TORRENT_ASSERT(block <= block_size());
@ -1467,14 +1467,12 @@ namespace libtorrent
boost::shared_ptr<torrent_plugin> tp(ext(get_handle(), userdata));
if (!tp) return;
add_extension(tp);
add_extension(std::move(tp));
for (peer_iterator i = m_connections.begin();
i != m_connections.end(); ++i)
for (auto p : m_connections)
{
peer_connection* p = *i;
boost::shared_ptr<peer_plugin> pp(tp->new_connection(peer_connection_handle(p->self())));
if (pp) p->add_extension(pp);
if (pp) p->add_extension(std::move(pp));
}
// if files are checked for this torrent, call the extension