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