ref: b1fd89712225fed501970ab417706453f7640fc6
parent: b3e4717d9a8216171495366bc91aaeeefc1e0e94
author: Azamat H. Hackimov <azamat.hackimov@gmail.com>
date: Fri May 6 06:18:00 EDT 2016
Added support for dumb_*_noclose, dumb_*_seek, dumb_*_get_size Added support for new DUMB API.
--- a/src/allegro/packfile.c
+++ b/src/allegro/packfile.c
@@ -22,10 +22,22 @@
#include "aldumb.h"
+typedef struct dumb_packfile
+{
+ FILE * file;
+ long size;
+} dumb_packfile;
+
static void *dumb_packfile_open(const char *filename)
{
- return pack_fopen(filename, F_READ);
+ dumb_packfile * file = ( dumb_packfile * ) malloc( sizeof(dumb_packfile) );
+ if ( !file ) return 0;
+ file->file = fopen(filename, "rb");
+ fseek(file->file, 0, SEEK_END);
+ file->size = ftell(file->file);
+ fseek(file->file, 0, SEEK_SET);
+ return file;
}
@@ -32,7 +44,8 @@
static int dumb_packfile_skip(void *f, long n)
{
- return pack_fseek(f, n);
+ dumb_packfile * file = ( dumb_packfile * ) f;
+ return fseek(file->file, n, SEEK_CUR);
}
@@ -39,7 +52,8 @@
static int dumb_packfile_getc(void *f)
{
- return pack_getc(f);
+ dumb_packfile * file = ( dumb_packfile * ) f;
+ return fgetc(file->file);
}
@@ -46,7 +60,8 @@
static long dumb_packfile_getnc(char *ptr, long n, void *f)
{
- return pack_fread(ptr, n, f);
+ dumb_packfile * file = ( dumb_packfile * ) f;
+ return fread(ptr, 1, n, file->file);
}
@@ -53,17 +68,36 @@
static void dumb_packfile_close(void *f)
{
- pack_fclose(f);
+ dumb_packfile * file = ( dumb_packfile * ) f;
+ fclose(file->file);
+ free(f);
}
+static void dumb_packfile_noclose(void *f)
+{
+ free(f);
+}
+static int dumb_packfile_seek(void *f, long n)
+{
+ dumb_packfile * file = (dumb_packfile *) f;
+ return fseek(file->file, n, SEEK_SET);
+}
+static long dumb_packfile_get_size(void *f)
+{
+ dumb_packfile * file = (dumb_packfile *) f;
+ return file->size;
+}
+
static DUMBFILE_SYSTEM packfile_dfs = {
&dumb_packfile_open,
&dumb_packfile_skip,
&dumb_packfile_getc,
&dumb_packfile_getnc,
- &dumb_packfile_close
+ &dumb_packfile_close,
+ &dumb_packfile_seek,
+ &dumb_packfile_get_size
};
@@ -80,7 +114,9 @@
&dumb_packfile_skip,
&dumb_packfile_getc,
&dumb_packfile_getnc,
- NULL
+ &dumb_packfile_noclose,
+ &dumb_packfile_seek,
+ &dumb_packfile_get_size
};