From 748cbac1c0b22a9eb6334dd4e1cf772a236d3425 Mon Sep 17 00:00:00 2001 From: "Ryan C. Gordon" Date: Fri, 12 Apr 2002 05:53:12 +0000 Subject: [PATCH] Patches for correctness and cleaner win32 support. --- Makefile | 12 ++++++------ archivers/grp.c | 6 ++++-- archivers/zip.c | 2 +- physfs.h | 15 ++++----------- physfs_byteorder.c | 12 ++++++++---- platform/win32.c | 7 ++++--- 6 files changed, 27 insertions(+), 27 deletions(-) diff --git a/Makefile b/Makefile index e814eeea..703f7b0f 100644 --- a/Makefile +++ b/Makefile @@ -175,9 +175,9 @@ ifeq ($(strip $(use_archive_zip)),true) CFLAGS += -DPHYSFS_SUPPORTS_ZIP LDFLAGS += -lz ifeq ($(strip $(cygwin)),true) - EXTRABUILD += zlibwin32/zlib.a - CFLAGS += -Izlibwin32 - LDFLAGS += -Lzlibwin32 + EXTRABUILD += zlib114/zlib114.a + CFLAGS += -Izlib114 + LDFLAGS += -Lzlib114 endif endif @@ -264,8 +264,8 @@ $(BINDIR): ifeq ($(strip $(cygwin)),true) -zlibwin32/zlib.a: - cd zlibwin32 ; $(MAKE) CC=$(CC) +zlib114/zlib114.a: + cd zlib114 ; $(MAKE) CC=$(CC) endif @@ -275,7 +275,7 @@ clean: rm -f $(CLEANUP) rm -rf $(BINDIR) ifeq ($(strip $(cygwin)),true) - cd zlibwin32 ; $(MAKE) clean + cd zlib114 ; $(MAKE) clean endif listobjs: diff --git a/archivers/grp.c b/archivers/grp.c index 68679589..bec1d10b 100644 --- a/archivers/grp.c +++ b/archivers/grp.c @@ -133,7 +133,7 @@ static PHYSFS_sint64 GRP_read(FileHandle *handle, void *buffer, PHYSFS_uint64 objsLeft = (bytesLeft / objSize); if (objsLeft < objCount) - objCount = objsLeft; + objCount = (PHYSFS_uint32) objsLeft; return(__PHYSFS_platformRead(fh, buffer, objSize, objCount)); } /* GRP_read */ @@ -143,7 +143,9 @@ static int GRP_eof(FileHandle *handle) { GRPfileinfo *finfo = (GRPfileinfo *) (handle->opaque); void *fh = finfo->handle; - return(__PHYSFS_platformTell(fh) >= finfo->startPos + finfo->size); + PHYSFS_sint64 pos = __PHYSFS_platformTell(fh); + BAIL_IF_MACRO(pos < 0, NULL, 1); /* (*shrug*) */ + return(pos >= (PHYSFS_sint64) (finfo->startPos + finfo->size)); } /* GRP_eof */ diff --git a/archivers/zip.c b/archivers/zip.c index 24cf9aec..d42020f3 100644 --- a/archivers/zip.c +++ b/archivers/zip.c @@ -153,7 +153,7 @@ static int ZIP_seek(FileHandle *handle, PHYSFS_uint64 offset) PHYSFS_uint32 bufsize = 4096 * 2; BAIL_IF_MACRO(unztell(fh) == offset, NULL, 1); - BAIL_IF_MACRO(ZIP_fileLength(handle) <= offset, ERR_PAST_EOF, 0); + BAIL_IF_MACRO(ZIP_fileLength(handle) <= (PHYSFS_sint64) offset, ERR_PAST_EOF, 0); /* reset to the start of the zipfile. */ unzCloseCurrentFile(fh); diff --git a/physfs.h b/physfs.h index a81340c1..7b94dfc3 100644 --- a/physfs.h +++ b/physfs.h @@ -129,10 +129,6 @@ #ifndef _INCLUDE_PHYSFS_H_ #define _INCLUDE_PHYSFS_H_ -#ifdef _WIN32 -#include -#endif - #ifdef __cplusplus extern "C" { #endif @@ -143,8 +139,6 @@ extern "C" { #define __EXPORT__ #endif - -/* !!! FIXME: This is not universal. */ typedef unsigned char PHYSFS_uint8; typedef signed char PHYSFS_sint8; typedef unsigned short PHYSFS_uint16; @@ -152,13 +146,12 @@ typedef signed short PHYSFS_sint16; typedef unsigned int PHYSFS_uint32; typedef signed int PHYSFS_sint32; -#ifdef PHYSFS_NO_64BIT_SUPPORT /* oh well. */ +#if (defined PHYSFS_NO_64BIT_SUPPORT) /* oh well. */ typedef PHYSFS_uint32 PHYSFS_uint64; typedef PHYSFS_sint32 PHYSFS_sint64; -#elif _WIN32 -/*!!! No 64-bit unsigned in Win32???? */ -typedef LONGLONG PHYSFS_sint64; -typedef LONGLONG PHYSFS_uint64; +#elif (defined _MSC_VER) +typedef signed __int64 PHYSFS_sint64; +typedef unsigned __int64 PHYSFS_uint64; #else typedef unsigned long long PHYSFS_uint64; typedef signed long long PHYSFS_sint64; diff --git a/physfs_byteorder.c b/physfs_byteorder.c index 46359456..45ba55c5 100644 --- a/physfs_byteorder.c +++ b/physfs_byteorder.c @@ -40,22 +40,26 @@ #define PHYSFS_Swap32 __arch__swab32 #endif #endif /* linux */ - + +#if (defined _MSC_VER) +#define inline __inline +#endif + #ifndef PHYSFS_Swap16 -static __inline__ PHYSFS_uint16 PHYSFS_Swap16(PHYSFS_uint16 D) +static inline PHYSFS_uint16 PHYSFS_Swap16(PHYSFS_uint16 D) { return((D<<8)|(D>>8)); } #endif #ifndef PHYSFS_Swap32 -static __inline__ PHYSFS_uint32 PHYSFS_Swap32(PHYSFS_uint32 D) +static inline PHYSFS_uint32 PHYSFS_Swap32(PHYSFS_uint32 D) { return((D<<24)|((D<<8)&0x00FF0000)|((D>>8)&0x0000FF00)|(D>>24)); } #endif #ifndef PHYSFS_NO_64BIT_SUPPORT #ifndef PHYSFS_Swap64 -static __inline__ PHYSFS_uint64 PHYSFS_Swap64(PHYSFS_uint64 val) { +static inline PHYSFS_uint64 PHYSFS_Swap64(PHYSFS_uint64 val) { PHYSFS_uint32 hi, lo; /* Separate into high and low 32-bit values and swap them */ diff --git a/platform/win32.c b/platform/win32.c index 16568370..da308edb 100644 --- a/platform/win32.c +++ b/platform/win32.c @@ -184,6 +184,9 @@ PHYSFS_uint64 __PHYSFS_platformGetThreadID(void) /* ...make this Cygwin AND Visual C friendly... */ int __PHYSFS_platformStricmp(const char *x, const char *y) { +#if (defined _MSC_VER) + return(stricmp(x, y)); +#else int ux, uy; do @@ -199,6 +202,7 @@ int __PHYSFS_platformStricmp(const char *x, const char *y) } while ((ux) && (uy)); return(0); +#endif } /* __PHYSFS_platformStricmp */ @@ -469,9 +473,6 @@ static int doNTInit() /*!!! Second parameter can't be NULL or the function fails??? */ if(!GetUserProfileDirectory(AccessTokenHandle, TempProfileDirectory, &pathsize)) { - const char *temp; - temp = win32strerror(); - /* Allocate memory for the profile directory */ ProfileDirectory = (char *)malloc(pathsize); BAIL_IF_MACRO(ProfileDirectory == NULL, ERR_OUT_OF_MEMORY, 0);