From e3915fb5da8fa3421981a9ad9f0fb852842ae8cc Mon Sep 17 00:00:00 2001 From: Moritz Bunkus Date: Sat, 31 Jul 2004 23:37:12 +0000 Subject: [PATCH] More comfort functions: read data into a string object. --- src/common/mm_io.cpp | 17 +++++++++++++++++ src/common/mm_io.h | 1 + 2 files changed, 18 insertions(+) diff --git a/src/common/mm_io.cpp b/src/common/mm_io.cpp index ceb8cf4b4..7178c8fad 100644 --- a/src/common/mm_io.cpp +++ b/src/common/mm_io.cpp @@ -361,6 +361,23 @@ mm_io_c::puts_unl(const char *s) { return bytes_written; } +uint32_t +mm_io_c::read(string &buffer, + size_t size) { + char cbuffer[size + 1]; + int nread; + + nread = read(buffer, size); + if (nread < 0) + buffer = ""; + else { + cbuffer[nread] = 0; + buffer = cbuffer; + } + + return nread; +} + unsigned char mm_io_c::read_uint8() { unsigned char value; diff --git a/src/common/mm_io.h b/src/common/mm_io.h index a5b8c11b2..90a454ed0 100644 --- a/src/common/mm_io.h +++ b/src/common/mm_io.h @@ -45,6 +45,7 @@ public: virtual void setFilePointer(int64 offset, seek_mode mode = seek_beginning); virtual bool setFilePointer2(int64 offset, seek_mode mode = seek_beginning); virtual uint32 read(void *buffer, size_t size); + virtual uint32_t read(string &buffer, size_t size); virtual unsigned char read_uint8(); virtual uint16_t read_uint16(); virtual uint32_t read_uint24();