diff options
author | waker <wakeroid@gmail.com> | 2011-02-01 20:23:41 +0100 |
---|---|---|
committer | waker <wakeroid@gmail.com> | 2011-02-01 20:23:41 +0100 |
commit | c0606a32db2c30abf4ab8f54ab44c6624be89c32 (patch) | |
tree | 80c3514465b5267bfce551989648e4bf88c4bd45 /plugins/adplug/libbinio/binfile.cpp | |
parent | cb26c00e37ad876f2d3f0f5704e323bf6d47ec48 (diff) |
added vfs support to adplug (libbinio)
Diffstat (limited to 'plugins/adplug/libbinio/binfile.cpp')
-rw-r--r-- | plugins/adplug/libbinio/binfile.cpp | 28 |
1 files changed, 18 insertions, 10 deletions
diff --git a/plugins/adplug/libbinio/binfile.cpp b/plugins/adplug/libbinio/binfile.cpp index 336f1b3b..a20315ac 100644 --- a/plugins/adplug/libbinio/binfile.cpp +++ b/plugins/adplug/libbinio/binfile.cpp @@ -22,6 +22,8 @@ #include "binfile.h" +extern DB_functions_t *deadbeef; + /***** binfbase *****/ binfbase::binfbase() @@ -37,7 +39,8 @@ binfbase::~binfbase() void binfbase::close() { if(f != NULL) { - if(fclose(f) == EOF) err |= Fatal; else f = NULL; + deadbeef->fclose(f); + f = NULL; } else err |= NotOpen; } @@ -49,9 +52,9 @@ void binfbase::seek(long pos, Offset offs) if(f == NULL) { err |= NotOpen; return; } switch(offs) { - case Set: error = fseek(f, pos, SEEK_SET); break; - case Add: error = fseek(f, pos, SEEK_CUR); break; - case End: error = fseek(f, pos, SEEK_END); break; + case Set: error = deadbeef->fseek(f, pos, SEEK_SET); break; + case Add: error = deadbeef->fseek(f, pos, SEEK_CUR); break; + case End: error = deadbeef->fseek(f, pos, SEEK_END); break; } if(error == -1) err |= Fatal; @@ -63,7 +66,7 @@ long binfbase::pos() if(f == NULL) { err |= NotOpen; return 0; } - pos = ftell(f); + pos = deadbeef->ftell(f); if(pos == -1) { err |= Fatal; @@ -96,7 +99,7 @@ binifstream::~binifstream() void binifstream::open(const char *filename, const Mode mode) { - f = fopen(filename, "rb"); + f = deadbeef->fopen(filename); if(f == NULL) switch(errno) { @@ -118,8 +121,9 @@ binifstream::Byte binifstream::getByte() int read; if(f != NULL) { - read = fgetc(f); - if(read == EOF) err |= Eof; + if (1 != deadbeef->fread (&read, 1, 1, f)) { + err |= Eof; + } return (Byte)read; } else { err |= NotOpen; @@ -151,6 +155,7 @@ binofstream::~binofstream() void binofstream::open(const char *filename, const Mode mode) { +#if 0 const char *modestr = "wb"; // Check if append mode is desired @@ -168,6 +173,7 @@ void binofstream::open(const char *filename, const Mode mode) case ENOENT: err |= NotFound; break; default: err |= NotOpen; break; } +#endif } #if BINIO_ENABLE_STRING @@ -179,10 +185,12 @@ void binofstream::open(const std::string &filename, const Mode mode) void binofstream::putByte(Byte b) { +#if 0 if(f == NULL) { err |= NotOpen; return; } if(fputc(b, f) == EOF) err |= Fatal; +#endif } /***** binfstream *****/ @@ -220,11 +228,11 @@ void binfstream::open(const char *filename, const Mode mode) if(mode & Append) // Create & append modestr = "a+b"; - f = fopen(filename, modestr); + f = deadbeef->fopen(filename); // NoCreate & append (emulated -- not possible with standard C fopen()) if(f != NULL && (mode & Append) && (mode & NoCreate)) - ferror = fseek(f, 0, SEEK_END); + ferror = deadbeef->fseek(f, 0, SEEK_END); if(f == NULL || ferror == -1) { switch(errno) { |