Patched to compile with an ancient version of CodeWarrior.
--- a/archivers/dir.c Sun Sep 02 01:17:35 2001 +0000
+++ b/archivers/dir.c Sun Sep 02 04:55:25 2001 +0000
@@ -10,30 +10,102 @@
#include <stdlib.h>
#include <string.h>
#include <errno.h>
-#include <sys/stat.h>
-#include <sys/types.h>
#include <fcntl.h>
#include "physfs.h"
#define __PHYSICSFS_INTERNAL__
#include "physfs_internal.h"
-extern const DirFunctions __PHYSFS_DirFunctions_DIR;
-static const FileFunctions __PHYSFS_FileFunctions_DIR;
-static const FileFunctions __PHYSFS_FileFunctions_DIRW;
+static int DIR_read(FileHandle *handle, void *buffer,
+ unsigned int objSize, unsigned int objCount);
+static int DIR_write(FileHandle *handle, void *buffer,
+ unsigned int objSize, unsigned int objCount);
+static int DIR_eof(FileHandle *handle);
+static int DIR_tell(FileHandle *handle);
+static int DIR_seek(FileHandle *handle, int offset);
+static int DIR_fileLength(FileHandle *handle);
+static int DIR_fileClose(FileHandle *handle);
+static int DIR_isArchive(const char *filename, int forWriting);
+static DirHandle *DIR_openArchive(const char *name, int forWriting);
+static LinkedStringList *DIR_enumerateFiles(DirHandle *h,
+ const char *dname,
+ int omitSymLinks);
+static int DIR_exists(DirHandle *h, const char *name);
+static int DIR_isDirectory(DirHandle *h, const char *name);
+static int DIR_isSymLink(DirHandle *h, const char *name);
+static FileHandle *DIR_openRead(DirHandle *h, const char *filename);
+static FileHandle *DIR_openWrite(DirHandle *h, const char *filename);
+static FileHandle *DIR_openAppend(DirHandle *h, const char *filename);
+static int DIR_remove(DirHandle *h, const char *name);
+static int DIR_mkdir(DirHandle *h, const char *name);
+static void DIR_dirClose(DirHandle *h);
+
+
+static const FileFunctions __PHYSFS_FileFunctions_DIR =
+{
+ DIR_read, /* read() method */
+ NULL, /* write() method */
+ DIR_eof, /* eof() method */
+ DIR_tell, /* tell() method */
+ DIR_seek, /* seek() method */
+ DIR_fileLength, /* fileLength() method */
+ DIR_fileClose /* fileClose() method */
+};
+
+
+static const FileFunctions __PHYSFS_FileFunctions_DIRW =
+{
+ NULL, /* read() method */
+ DIR_write, /* write() method */
+ DIR_eof, /* eof() method */
+ DIR_tell, /* tell() method */
+ DIR_seek, /* seek() method */
+ DIR_fileLength, /* fileLength() method */
+ DIR_fileClose /* fileClose() method */
+};
+
+
+const DirFunctions __PHYSFS_DirFunctions_DIR =
+{
+ DIR_isArchive, /* isArchive() method */
+ DIR_openArchive, /* openArchive() method */
+ DIR_enumerateFiles, /* enumerateFiles() method */
+ DIR_exists, /* exists() method */
+ DIR_isDirectory, /* isDirectory() method */
+ DIR_isSymLink, /* isSymLink() method */
+ DIR_openRead, /* openRead() method */
+ DIR_openWrite, /* openWrite() method */
+ DIR_openAppend, /* openAppend() method */
+ DIR_remove, /* remove() method */
+ DIR_mkdir, /* mkdir() method */
+ DIR_dirClose /* dirClose() method */
+};
+
+
+/* This doesn't get listed, since it's technically not an archive... */
+#if 0
+const PHYSFS_ArchiveInfo __PHYSFS_ArchiveInfo_DIR =
+{
+ "DIR",
+ "non-archive directory I/O",
+ "Ryan C. Gordon (icculus@clutteredmind.org)",
+ "http://www.icculus.org/physfs/",
+};
+#endif
+
static int DIR_read(FileHandle *handle, void *buffer,
unsigned int objSize, unsigned int objCount)
{
FILE *h = (FILE *) (handle->opaque);
- int retval;
+ size_t retval;
errno = 0;
retval = fread(buffer, objSize, objCount, h);
- BAIL_IF_MACRO((retval < (signed int) objCount) && (ferror(h)),
- strerror(errno),retval);
+ BAIL_IF_MACRO((retval < (size_t) objCount) && (ferror(h)),
+ strerror(errno), (int) retval);
- return(retval);
+ return((int) retval);
} /* DIR_read */
@@ -41,14 +113,14 @@
unsigned int objSize, unsigned int objCount)
{
FILE *h = (FILE *) (handle->opaque);
- int retval;
+ size_t retval;
errno = 0;
- retval = fwrite(buffer, objSize, objCount, h);
+ retval = fwrite(buffer, (size_t) objSize, objCount, h);
if ( (retval < (signed int) objCount) && (ferror(h)) )
__PHYSFS_setError(strerror(errno));
- return(retval);
+ return((int) retval);
} /* DIR_write */
@@ -80,6 +152,7 @@
{
FILE *h = (FILE *) (handle->opaque);
+#if 0
/*
* we manually fflush() the buffer, since that's the place fclose() will
* most likely fail, but that will leave the file handle in an undefined
@@ -94,6 +167,7 @@
/* EBADF == "Not open for writing". That's fine. */
BAIL_IF_MACRO((errno != 0) && (errno != EBADF), strerror(errno), 0);
+#endif
/* if fclose fails anyhow, we just have to pray that it's still usable. */
errno = 0;
@@ -115,8 +189,8 @@
{
const char *dirsep = PHYSFS_getDirSeparator();
DirHandle *retval = NULL;
- int namelen = strlen(name);
- int seplen = strlen(dirsep);
+ size_t namelen = strlen(name);
+ size_t seplen = strlen(dirsep);
BAIL_IF_MACRO(!DIR_isArchive(name, forWriting),
ERR_UNSUPPORTED_ARCHIVE, NULL);
@@ -282,59 +356,5 @@
free(h);
} /* DIR_dirClose */
-
-
-static const FileFunctions __PHYSFS_FileFunctions_DIR =
-{
- DIR_read, /* read() method */
- NULL, /* write() method */
- DIR_eof, /* eof() method */
- DIR_tell, /* tell() method */
- DIR_seek, /* seek() method */
- DIR_fileLength, /* fileLength() method */
- DIR_fileClose /* fileClose() method */
-};
-
-
-static const FileFunctions __PHYSFS_FileFunctions_DIRW =
-{
- NULL, /* read() method */
- DIR_write, /* write() method */
- DIR_eof, /* eof() method */
- DIR_tell, /* tell() method */
- DIR_seek, /* seek() method */
- DIR_fileLength, /* fileLength() method */
- DIR_fileClose /* fileClose() method */
-};
-
-
-const DirFunctions __PHYSFS_DirFunctions_DIR =
-{
- DIR_isArchive, /* isArchive() method */
- DIR_openArchive, /* openArchive() method */
- DIR_enumerateFiles, /* enumerateFiles() method */
- DIR_exists, /* exists() method */
- DIR_isDirectory, /* isDirectory() method */
- DIR_isSymLink, /* isSymLink() method */
- DIR_openRead, /* openRead() method */
- DIR_openWrite, /* openWrite() method */
- DIR_openAppend, /* openAppend() method */
- DIR_remove, /* remove() method */
- DIR_mkdir, /* mkdir() method */
- DIR_dirClose /* dirClose() method */
-};
-
-
-/* This doesn't get listed, since it's technically not an archive... */
-#if 0
-const PHYSFS_ArchiveInfo __PHYSFS_ArchiveInfo_DIR =
-{
- "DIR",
- "non-archive directory I/O",
- "Ryan C. Gordon",
- "http://www.icculus.org/",
-};
-#endif
-
/* end of dir.c ... */
--- a/archivers/grp.c Sun Sep 02 01:17:35 2001 +0000
+++ b/archivers/grp.c Sun Sep 02 04:55:25 2001 +0000
@@ -32,8 +32,6 @@
#include <stdlib.h>
#include <string.h>
#include <errno.h>
-#include <sys/stat.h>
-#include <sys/types.h>
#include <fcntl.h>
#include <assert.h>
#include "physfs.h"
@@ -41,10 +39,11 @@
#define __PHYSICSFS_INTERNAL__
#include "physfs_internal.h"
+#if 0
#if (!defined PHYSFS_SUPPORTS_GRP)
#error PHYSFS_SUPPORTS_GRP must be defined.
#endif
-
+#endif
typedef struct
{
@@ -60,8 +59,68 @@
} GRPfileinfo;
-extern const DirFunctions __PHYSFS_DirFunctions_GRP;
-static const FileFunctions __PHYSFS_FileFunctions_GRP;
+static void GRP_dirClose(DirHandle *h);
+static int GRP_read(FileHandle *handle, void *buffer,
+ unsigned int objSize, unsigned int objCount);
+static int GRP_eof(FileHandle *handle);
+static int GRP_tell(FileHandle *handle);
+static int GRP_seek(FileHandle *handle, int offset);
+static int GRP_fileLength(FileHandle *handle);
+static int GRP_fileClose(FileHandle *handle);
+static int GRP_isArchive(const char *filename, int forWriting);
+static DirHandle *GRP_openArchive(const char *name, int forWriting);
+static LinkedStringList *GRP_enumerateFiles(DirHandle *h,
+ const char *dirname,
+ int omitSymLinks);
+static int GRP_exists(DirHandle *h, const char *name);
+static int GRP_isDirectory(DirHandle *h, const char *name);
+static int GRP_isSymLink(DirHandle *h, const char *name);
+static FileHandle *GRP_openRead(DirHandle *h, const char *name);
+
+static const FileFunctions __PHYSFS_FileFunctions_GRP =
+{
+ GRP_read, /* read() method */
+ NULL, /* write() method */
+ GRP_eof, /* eof() method */
+ GRP_tell, /* tell() method */
+ GRP_seek, /* seek() method */
+ GRP_fileLength, /* fileLength() method */
+ GRP_fileClose /* fileClose() method */
+};
+
+
+const DirFunctions __PHYSFS_DirFunctions_GRP =
+{
+ GRP_isArchive, /* isArchive() method */
+ GRP_openArchive, /* openArchive() method */
+ GRP_enumerateFiles, /* enumerateFiles() method */
+ GRP_exists, /* exists() method */
+ GRP_isDirectory, /* isDirectory() method */
+ GRP_isSymLink, /* isSymLink() method */
+ GRP_openRead, /* openRead() method */
+ NULL, /* openWrite() method */
+ NULL, /* openAppend() method */
+ NULL, /* remove() method */
+ NULL, /* mkdir() method */
+ GRP_dirClose /* dirClose() method */
+};
+
+const PHYSFS_ArchiveInfo __PHYSFS_ArchiveInfo_GRP =
+{
+ "GRP",
+ "Build engine Groupfile format",
+ "Ryan C. Gordon (icculus@clutteredmind.org)",
+ "http://www.icculus.org/physfs/",
+};
+
+
+
+static void GRP_dirClose(DirHandle *h)
+{
+ fclose( ((GRPinfo *) h->opaque)->handle );
+ free(h->opaque);
+ free(h);
+} /* GRP_dirClose */
static int GRP_read(FileHandle *handle, void *buffer,
@@ -71,7 +130,7 @@
FILE *fh = (FILE *) (((GRPinfo *) (handle->dirHandle->opaque))->handle);
int bytesLeft = (finfo->startPos + finfo->size) - finfo->curPos;
unsigned int objsLeft = bytesLeft / objSize;
- int retval = 0;
+ size_t retval = 0;
if (objsLeft < objCount)
objCount = objsLeft;
@@ -82,10 +141,10 @@
errno = 0;
retval = fread(buffer, objSize, objCount, fh);
finfo->curPos += (retval * objSize);
- BAIL_IF_MACRO((retval < (signed int) objCount) && (ferror(fh)),
- strerror(errno),retval);
+ BAIL_IF_MACRO((retval < (size_t) objCount) && (ferror(fh)),
+ strerror(errno), (int) retval);
- return(retval);
+ return((int) retval);
} /* GRP_read */
@@ -345,50 +404,5 @@
return(retval);
} /* GRP_openRead */
-
-static void GRP_dirClose(DirHandle *h)
-{
- fclose( ((GRPinfo *) h->opaque)->handle );
- free(h->opaque);
- free(h);
-} /* GRP_dirClose */
-
-
-static const FileFunctions __PHYSFS_FileFunctions_GRP =
-{
- GRP_read, /* read() method */
- NULL, /* write() method */
- GRP_eof, /* eof() method */
- GRP_tell, /* tell() method */
- GRP_seek, /* seek() method */
- GRP_fileLength, /* fileLength() method */
- GRP_fileClose /* fileClose() method */
-};
-
-
-const DirFunctions __PHYSFS_DirFunctions_GRP =
-{
- GRP_isArchive, /* isArchive() method */
- GRP_openArchive, /* openArchive() method */
- GRP_enumerateFiles, /* enumerateFiles() method */
- GRP_exists, /* exists() method */
- GRP_isDirectory, /* isDirectory() method */
- GRP_isSymLink, /* isSymLink() method */
- GRP_openRead, /* openRead() method */
- NULL, /* openWrite() method */
- NULL, /* openAppend() method */
- NULL, /* remove() method */
- NULL, /* mkdir() method */
- GRP_dirClose /* dirClose() method */
-};
-
-const PHYSFS_ArchiveInfo __PHYSFS_ArchiveInfo_GRP =
-{
- "GRP",
- "Build engine Groupfile format",
- "Ryan C. Gordon (icculus@clutteredmind.org)",
- "http://www.icculus.org/physfs/",
-};
-
/* end of grp.c ... */
--- a/archivers/zip.c Sun Sep 02 01:17:35 2001 +0000
+++ b/archivers/zip.c Sun Sep 02 04:55:25 2001 +0000
@@ -54,12 +54,66 @@
} ZIPfileinfo;
-extern const DirFunctions __PHYSFS_DirFunctions_ZIP;
-static const FileFunctions __PHYSFS_FileFunctions_ZIP;
+/* Number of symlinks to follow before we assume it's a recursive link... */
+#define SYMLINK_RECURSE_COUNT 20
+
+
+static int ZIP_read(FileHandle *handle, void *buffer,
+ unsigned int objSize, unsigned int objCount);
+static int ZIP_eof(FileHandle *handle);
+static int ZIP_tell(FileHandle *handle);
+static int ZIP_seek(FileHandle *handle, int offset);
+static int ZIP_fileLength(FileHandle *handle);
+static int ZIP_fileClose(FileHandle *handle);
+static int ZIP_isArchive(const char *filename, int forWriting);
+static char *ZIP_realpath(unzFile fh, unz_file_info *info);
+static DirHandle *ZIP_openArchive(const char *name, int forWriting);
+static LinkedStringList *ZIP_enumerateFiles(DirHandle *h,
+ const char *dirname,
+ int omitSymLinks);
+static int ZIP_exists(DirHandle *h, const char *name);
+static int ZIP_isDirectory(DirHandle *h, const char *name);
+static int ZIP_isSymLink(DirHandle *h, const char *name);
+static FileHandle *ZIP_openRead(DirHandle *h, const char *filename);
+static void ZIP_dirClose(DirHandle *h);
-/* Number of symlinks to follow before we assume it's a recursive link... */
-#define SYMLINK_RECURSE_COUNT 20
+static const FileFunctions __PHYSFS_FileFunctions_ZIP =
+{
+ ZIP_read, /* read() method */
+ NULL, /* write() method */
+ ZIP_eof, /* eof() method */
+ ZIP_tell, /* tell() method */
+ ZIP_seek, /* seek() method */
+ ZIP_fileLength, /* fileLength() method */
+ ZIP_fileClose /* fileClose() method */
+};
+
+
+const DirFunctions __PHYSFS_DirFunctions_ZIP =
+{
+ ZIP_isArchive, /* isArchive() method */
+ ZIP_openArchive, /* openArchive() method */
+ ZIP_enumerateFiles, /* enumerateFiles() method */
+ ZIP_exists, /* exists() method */
+ ZIP_isDirectory, /* isDirectory() method */
+ ZIP_isSymLink, /* isSymLink() method */
+ ZIP_openRead, /* openRead() method */
+ NULL, /* openWrite() method */
+ NULL, /* openAppend() method */
+ NULL, /* remove() method */
+ NULL, /* mkdir() method */
+ ZIP_dirClose /* dirClose() method */
+};
+
+const PHYSFS_ArchiveInfo __PHYSFS_ArchiveInfo_ZIP =
+{
+ "ZIP",
+ "PkZip/WinZip/Info-Zip compatible",
+ "Ryan C. Gordon (icculus@clutteredmind.org)",
+ "http://www.icculus.org/physfs/",
+};
+
static int ZIP_read(FileHandle *handle, void *buffer,
@@ -92,9 +146,6 @@
} /* ZIP_tell */
-static int ZIP_fileLength(FileHandle *handle);
-
-
static int ZIP_seek(FileHandle *handle, int offset)
{
/* this blows. */
@@ -623,42 +674,5 @@
free(h);
} /* ZIP_dirClose */
-
-static const FileFunctions __PHYSFS_FileFunctions_ZIP =
-{
- ZIP_read, /* read() method */
- NULL, /* write() method */
- ZIP_eof, /* eof() method */
- ZIP_tell, /* tell() method */
- ZIP_seek, /* seek() method */
- ZIP_fileLength, /* fileLength() method */
- ZIP_fileClose /* fileClose() method */
-};
-
-
-const DirFunctions __PHYSFS_DirFunctions_ZIP =
-{
- ZIP_isArchive, /* isArchive() method */
- ZIP_openArchive, /* openArchive() method */
- ZIP_enumerateFiles, /* enumerateFiles() method */
- ZIP_exists, /* exists() method */
- ZIP_isDirectory, /* isDirectory() method */
- ZIP_isSymLink, /* isSymLink() method */
- ZIP_openRead, /* openRead() method */
- NULL, /* openWrite() method */
- NULL, /* openAppend() method */
- NULL, /* remove() method */
- NULL, /* mkdir() method */
- ZIP_dirClose /* dirClose() method */
-};
-
-const PHYSFS_ArchiveInfo __PHYSFS_ArchiveInfo_ZIP =
-{
- "ZIP",
- "PkZip/WinZip/Info-Zip compatible",
- "Ryan C. Gordon (icculus@clutteredmind.org)",
- "http://www.icculus.org/physfs/",
-};
-
/* end of zip.c ... */
--- a/physfs.c Sun Sep 02 01:17:35 2001 +0000
+++ b/physfs.c Sun Sep 02 04:55:25 2001 +0000
@@ -11,8 +11,6 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
-#include <sys/stat.h>
-#include <sys/types.h>
#include <fcntl.h>
#include <errno.h>
#include <assert.h>
@@ -700,13 +698,13 @@
{
char **rc = PHYSFS_enumerateFiles("");
char **i;
- int extlen = strlen(archiveExt);
+ size_t extlen = strlen(archiveExt);
char *ext;
for (i = rc; *i != NULL; i++)
{
- int l = strlen(*i);
- if ((l > extlen) && ((*i)[l - extlen - 1] == '.'));
+ size_t l = strlen(*i);
+ if ((l > extlen) && ((*i)[l - extlen - 1] == '.'))
{
ext = (*i) + (l - extlen);
if (__PHYSFS_platformStricmp(ext, archiveExt) == 0)
@@ -742,7 +740,7 @@
const char *append)
{
const char *dirsep = PHYSFS_getDirSeparator();
- int sepsize = strlen(dirsep);
+ size_t sepsize = strlen(dirsep);
char *str;
char *i1;
char *i2;
@@ -966,7 +964,7 @@
finalList = next;
} /* for */
- if (retval != NULL);
+ if (retval != NULL)
retval[i] = NULL;
return(retval);