forked from premiere/premiere-libtorrent
merged some windows fixes from RC_0_16
This commit is contained in:
parent
38d7e58177
commit
d8c2228ff3
26
src/file.cpp
26
src/file.cpp
|
@ -1209,6 +1209,19 @@ namespace libtorrent
|
|||
|
||||
size_type file::readv(size_type file_offset, iovec_t const* bufs, int num_bufs, error_code& ec)
|
||||
{
|
||||
#ifdef TORRENT_WINDOWS
|
||||
if (m_file_handle == INVALID_HANDLE_VALUE)
|
||||
{
|
||||
ec = error_code(ERROR_INVALID_HANDLE, get_system_category());
|
||||
return -1;
|
||||
}
|
||||
#else
|
||||
if (m_file_handle == -1)
|
||||
{
|
||||
ec = error_code(EBADF, get_system_category());
|
||||
return -1;
|
||||
}
|
||||
#endif
|
||||
TORRENT_ASSERT((m_open_mode & rw_mask) == read_only || (m_open_mode & rw_mask) == read_write);
|
||||
TORRENT_ASSERT(bufs);
|
||||
TORRENT_ASSERT(num_bufs > 0);
|
||||
|
@ -1420,6 +1433,19 @@ namespace libtorrent
|
|||
|
||||
size_type file::writev(size_type file_offset, iovec_t const* bufs, int num_bufs, error_code& ec)
|
||||
{
|
||||
#ifdef TORRENT_WINDOWS
|
||||
if (m_file_handle == INVALID_HANDLE_VALUE)
|
||||
{
|
||||
ec = error_code(ERROR_INVALID_HANDLE, get_system_category());
|
||||
return -1;
|
||||
}
|
||||
#else
|
||||
if (m_file_handle == -1)
|
||||
{
|
||||
ec = error_code(EBADF, get_system_category());
|
||||
return -1;
|
||||
}
|
||||
#endif
|
||||
TORRENT_ASSERT((m_open_mode & rw_mask) == write_only || (m_open_mode & rw_mask) == read_write);
|
||||
TORRENT_ASSERT(bufs);
|
||||
TORRENT_ASSERT(num_bufs > 0);
|
||||
|
|
|
@ -34,6 +34,7 @@ POSSIBILITY OF SUCH DAMAGE.
|
|||
#include <boost/config.hpp>
|
||||
#include <fcntl.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h> // for exit()
|
||||
|
||||
int test_main();
|
||||
|
||||
|
|
|
@ -232,12 +232,16 @@ void create_random_files(std::string const& path, const int file_sizes[], int nu
|
|||
snprintf(filename, sizeof(filename), "%s/test%d", path.c_str(), i);
|
||||
int to_write = file_sizes[i];
|
||||
file f(filename, file::write_only, ec);
|
||||
if (ec) fprintf(stderr, "failed to create file \"%s\": (%d) %s\n"
|
||||
, filename, ec.value(), ec.message().c_str());
|
||||
size_type offset = 0;
|
||||
while (to_write > 0)
|
||||
{
|
||||
int s = (std::min)(to_write, 300000);
|
||||
file::iovec_t b = { random_data, s};
|
||||
f.writev(offset, &b, 1, ec);
|
||||
if (ec) fprintf(stderr, "failed to write file \"%s\": (%d) %s\n"
|
||||
, filename, ec.value(), ec.message().c_str());
|
||||
offset += s;
|
||||
to_write -= s;
|
||||
}
|
||||
|
|
|
@ -101,7 +101,7 @@ void test_checking(bool read_only_files, bool corrupt_files = false)
|
|||
char path[1024];
|
||||
snprintf(path, sizeof(path), "tmp1_checking/test_torrent_dir/test%d", i);
|
||||
#ifdef TORRENT_WINDOWS
|
||||
SetFileAttributes(path, FILE_ATTRIBUTE_READONLY);
|
||||
SetFileAttributesA(path, FILE_ATTRIBUTE_READONLY);
|
||||
#else
|
||||
chmod(path, S_IRUSR);
|
||||
#endif
|
||||
|
|
Loading…
Reference in New Issue