diff --git a/libtorrent/src/allocator.cpp b/libtorrent/src/allocator.cpp index 2161dc38..e98710f9 100644 --- a/libtorrent/src/allocator.cpp +++ b/libtorrent/src/allocator.cpp @@ -34,18 +34,27 @@ POSSIBILITY OF SUCH DAMAGE. #include "libtorrent/config.hpp" #include "libtorrent/assert.hpp" -#ifdef TORRENT_WINDOWS -#include -#elif defined TORRENT_BEOS +#if defined TORRENT_BEOS #include #include // malloc/free -#else +#elif !defined TORRENT_WINDOWS #include // valloc/free #include // _SC_PAGESIZE #endif #if TORRENT_USE_MEMALIGN || TORRENT_USE_POSIX_MEMALIGN #include // memalign +#include // _aligned_malloc on mingw +#endif + +#ifdef TORRENT_WINDOWS +// windows.h must be included after stdlib.h under mingw +#include +#endif + +#ifdef TORRENT_MINGW +#define _aligned_malloc __mingw_aligned_malloc +#define _aligned_free __mingw_aligned_free #endif #ifdef TORRENT_DEBUG_BUFFERS diff --git a/libtorrent/src/file.cpp b/libtorrent/src/file.cpp index 63545bd4..acd7704f 100644 --- a/libtorrent/src/file.cpp +++ b/libtorrent/src/file.cpp @@ -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 { } } - 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;