00001 #include <stdio.h>
00002 #include "default_file.h"
00003
00004
00005 namespace audiere {
00006
00007 class CFile : public RefImplementation<File> {
00008 public:
00009 CFile(FILE* file) {
00010 m_file = file;
00011 }
00012
00013 ~CFile() {
00014 fclose(m_file);
00015 }
00016
00017 int ADR_CALL read(void* buffer, int size) {
00018 return fread(buffer, 1, size, m_file);
00019 }
00020
00021 bool ADR_CALL seek(int position, SeekMode mode) {
00022 int m;
00023 switch (mode) {
00024 case BEGIN: m = SEEK_SET; break;
00025 case CURRENT: m = SEEK_CUR; break;
00026 case END: m = SEEK_END; break;
00027 default: return false;
00028 }
00029
00030 return (fseek(m_file, position, m) == 0);
00031 }
00032
00033 int ADR_CALL tell() {
00034 return ftell(m_file);
00035 }
00036
00037 private:
00038 FILE* m_file;
00039 };
00040
00041
00042 File* OpenDefaultFile(const char* filename) {
00043 FILE* file = fopen(filename, "rb");
00044 return (file ? new CFile(file) : 0);
00045 }
00046
00047 }