diff --git a/ChangeLog b/ChangeLog index f965c6d70..d94d95eb6 100644 --- a/ChangeLog +++ b/ChangeLog @@ -24,6 +24,7 @@ * fix uTP edge case where udp socket buffer fills up * fix nagle implementation in uTP + * fix mingw build issues * increase max allowed outstanding piece requests from peers * uTP performance improvement. only fast retransmit one packet at a time * improve error message for 'file too short' diff --git a/src/allocator.cpp b/src/allocator.cpp index 8268250b8..eabed79d7 100644 --- a/src/allocator.cpp +++ b/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 || defined TORRENT_WINDOWS #include // memalign and _aligned_malloc +#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/src/file.cpp b/src/file.cpp index 2b700a112..953e84352 100644 --- a/src/file.cpp +++ b/src/file.cpp @@ -1978,22 +1978,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; } @@ -2004,12 +2012,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;