diff options
author | 2013-01-02 11:24:18 +0000 | |
---|---|---|
committer | 2013-01-02 11:24:18 +0000 | |
commit | 82191eb25ff75990acff7bb4445059be2e4294b9 (patch) | |
tree | ddd16cbdf6c61333f6bdab93691e31fa32cf6843 /src/lib | |
parent | c3aff0cfdc52d4bbaec4fbb4679278c78ed1e4e0 (diff) |
floppy: Correctly reach files inside zips or softlists [O. Galibert]
Diffstat (limited to 'src/lib')
-rw-r--r-- | src/lib/formats/ioprocs.c | 55 | ||||
-rw-r--r-- | src/lib/formats/ioprocs.h | 2 |
2 files changed, 57 insertions, 0 deletions
diff --git a/src/lib/formats/ioprocs.c b/src/lib/formats/ioprocs.c index 9adcf8783e7..66136f0cee1 100644 --- a/src/lib/formats/ioprocs.c +++ b/src/lib/formats/ioprocs.c @@ -2,6 +2,7 @@ #include <string.h> #include "osdcore.h" #include "ioprocs.h" +#include "corefile.h" /********************************************************************* @@ -58,6 +59,60 @@ const struct io_procs stdio_ioprocs_noclose = stdio_filesizeproc }; +/********************************************************************* + ioprocs implementation on corefile +*********************************************************************/ + +static void corefile_closeproc(void *file) +{ + core_fclose((core_file*)file); +} + +static int corefile_seekproc(void *file, INT64 offset, int whence) +{ + return core_fseek((core_file*)file, (long) offset, whence); +} + +static size_t corefile_readproc(void *file, void *buffer, size_t length) +{ + return core_fread((core_file*)file, buffer, length); +} + +static size_t corefile_writeproc(void *file, const void *buffer, size_t length) +{ + return core_fwrite((core_file*)file, buffer, length); +} + +static UINT64 corefile_filesizeproc(void *file) +{ + long l, sz; + l = core_ftell((core_file*)file); + if (core_fseek((core_file*)file, 0, SEEK_END)) + return (size_t) -1; + sz = core_ftell((core_file*)file); + if (core_fseek((core_file*)file, l, SEEK_SET)) + return (size_t) -1; + return (size_t) sz; +} + +const struct io_procs corefile_ioprocs = +{ + corefile_closeproc, + corefile_seekproc, + corefile_readproc, + corefile_writeproc, + corefile_filesizeproc +}; + +const struct io_procs corefile_ioprocs_noclose = +{ + NULL, + corefile_seekproc, + corefile_readproc, + corefile_writeproc, + corefile_filesizeproc +}; + /********************************************************************* diff --git a/src/lib/formats/ioprocs.h b/src/lib/formats/ioprocs.h index f6c30866988..94239c1ba56 100644 --- a/src/lib/formats/ioprocs.h +++ b/src/lib/formats/ioprocs.h @@ -46,6 +46,8 @@ struct io_generic extern const struct io_procs stdio_ioprocs; extern const struct io_procs stdio_ioprocs_noclose; +extern const struct io_procs corefile_ioprocs; +extern const struct io_procs corefile_ioprocs_noclose; |