Browse Source

merge upstream patch r8983 (merged mingw build fixes from RC_0_16)

miguelfreitas
Miguel Freitas 11 years ago
parent
commit
92ea5ff97a
  1. 17
      libtorrent/src/allocator.cpp
  2. 22
      libtorrent/src/file.cpp

17
libtorrent/src/allocator.cpp

@ -34,18 +34,27 @@ POSSIBILITY OF SUCH DAMAGE. @@ -34,18 +34,27 @@ POSSIBILITY OF SUCH DAMAGE.
#include "libtorrent/config.hpp"
#include "libtorrent/assert.hpp"
#ifdef TORRENT_WINDOWS
#include <windows.h>
#elif defined TORRENT_BEOS
#if defined TORRENT_BEOS
#include <kernel/OS.h>
#include <stdlib.h> // malloc/free
#else
#elif !defined TORRENT_WINDOWS
#include <stdlib.h> // valloc/free
#include <unistd.h> // _SC_PAGESIZE
#endif
#if TORRENT_USE_MEMALIGN || TORRENT_USE_POSIX_MEMALIGN
#include <malloc.h> // memalign
#include <stdlib.h> // _aligned_malloc on mingw
#endif
#ifdef TORRENT_WINDOWS
// windows.h must be included after stdlib.h under mingw
#include <windows.h>
#endif
#ifdef TORRENT_MINGW
#define _aligned_malloc __mingw_aligned_malloc
#define _aligned_free __mingw_aligned_free
#endif
#ifdef TORRENT_DEBUG_BUFFERS

22
libtorrent/src/file.cpp

@ -1986,22 +1986,30 @@ typedef struct _FILE_ALLOCATED_RANGE_BUFFER { @@ -1986,22 +1986,30 @@ typedef struct _FILE_ALLOCATED_RANGE_BUFFER {
if ((m_open_mode & sparse) == 0)
{
typedef DWORD (WINAPI *GetCompressedFileSizeW_t)(LPCWSTR lpFileName, LPDWORD lpFileSizeHigh);
#if TORRENT_USE_WSTRING
typedef DWORD (WINAPI *GetCompressedFileSize_t)(LPCWSTR lpFileName, LPDWORD lpFileSizeHigh);
#else
typedef DWORD (WINAPI *GetCompressedFileSize_t)(LPCSTR lpFileName, LPDWORD lpFileSizeHigh);
#endif
typedef BOOL (WINAPI *SetFileValidData_t)(HANDLE hFile, LONGLONG ValidDataLength);
static GetCompressedFileSizeW_t GetCompressedFileSizeW = NULL;
static GetCompressedFileSize_t GetCompressedFileSize_ = NULL;
static SetFileValidData_t SetFileValidData = NULL;
static bool failed_kernel32 = false;
if ((GetCompressedFileSizeW == NULL) && !failed_kernel32)
if ((GetCompressedFileSize_ == NULL) && !failed_kernel32)
{
HMODULE kernel32 = LoadLibraryA("kernel32.dll");
if (kernel32)
{
GetCompressedFileSizeW = (GetCompressedFileSizeW_t)GetProcAddress(kernel32, "GetCompressedFileSizeW");
#if TORRENT_USE_WSTRING
GetCompressedFileSize_ = (GetCompressedFileSize_t)GetProcAddress(kernel32, "GetCompressedFileSizeW");
#else
GetCompressedFileSize_ = (GetCompressedFileSize_t)GetProcAddress(kernel32, "GetCompressedFileSizeA");
#endif
SetFileValidData = (SetFileValidData_t)GetProcAddress(kernel32, "SetFileValidData");
if ((GetCompressedFileSizeW == NULL) || (SetFileValidData == NULL))
if ((GetCompressedFileSize_ == NULL) || (SetFileValidData == NULL))
{
failed_kernel32 = true;
}
@ -2012,12 +2020,12 @@ typedef struct _FILE_ALLOCATED_RANGE_BUFFER { @@ -2012,12 +2020,12 @@ typedef struct _FILE_ALLOCATED_RANGE_BUFFER {
}
}
if (!failed_kernel32 && GetCompressedFileSizeW && SetFileValidData)
if (!failed_kernel32 && GetCompressedFileSize_ && SetFileValidData)
{
// only allocate the space if the file
// is not fully allocated
DWORD high_dword = 0;
offs.LowPart = GetCompressedFileSize(m_path.c_str(), &high_dword);
offs.LowPart = GetCompressedFileSize_(m_path.c_str(), &high_dword);
offs.HighPart = high_dword;
ec.assign(GetLastError(), get_system_category());
if (ec) return false;

Loading…
Cancel
Save