Updates, corrections and enhancements to get this ported to win32.

This commit is contained in:
Ryan C. Gordon 2001-08-23 15:23:21 +00:00
parent 500f1a6687
commit f0c09894c8
8 changed files with 45 additions and 12 deletions

View File

@ -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)

View File

@ -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)"
#-----------------------------------------------------------------------------#

View File

@ -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 @@ 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));

View File

@ -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 @@ 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);

View File

@ -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"

View File

@ -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; \

View File

@ -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

View File

@ -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 ... */