Added PHYSFS_fileLength(). Bleh.
--- a/archivers/dir.c Mon Jul 09 01:45:13 2001 +0000
+++ b/archivers/dir.c Mon Jul 09 04:15:35 2001 +0000
@@ -70,6 +70,12 @@
} /* DIR_seek */
+static int DIR_fileLength(FileHandle *handle)
+{
+ return(__PHYSFS_platformFileLength((FILE *) (handle->opaque)));
+} /* DIR_fileLength */
+
+
static int DIR_fileClose(FileHandle *handle)
{
FILE *h = (FILE *) (handle->opaque);
@@ -283,18 +289,20 @@
DIR_eof, /* eof() method */
DIR_tell, /* tell() method */
DIR_seek, /* seek() method */
- DIR_fileClose, /* fileClose() 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_fileClose /* fileClose() method */
+ 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 */
};
--- a/archivers/grp.c Mon Jul 09 01:45:13 2001 +0000
+++ b/archivers/grp.c Mon Jul 09 04:15:35 2001 +0000
@@ -115,6 +115,13 @@
} /* GRP_seek */
+static int GRP_fileLength(FileHandle *handle)
+{
+ GRPfileinfo *finfo = (GRPfileinfo *) (handle->opaque);
+ return(finfo->size);
+} /* GRP_fileLength */
+
+
static int GRP_fileClose(FileHandle *handle)
{
free(handle->opaque);
@@ -340,12 +347,13 @@
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_fileClose /* fileClose() method */
+ 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 */
};
--- a/archivers/zip.c Mon Jul 09 01:45:13 2001 +0000
+++ b/archivers/zip.c Mon Jul 09 04:15:35 2001 +0000
@@ -42,6 +42,11 @@
} /* ZIP_seek */
+static int ZIP_fileLength(FileHandle *handle)
+{
+} /* ZIP_fileLength */
+
+
static int ZIP_fileClose(FileHandle *handle)
{
} /* ZIP_fileClose */
@@ -89,12 +94,13 @@
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_fileClose /* fileClose() method */
+ 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 */
};
--- a/physfs.c Mon Jul 09 01:45:13 2001 +0000
+++ b/physfs.c Mon Jul 09 04:15:35 2001 +0000
@@ -1227,5 +1227,15 @@
} /* PHYSFS_seek */
+int PHYSFS_fileLength(PHYSFS_file *handle)
+{
+ FileHandle *h = (FileHandle *) handle->opaque;
+ assert(h != NULL);
+ assert(h->funcs != NULL);
+ BAIL_IF_MACRO(h->funcs->fileLength == NULL, ERR_NOT_SUPPORTED, 0);
+ return(h->funcs->fileLength(h));
+} /* PHYSFS_filelength */
+
+
/* end of physfs.c ... */
--- a/physfs.h Mon Jul 09 01:45:13 2001 +0000
+++ b/physfs.h Mon Jul 09 04:15:35 2001 +0000
@@ -791,6 +791,20 @@
*/
int PHYSFS_seek(PHYSFS_file *handle, int pos);
+
+/**
+ * Get total length of a file in bytes. Note that if the file size can't
+ * be determined (since the archive is "streamed" or whatnot) than this
+ * with report (-1). Also note that if another process/thread is writing
+ * to this file at the same time, then the information this function
+ * supplies could be incorrect before you get it. Use with caution, or
+ * better yet, don't use at all.
+ *
+ * @param handle handle returned from PHYSFS_open*().
+ * @return size in bytes of the file. -1 if can't be determined.
+ */
+int PHYSFS_fileLength(PHYSFS_file *handle);
+
#ifdef __cplusplus
}
#endif
--- a/physfs_internal.h Mon Jul 09 01:45:13 2001 +0000
+++ b/physfs_internal.h Mon Jul 09 04:15:35 2001 +0000
@@ -83,6 +83,13 @@
int (*seek)(FileHandle *handle, int offset);
/*
+ * Return number of bytes available in the file, or -1 if you
+ * aren't able to determine.
+ * On failure, call __PHYSFS_setError().
+ */
+ int (*fileLength)(FileHandle *handle);
+
+ /*
* Close the file, and free the FileHandle structure (including "opaque").
* returns non-zero on success, zero if can't close file.
* On failure, call __PHYSFS_setError().
@@ -402,6 +409,13 @@
LinkedStringList *__PHYSFS_platformEnumerateFiles(const char *dirname);
+/*
+ * Determine the current size of a file, in bytes, from a stdio FILE *.
+ * Return -1 if you can't do it, and call __PHYSFS_setError().
+ */
+int __PHYSFS_platformFileLength(FILE *handle);
+
+
#ifdef __cplusplus
extern "C" {
#endif
--- a/platform/unix.c Mon Jul 09 01:45:13 2001 +0000
+++ b/platform/unix.c Mon Jul 09 04:15:35 2001 +0000
@@ -328,5 +328,14 @@
} /* __PHYSFS_platformEnumerateFiles */
+int __PHYSFS_platformFileLength(FILE *handle)
+{
+ struct stat statbuf;
+ errno = 0;
+ BAIL_IF_MACRO(fstat(fileno(handle), &statbuf) == -1, strerror(errno), -1);
+ return(statbuf.st_size);
+} /* __PHYSFS_platformFileLength */
+
+
/* end of unix.c ... */