From d6f9cf64a4dd99d359c40331338704e75466bade Mon Sep 17 00:00:00 2001 From: Yamagi Burmeister Date: Tue, 20 Feb 2018 09:42:45 +0100 Subject: [PATCH] Enforce 32 bit IO-API for minizip on !Linux and !Windows. By default minizip uses fopen64(), fseek64() and so on. Those may not be defined on all system, especially the BSDs. While FreeBSD already has a special case, for example OpenBSD hasn't. Work around this by forcing minizip to use fopen(), fseek() and so on everything that's not Linux or Windows. This is not 100% correct, it may prevent the usage of ZIPs lager than 2GB on Solaris and other rarely used systems. But I doubt that anyone has such large ZIPs with assets, they would likely hit other internal limits. In the future Quake II should use off_t instead of int were applicable. With that we could set -D_FILE_OFFSET_BITS=64. This change is based upon a patch send by @devnexen in pr #279. --- CMakeLists.txt | 4 ++++ Makefile | 23 +++++++++++++++++++++-- 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 69563739..f4f2ef31 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -100,6 +100,10 @@ if(${ZIP_SUPPORT}) list(APPEND yquake2IncludeDirectories ${ZLIB_INCLUDE_DIRS}) list(APPEND yquake2ZLibLinkerFlags ${ZLIB_LIBRARIES}) add_definitions(-DZIP -DNOUNCRYPT) + + if(NOT CMAKE_SYSTEM_NAME MATCHES "Linux" OR NOT CMAKE_SYSTEM_NAME MATCHES "Windows") + add_definitions(-DIOAPI_NO_64) + endif() endif() if(${OGG_SUPPORT}) diff --git a/Makefile b/Makefile index 0bbfbb41..f89bc50c 100755 --- a/Makefile +++ b/Makefile @@ -222,6 +222,25 @@ endif # ---------- +# Just set IOAPI_NO_64 on everything that's not Linux or Windows, +# otherwise minizip will use fopen64(), fseek64() and friends that +# may be unavailable. This is - of course - not really correct, in +# a better world we would set -DIOAPI_NO_64 to force everything to +# fopen(), fseek() and so on and -D_FILE_OFFSET_BITS=64 to let the +# libc headers do their work. Currently we can't do that because +# Quake II uses nearly everywere int instead of off_t... +# +# This may have the side effect that ZIP files larger than 2GB are +# unsupported. But I doubt that anyone has such large files, they +# would likely hit other internal limits. +ifneq ($(YQ2_OSTYPE),Windows) +ifneq ($(YQ2_OSTYPE),Linux) +ZIPCFLAGS += -DIOAPI_NO_64 +endif +endif + +# ---------- + # Extra CFLAGS for SDL ifeq ($(WITH_SDL2),yes) SDLCFLAGS := $(shell sdl2-config --cflags) @@ -468,7 +487,7 @@ endif # !DLOPEN_OPENAL endif # WITH_OPENAL ifeq ($(WITH_ZIP),yes) -release/quake2 : CFLAGS += -DZIP -DNOUNCRYPT +release/quake2 : CFLAGS += $(ZIPCFLAGS) -DZIP -DNOUNCRYPT release/quake2 : LDFLAGS += -lz endif @@ -542,7 +561,7 @@ build/server/%.o: %.c release/q2ded : CFLAGS += -DDEDICATED_ONLY -Wno-unused-result ifeq ($(WITH_ZIP),yes) -release/q2ded : CFLAGS += -DZIP -DNOUNCRYPT +release/q2ded : CFLAGS += $(ZIPCFLAGS) -DZIP -DNOUNCRYPT release/q2ded : LDFLAGS += -lz endif endif