Skip to content

Commit

Permalink
Patches for correctness and cleaner win32 support.
Browse files Browse the repository at this point in the history
  • Loading branch information
icculus committed Apr 12, 2002
1 parent 7ffd15f commit 748cbac
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 27 deletions.
12 changes: 6 additions & 6 deletions Makefile
Expand Up @@ -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

Expand Down Expand Up @@ -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


Expand All @@ -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:
Expand Down
6 changes: 4 additions & 2 deletions archivers/grp.c
Expand Up @@ -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 */
Expand All @@ -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 */


Expand Down
2 changes: 1 addition & 1 deletion archivers/zip.c
Expand Up @@ -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);
Expand Down
15 changes: 4 additions & 11 deletions physfs.h
Expand Up @@ -129,10 +129,6 @@
#ifndef _INCLUDE_PHYSFS_H_
#define _INCLUDE_PHYSFS_H_

#ifdef _WIN32
#include <windows.h>
#endif

#ifdef __cplusplus
extern "C" {
#endif
Expand All @@ -143,22 +139,19 @@ 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;
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;
Expand Down
12 changes: 8 additions & 4 deletions physfs_byteorder.c
Expand Up @@ -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 */
Expand Down
7 changes: 4 additions & 3 deletions platform/win32.c
Expand Up @@ -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
Expand All @@ -199,6 +202,7 @@ int __PHYSFS_platformStricmp(const char *x, const char *y)
} while ((ux) && (uy));

return(0);
#endif
} /* __PHYSFS_platformStricmp */


Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 748cbac

Please sign in to comment.