shithub: dumb

Download patch

ref: 0ac0a6f6b4e93f713fffc4136a4457b951e0432f
parent: 6b24397701f4565c95e1c4ab54efa36a3694e4e6
author: Christopher Snowhill <kode54@gmail.com>
date: Fri May 6 07:48:45 EDT 2016

Update packfile

This API kind of sucks.

--- a/src/allegro/packfile.c
+++ b/src/allegro/packfile.c
@@ -30,12 +30,12 @@
 } dumb_packfile;
 
 
-static void *dumb_packfile_open_ex(PACKFILE *p)
+static void *dumb_packfile_open_ex(PACKFILE *p, long size)
 {
 	dumb_packfile * file = ( dumb_packfile * ) malloc( sizeof(dumb_packfile) );
 	if ( !file ) return 0;
 	file->p = p;
-	file->size = file_size_ex(filename);
+	file->size = size;
 	file->pos = 0;
 	return file;
 }
@@ -43,7 +43,7 @@
 static void *dumb_packfile_open(const char *filename)
 {
 	PACKFILE *p = pack_fopen(filename, F_READ);
-	if (p) return dumb_packfile_open_ex(p);
+	if (p) return dumb_packfile_open_ex(p, file_size_ex(filename));
 	else return 0;
 }
 
@@ -132,10 +132,11 @@
 };
 
 
+/* XXX no way to get the file size from an existing PACKFILE without reading the entire contents first */
 
 DUMBFILE *dumbfile_open_packfile(PACKFILE *p)
 {
-	return dumbfile_open_ex(dumb_packfile_open_ex(p), &packfile_dfs_leave_open);
+	return dumbfile_open_ex(dumb_packfile_open_ex(p, 0x7fffffff), &packfile_dfs_leave_open);
 }
 
 
@@ -142,5 +143,5 @@
 
 DUMBFILE *dumbfile_from_packfile(PACKFILE *p)
 {
-	return p ? dumbfile_open_ex(dumb_packfile_open_ex(p), &packfile_dfs) : NULL;
+	return p ? dumbfile_open_ex(dumb_packfile_open_ex(p, 0x7fffffff), &packfile_dfs) : NULL;
 }