| 111 | }; |
| 112 | |
| 113 | class CBytecodeFileStream : public asIBinaryStream |
| 114 | { |
| 115 | public: |
| 116 | CBytecodeFileStream(const char *name) { this->name = name; f = 0; isReading = false; position = 0; } |
| 117 | ~CBytecodeFileStream() { if (f) fclose(f); } |
| 118 | |
| 119 | int Write(const void *ptr, asUINT size) |
| 120 | { |
| 121 | if (size == 0) return 0; |
| 122 | if (f == 0 || isReading) |
| 123 | { |
| 124 | if (f) |
| 125 | fclose(f); |
| 126 | #ifdef _MSC_VER |
| 127 | fopen_s(&f, name.c_str(), "wb"); |
| 128 | #else |
| 129 | f = fopen(name.c_str(), "wb"); |
| 130 | #endif |
| 131 | isReading = false; |
| 132 | } |
| 133 | size_t r = fwrite(ptr, size, 1, f); |
| 134 | fflush(f); |
| 135 | position += size; |
| 136 | if (r != 1) |
| 137 | return -1; |
| 138 | return 0; |
| 139 | } |
| 140 | int Read(void *ptr, asUINT size) |
| 141 | { |
| 142 | if (size == 0) return 0; |
| 143 | if (f == 0 || !isReading) |
| 144 | { |
| 145 | if (f) |
| 146 | fclose(f); |
| 147 | #ifdef _MSC_VER |
| 148 | fopen_s(&f, name.c_str(), "rb"); |
| 149 | #else |
| 150 | f = fopen(name.c_str(), "rb"); |
| 151 | #endif |
| 152 | isReading = true; |
| 153 | } |
| 154 | size_t r = fread(ptr, size, 1, f); |
| 155 | position += size; |
| 156 | if (r != 1) |
| 157 | return -1; |
| 158 | return 0; |
| 159 | } |
| 160 | void Restart() { if (f) { fclose(f); f = 0; } position = 0; } |
| 161 | |
| 162 | protected: |
| 163 | std::string name; |
| 164 | FILE *f; |
| 165 | bool isReading; |
| 166 | asDWORD position; |
| 167 | }; |
| 168 | |
| 169 | class CBytecodeStream : public asIBinaryStream |
| 170 | { |
nothing calls this directly
no outgoing calls
no test coverage detected