diff --git a/src/file.cpp b/src/file.cpp index 952227af4..e5fe9e004 100644 --- a/src/file.cpp +++ b/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); diff --git a/test/main.cpp b/test/main.cpp index d0b0734bf..be329c5aa 100644 --- a/test/main.cpp +++ b/test/main.cpp @@ -34,6 +34,7 @@ POSSIBILITY OF SUCH DAMAGE. #include #include #include +#include // for exit() int test_main(); diff --git a/test/setup_transfer.cpp b/test/setup_transfer.cpp index e7abaf27e..4d8f50969 100644 --- a/test/setup_transfer.cpp +++ b/test/setup_transfer.cpp @@ -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; } diff --git a/test/test_checking.cpp b/test/test_checking.cpp index f9044b44e..161f81b86 100644 --- a/test/test_checking.cpp +++ b/test/test_checking.cpp @@ -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