Updates, corrections and enhancements to get this ported to win32.
--- a/CHANGELOG Thu Aug 23 15:22:52 2001 +0000
+++ b/CHANGELOG Thu Aug 23 15:23:21 2001 +0000
@@ -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)
--- a/Makefile Thu Aug 23 15:22:52 2001 +0000
+++ b/Makefile Thu Aug 23 15:23:21 2001 +0000
@@ -165,7 +165,7 @@
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 @@
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 @@
@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)"
#-----------------------------------------------------------------------------#
--- a/archivers/dir.c Thu Aug 23 15:22:52 2001 +0000
+++ b/archivers/dir.c Thu Aug 23 15:23:21 2001 +0000
@@ -13,7 +13,6 @@
#include <sys/stat.h>
#include <sys/types.h>
#include <fcntl.h>
-#include <unistd.h>
#include "physfs.h"
#define __PHYSICSFS_INTERNAL__
@@ -31,7 +30,8 @@
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 @@
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 @@
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));
--- a/archivers/grp.c Thu Aug 23 15:22:52 2001 +0000
+++ b/archivers/grp.c Thu Aug 23 15:23:21 2001 +0000
@@ -35,7 +35,6 @@
#include <sys/stat.h>
#include <sys/types.h>
#include <fcntl.h>
-#include <unistd.h>
#include <assert.h>
#include "physfs.h"
@@ -71,7 +70,7 @@
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 @@
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 @@
{
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);
--- a/archivers/zip.c Thu Aug 23 15:22:52 2001 +0000
+++ b/archivers/zip.c Thu Aug 23 15:23:21 2001 +0000
@@ -20,7 +20,6 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
-#include <unistd.h>
#include <errno.h>
#include "physfs.h"
#include "unzip.h"
--- a/physfs.h Thu Aug 23 15:22:52 2001 +0000
+++ b/physfs.h Thu Aug 23 15:23:21 2001 +0000
@@ -167,7 +167,7 @@
#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; \
--- a/physfs_internal.h Thu Aug 23 15:22:52 2001 +0000
+++ b/physfs_internal.h Thu Aug 23 15:23:21 2001 +0000
@@ -295,7 +295,8 @@
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_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
--- a/platform/unix.c Thu Aug 23 15:22:52 2001 +0000
+++ b/platform/unix.c Thu Aug 23 15:23:21 2001 +0000
@@ -458,5 +458,14 @@
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 ... */