From f0c09894c851b80cadeb4c7881f889c8a461a801 Mon Sep 17 00:00:00 2001 From: "Ryan C. Gordon" Date: Thu, 23 Aug 2001 15:23:21 +0000 Subject: [PATCH] Updates, corrections and enhancements to get this ported to win32. --- CHANGELOG | 7 +++++++ Makefile | 9 ++++++++- archivers/dir.c | 8 ++++---- archivers/grp.c | 10 ++++++---- archivers/zip.c | 1 - physfs.h | 2 +- physfs_internal.h | 11 ++++++++++- platform/unix.c | 9 +++++++++ 8 files changed, 45 insertions(+), 12 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 5a5fcccc..14f653c4 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -6,6 +6,13 @@ 08012001 - Added a safety memset in error setting, fixed URLs and email addr. 08062001 - Added CD-ROM detection code to the unix platform driver. 08072001 - Changed version to 0.1.1. +08232001 - Fixed a potential free()ing of a NULL pointer in + __PHYSFS_platformEnumerateFiles() in platform/unix.c. Added + platform/win32.c. Other cleanups to get this compiling with + Visual C and CygWin. Added BAIL_MACRO for times when we were doing + BAIL_IF_MACRO(1, ...). Abstracted mkdir() in the platform drivers. + Added GRP setting output to showcfg in the Makefile. Changed + version to 0.1.2. --ryan. (icculus@clutteredmind.org) diff --git a/Makefile b/Makefile index b7eb3233..38bdab5c 100644 --- a/Makefile +++ b/Makefile @@ -165,7 +165,7 @@ MAINLIB := $(BINDIR)/$(strip $(BASELIBNAME))$(strip $(LIB_EXT)) TESTSRCS := test/test_physfs.c -MAINSRCS := physfs.c platform/unix.c archivers/dir.c +MAINSRCS := physfs.c archivers/dir.c ifeq ($(strip $(use_archive_zip)),true) MAINSRCS += archivers/zip.c archivers/unzip.c @@ -178,6 +178,12 @@ MAINSRCS += archivers/grp.c CFLAGS += -DPHYSFS_SUPPORTS_GRP endif +ifeq ($(strip $(cygwin)),true) +MAINSRCS += platform/win32.c +else +MAINSRCS += platform/unix.c +endif + TESTEXE := $(BINDIR)/test_physfs$(EXE_EXT) # Rule for getting list of objects from source @@ -269,6 +275,7 @@ showcfg: @echo "Building DLLs : $(build_dll)" @echo "Install prefix : $(install_prefix)" @echo "PhysFS version : $(VERFULL)" + @echo "Supports .GRP : $(use_archive_grp)" @echo "Supports .ZIP : $(use_archive_zip)" #-----------------------------------------------------------------------------# diff --git a/archivers/dir.c b/archivers/dir.c index 06e4117f..d51fde12 100644 --- a/archivers/dir.c +++ b/archivers/dir.c @@ -13,7 +13,6 @@ #include #include #include -#include #include "physfs.h" #define __PHYSICSFS_INTERNAL__ @@ -31,7 +30,8 @@ static int DIR_read(FileHandle *handle, void *buffer, errno = 0; retval = fread(buffer, objSize, objCount, h); - BAIL_IF_MACRO((retval < objCount) && (ferror(h)),strerror(errno),retval); + BAIL_IF_MACRO((retval < (signed int) objCount) && (ferror(h)), + strerror(errno),retval); return(retval); } /* DIR_read */ @@ -45,7 +45,7 @@ static int DIR_write(FileHandle *handle, void *buffer, errno = 0; retval = fwrite(buffer, objSize, objCount, h); - if ( (retval < objCount) && (ferror(h)) ) + if ( (retval < (signed int) objCount) && (ferror(h)) ) __PHYSFS_setError(strerror(errno)); return(retval); @@ -267,7 +267,7 @@ static int DIR_mkdir(DirHandle *h, const char *name) BAIL_IF_MACRO(f == NULL, NULL, 0); errno = 0; - retval = (mkdir(f, S_IRWXU) == 0); + retval = __PHYSFS_platformMkDir(f); if (!retval) __PHYSFS_setError(strerror(errno)); diff --git a/archivers/grp.c b/archivers/grp.c index 3054d38a..8a507a54 100644 --- a/archivers/grp.c +++ b/archivers/grp.c @@ -35,7 +35,6 @@ #include #include #include -#include #include #include "physfs.h" @@ -71,7 +70,7 @@ static int GRP_read(FileHandle *handle, void *buffer, GRPfileinfo *finfo = (GRPfileinfo *) (handle->opaque); FILE *fh = (FILE *) (((GRPinfo *) (handle->dirHandle->opaque))->handle); int bytesLeft = (finfo->startPos + finfo->size) - finfo->curPos; - int objsLeft = bytesLeft / objSize; + unsigned int objsLeft = bytesLeft / objSize; int retval = 0; if (objsLeft < objCount) @@ -83,7 +82,8 @@ static int GRP_read(FileHandle *handle, void *buffer, errno = 0; retval = fread(buffer, objSize, objCount, fh); finfo->curPos += (retval * objSize); - BAIL_IF_MACRO((retval < objCount) && (ferror(fh)),strerror(errno),retval); + BAIL_IF_MACRO((retval < (signed int) objCount) && (ferror(fh)), + strerror(errno),retval); return(retval); } /* GRP_read */ @@ -134,7 +134,9 @@ static int openGrp(const char *filename, int forWriting, FILE **fh, int *count) { char buf[12]; - assert(sizeof (int) == 4); + /* !!! FIXME: Get me platform-independent typedefs! */ + if (sizeof (int) != 4) + assert(0); *fh = NULL; BAIL_IF_MACRO(forWriting, ERR_ARC_IS_READ_ONLY, 0); diff --git a/archivers/zip.c b/archivers/zip.c index 6b42e014..51759386 100644 --- a/archivers/zip.c +++ b/archivers/zip.c @@ -20,7 +20,6 @@ #include #include #include -#include #include #include "physfs.h" #include "unzip.h" diff --git a/physfs.h b/physfs.h index bfe5a178..2d6afcc7 100644 --- a/physfs.h +++ b/physfs.h @@ -167,7 +167,7 @@ typedef struct __PHYSFS_VERSION__ #define PHYSFS_VER_MAJOR 0 #define PHYSFS_VER_MINOR 1 -#define PHYSFS_VER_PATCH 1 +#define PHYSFS_VER_PATCH 2 #define PHYSFS_VERSION(x) { \ (x)->major = PHYSFS_VER_MAJOR; \ diff --git a/physfs_internal.h b/physfs_internal.h index 4f01a94f..64a45c5c 100644 --- a/physfs_internal.h +++ b/physfs_internal.h @@ -295,7 +295,8 @@ char *__PHYSFS_convertToDependent(const char *prepend, int __PHYSFS_verifySecurity(DirHandle *h, const char *fname); -/* This gets used all over for lessening code clutter. */ +/* These get used all over for lessening code clutter. */ +#define BAIL_MACRO(e, r) { __PHYSFS_setError(e); return r; } #define BAIL_IF_MACRO(c, e, r) if (c) { __PHYSFS_setError(e); return r; } @@ -448,6 +449,14 @@ char *__PHYSFS_platformCurrentDir(void); char *__PHYSFS_platformRealPath(const char *path); +/* + * Make a directory in the actual filesystem. (path) is specified in + * platform-dependent notation. On error, return zero and set the error + * message. Return non-zero on success. + */ +int __PHYSFS_platformMkDir(const char *path); + + #ifdef __cplusplus extern "C" { #endif diff --git a/platform/unix.c b/platform/unix.c index 7d321e97..cbd7b22f 100644 --- a/platform/unix.c +++ b/platform/unix.c @@ -458,5 +458,14 @@ char *__PHYSFS_platformRealPath(const char *path) return(retval); } /* __PHYSFS_platformRealPath */ + +int __PHYSFS_platformMkDir(const char *path) +{ + errno = 0; + rc = mkdir(path, S_IRWXU); + BAIL_IF_MACRO(rc == -1, strerror(errno), 0); + return(1); +} /* __PHYSFS_platformMkDir */ + /* end of unix.c ... */