Skip to content

Commit

Permalink
Updates, corrections and enhancements to get this ported to win32.
Browse files Browse the repository at this point in the history
  • Loading branch information
icculus committed Aug 23, 2001
1 parent 500f1a6 commit f0c0989
Show file tree
Hide file tree
Showing 8 changed files with 45 additions and 12 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG
Expand Up @@ -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)

Expand Down
9 changes: 8 additions & 1 deletion Makefile
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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)"

#-----------------------------------------------------------------------------#
Expand Down
8 changes: 4 additions & 4 deletions archivers/dir.c
Expand Up @@ -13,7 +13,6 @@
#include <sys/stat.h>
#include <sys/types.h>
#include <fcntl.h>
#include <unistd.h>
#include "physfs.h"

#define __PHYSICSFS_INTERNAL__
Expand All @@ -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 */
Expand All @@ -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);
Expand Down Expand Up @@ -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));

Expand Down
10 changes: 6 additions & 4 deletions archivers/grp.c
Expand Up @@ -35,7 +35,6 @@
#include <sys/stat.h>
#include <sys/types.h>
#include <fcntl.h>
#include <unistd.h>
#include <assert.h>
#include "physfs.h"

Expand Down Expand Up @@ -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)
Expand All @@ -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 */
Expand Down Expand Up @@ -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);
Expand Down
1 change: 0 additions & 1 deletion archivers/zip.c
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion physfs.h
Expand Up @@ -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; \
Expand Down
11 changes: 10 additions & 1 deletion physfs_internal.h
Expand Up @@ -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; }


Expand Down Expand Up @@ -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
Expand Down
9 changes: 9 additions & 0 deletions platform/unix.c
Expand Up @@ -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 ... */

0 comments on commit f0c0989

Please sign in to comment.