Fixes to build with MinGW-w64

This commit is contained in:
zed 2019-04-19 09:38:19 +03:00
parent 584bd5246b
commit 46c7fa777d
2 changed files with 14 additions and 8 deletions

View file

@ -31,7 +31,13 @@ STRIP=$(CCARCH)strip
CFLAGS=-fPIC -O3 -std=gnu99 -pedantic -Wall -Wextra -Wconversion -Werror -c -fmessage-length=0 -ffunction-sections -fdata-sections
LDFLAGS=-shared
EXECUTABLE=libzonedetect.so
ifeq ($(OS),Windows_NT)
EXT=dll
else
EXT=so
endif
EXECUTABLE=libzonedetect.$(EXT)
INCLUDES_SRC=zonedetect.h
SOURCES_SRC=zonedetect.c

View file

@ -31,7 +31,7 @@
#include <stdlib.h>
#include <string.h>
#include <math.h>
#if defined(_MSC_VER)
#if defined(_MSC_VER) || defined(__MINGW32__)
#include <windows.h>
#else
#include <errno.h>
@ -47,7 +47,7 @@ enum ZDInternalError {
ZD_E_DB_OPEN,
ZD_E_DB_SEEK,
ZD_E_DB_MMAP,
#if defined(_MSC_VER)
#if defined(_MSC_VER) || defined(__MINGW32__)
ZD_E_DB_MMAP_MSVIEW,
ZD_E_DB_MAP_EXCEPTION,
ZD_E_DB_MUNMAP_MSVIEW,
@ -58,7 +58,7 @@ enum ZDInternalError {
};
struct ZoneDetectOpaque {
#if defined(_MSC_VER)
#if defined(_MSC_VER) || defined(__MINGW32__)
HANDLE fd;
HANDLE fdMap;
int32_t length;
@ -255,7 +255,7 @@ static int ZDParseHeader(ZoneDetect *library)
library->dataOffset += index;
/* Verify file length */
if(tmp + library->dataOffset != library->length) {
if(tmp + library->dataOffset != (uint32_t)library->length) {
return -2;
}
@ -443,7 +443,7 @@ void ZDCloseDatabase(ZoneDetect *library)
free(library->notice);
}
#if defined(_MSC_VER)
#if defined(_MSC_VER) || defined(__MINGW32__)
if(!UnmapViewOfFile(library->mapping)) zdError(ZD_E_DB_MUNMAP_MSVIEW, (int)GetLastError());
if(!CloseHandle(library->fdMap)) zdError(ZD_E_DB_MUNMAP , (int)GetLastError());
if(!CloseHandle(library->fd)) zdError(ZD_E_DB_CLOSE , (int)GetLastError());
@ -463,7 +463,7 @@ ZoneDetect *ZDOpenDatabase(const char *path)
if(library) {
memset(library, 0, sizeof(*library));
#if defined(_MSC_VER)
#if defined(_MSC_VER) || defined(__MINGW32__)
library->fd = CreateFile(path, GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
if (library->fd == INVALID_HANDLE_VALUE) {
zdError(ZD_E_DB_OPEN, (int)GetLastError());
@ -718,7 +718,7 @@ const char *ZDGetErrorString(int errZD)
case ZD_E_DB_OPEN : return ZD_E_COULD_NOT("open database file");
case ZD_E_DB_SEEK : return ZD_E_COULD_NOT("retrieve database file size");
case ZD_E_DB_MMAP : return ZD_E_COULD_NOT("map database file to system memory");
#if defined(_MSC_VER)
#if defined(_MSC_VER) || defined(__MINGW32__)
case ZD_E_DB_MMAP_MSVIEW : return ZD_E_COULD_NOT("open database file view");
case ZD_E_DB_MAP_EXCEPTION: return "I/O exception occurred while accessing database file view";
case ZD_E_DB_MUNMAP_MSVIEW: return ZD_E_COULD_NOT("close database file view");