defaultfilesystem.cpp

来自「这个刚才那个的源代码」· C++ 代码 · 共 51 行

CPP
51
字号
#include <stdio.h>
#include "Utility.h"


namespace corona {

  class CFile : public DLLImplementation<File> {
  public:
    CFile(FILE* file) {
      m_file = file;
    }

    ~CFile() {
      fclose(m_file);
    }

    int COR_CALL read(void* buffer, int size) {
      return fread(buffer, 1, size, m_file);
    }

    int COR_CALL write(const void* buffer, int size) {
      return fwrite(buffer, 1, size, m_file);
    }

    bool COR_CALL seek(int position, SeekMode mode) {
      int m;
      switch (mode) {
        case BEGIN:   m = SEEK_SET; break;
        case CURRENT: m = SEEK_CUR; break;
        case END:     m = SEEK_END; break;
        default: return false;
      }
      return fseek(m_file, position, m) == 0;
    }

    int COR_CALL tell() {
      return ftell(m_file);
    }

  private:
    FILE* m_file;
  };


  COR_EXPORT(File*) CorOpenFile(const char* filename, bool writeable) {
    FILE* file = fopen(filename, (writeable ? "wb" : "rb"));
    return (file ? new CFile(file) : 0);
  }

}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?