summaryrefslogtreecommitdiff
path: root/updater/zbin/minizip/ioapi_mem.c
diff options
context:
space:
mode:
author(no author) <(no author)@4f64403b-2f21-0410-a795-97e2b3489a10>2010-11-10 01:32:22 +0000
committer(no author) <(no author)@4f64403b-2f21-0410-a795-97e2b3489a10>2010-11-10 01:32:22 +0000
commit0ff20b1aac36808f86b110d3028b6913c0634de7 (patch)
treea180b0b54bb2221980b4119f4acfe685be0216f3 /updater/zbin/minizip/ioapi_mem.c
parent63ea931032b288b78e611cf45543b655be295d16 (diff)
More appropriate minizip fix
git-svn-id: https://server.scottellis.com.au/svn/mim_plugs@550 4f64403b-2f21-0410-a795-97e2b3489a10
Diffstat (limited to 'updater/zbin/minizip/ioapi_mem.c')
-rw-r--r--updater/zbin/minizip/ioapi_mem.c68
1 files changed, 58 insertions, 10 deletions
diff --git a/updater/zbin/minizip/ioapi_mem.c b/updater/zbin/minizip/ioapi_mem.c
index 6f50c47..6ac1d16 100644
--- a/updater/zbin/minizip/ioapi_mem.c
+++ b/updater/zbin/minizip/ioapi_mem.c
@@ -45,7 +45,7 @@ uLong ZCALLBACK fwrite_mem_func OF((
const void* buf,
uLong size));
-long ZCALLBACK ftell_mem_func OF((
+uLong ZCALLBACK ftell_mem_func OF((
voidpf opaque,
voidpf stream));
@@ -66,9 +66,9 @@ int ZCALLBACK ferror_mem_func OF((
typedef struct ourmemory_s {
char *base; /* Base of the region of memory we're using */
- uLong size; /* Size of the region of memory we're using */
- uLong limit; /* Furthest we've written */
- uLong cur_offset; /* Current offset in the area */
+ size_t size; /* Size of the region of memory we're using */
+ size_t limit; /* Furthest we've written */
+ size_t cur_offset; /* Current offset in the area */
} ourmemory_t;
voidpf ZCALLBACK fopen_mem_func (opaque, filename, mode)
@@ -109,7 +109,7 @@ uLong ZCALLBACK fread_mem_func (opaque, stream, buf, size)
ourmemory_t *mem = (ourmemory_t *)stream;
if (size > mem->size - mem->cur_offset)
- size = mem->size - mem->cur_offset;
+ size = (uLong)(mem->size - mem->cur_offset);
memcpy(buf, mem->base + mem->cur_offset, size);
mem->cur_offset+=size;
@@ -127,7 +127,7 @@ uLong ZCALLBACK fwrite_mem_func (opaque, stream, buf, size)
ourmemory_t *mem = (ourmemory_t *)stream;
if (size > mem->size - mem->cur_offset)
- size = mem->size - mem->cur_offset;
+ size = (uLong)(mem->size - mem->cur_offset);
memcpy(mem->base + mem->cur_offset, buf, size);
mem->cur_offset+=size;
@@ -137,12 +137,19 @@ uLong ZCALLBACK fwrite_mem_func (opaque, stream, buf, size)
return size;
}
-long ZCALLBACK ftell_mem_func (opaque, stream)
+uLong ZCALLBACK ftell_mem_func (opaque, stream)
voidpf opaque;
voidpf stream;
{
ourmemory_t *mem = (ourmemory_t *)stream;
+ return (uLong)mem->cur_offset;
+}
+
+ZPOS64_T ZCALLBACK ftell64_mem_func (voidpf opaque, voidpf stream)
+{
+ ourmemory_t *mem = (ourmemory_t *)stream;
+
return mem->cur_offset;
}
@@ -153,14 +160,14 @@ long ZCALLBACK fseek_mem_func (opaque, stream, offset, origin)
int origin;
{
ourmemory_t *mem = (ourmemory_t *)stream;
- uLong new_pos;
+ size_t new_pos;
switch (origin)
{
case ZLIB_FILEFUNC_SEEK_CUR :
- new_pos = mem->cur_offset + offset;
+ new_pos = mem->cur_offset + (long)offset;
break;
case ZLIB_FILEFUNC_SEEK_END :
- new_pos = mem->limit + offset;
+ new_pos = mem->limit + (long)offset;
break;
case ZLIB_FILEFUNC_SEEK_SET :
new_pos = offset;
@@ -172,6 +179,34 @@ long ZCALLBACK fseek_mem_func (opaque, stream, offset, origin)
return 1; /* Failed to seek that far */
if (new_pos > mem->limit)
+ memset(mem->base + mem->limit, 0, (new_pos - mem->limit));
+
+ mem->cur_offset = new_pos;
+ return 0;
+}
+
+long ZCALLBACK fseek64_mem_func (voidpf opaque, voidpf stream, ZPOS64_T offset, int origin)
+{
+ ourmemory_t *mem = (ourmemory_t *)stream;
+ size_t new_pos;
+ switch (origin)
+ {
+ case ZLIB_FILEFUNC_SEEK_CUR :
+ new_pos = (size_t)(mem->cur_offset + (__int64)offset);
+ break;
+ case ZLIB_FILEFUNC_SEEK_END :
+ new_pos = (size_t)(mem->limit + (__int64)offset);
+ break;
+ case ZLIB_FILEFUNC_SEEK_SET :
+ new_pos = (size_t)offset;
+ break;
+ default: return -1;
+ }
+
+ if (new_pos > mem->size)
+ return 1; /* Failed to seek that far */
+
+ if (new_pos > mem->limit)
memset(mem->base + mem->limit, 0, new_pos - mem->limit);
mem->cur_offset = new_pos;
@@ -217,3 +252,16 @@ void fill_memory_filefunc (pzlib_filefunc_def)
pzlib_filefunc_def->zerror_file = ferror_mem_func;
pzlib_filefunc_def->opaque = NULL;
}
+
+void fill_memory_filefunc64 (pzlib_filefunc_def)
+ zlib_filefunc64_def* pzlib_filefunc_def;
+{
+ pzlib_filefunc_def->zopen64_file = fopen_mem_func;
+ pzlib_filefunc_def->zread_file = fread_mem_func;
+ pzlib_filefunc_def->zwrite_file = fwrite_mem_func;
+ pzlib_filefunc_def->ztell64_file = ftell64_mem_func;
+ pzlib_filefunc_def->zseek64_file = fseek64_mem_func;
+ pzlib_filefunc_def->zclose_file = fclose_mem_func;
+ pzlib_filefunc_def->zerror_file = ferror_mem_func;
+ pzlib_filefunc_def->opaque = NULL;
+}