ref: db4dcf6c1581496e336062c866ce522544d25849
parent: 4e0faec2b81698376b78c4715d633de23140cd10
author: Carlos Rafael Giani <dv@pseudoterminal.org>
date: Wed May 22 13:36:35 EDT 2013
the MEMFILE filesystem didn't have seek and get_size functions This caused crashes if read_any was used
--- a/dumb/src/helpers/memfile.c
+++ b/dumb/src/helpers/memfile.c
@@ -28,8 +28,8 @@
struct MEMFILE
{
- const char *ptr;
- long left;
+ const char *ptr, *ptr_begin;
+ long left, size;
};
@@ -73,13 +73,32 @@
}
+static int dumb_memfile_seek(void *f, long n)
+{
+ MEMFILE *m = f;
+ m->ptr = m->ptr_begin + n;
+ m->left = m->size - n;
+
+ return 0;
+}
+
+
+static long dumb_memfile_get_size(void *f)
+{
+ MEMFILE *m = f;
+ return m->size;
+}
+
+
static const DUMBFILE_SYSTEM memfile_dfs = {
NULL,
&dumb_memfile_skip,
&dumb_memfile_getc,
&dumb_memfile_getnc,
- &dumb_memfile_close
+ &dumb_memfile_close,
+ &dumb_memfile_seek,
+ &dumb_memfile_get_size
};
@@ -89,8 +108,10 @@
MEMFILE *m = malloc(sizeof(*m));
if (!m) return NULL;
+ m->ptr_begin = data;
m->ptr = data;
m->left = size;
+ m->size = size;
return dumbfile_open_ex(m, &memfile_dfs);
}