mm_io: Implement "read(size_t)" returning newly-allocated memory

This commit is contained in:
Moritz Bunkus 2012-12-22 19:32:26 +01:00
parent 7b8782022f
commit da3e2747b7
2 changed files with 10 additions and 0 deletions

View File

@ -265,6 +265,15 @@ mm_io_c::puts(const std::string &s) {
return num_written;
}
memory_cptr
mm_io_c::read(size_t size) {
auto buffer = memory_c::alloc(size);
if (read(buffer, size) != size)
throw mtx::mm_io::end_of_file_x{};
return buffer;
}
uint32_t
mm_io_c::read(void *buffer,
size_t size) {

View File

@ -43,6 +43,7 @@ public:
virtual uint64 getFilePointer() = 0;
virtual void setFilePointer(int64 offset, seek_mode mode = seek_beginning) = 0;
virtual bool setFilePointer2(int64 offset, seek_mode mode = seek_beginning);
virtual memory_cptr read(size_t size);
virtual uint32 read(void *buffer, size_t size);
virtual uint32_t read(std::string &buffer, size_t size, size_t offset = 0);
virtual uint32_t read(memory_cptr &buffer, size_t size, int offset = 0);