summaryrefslogtreecommitdiff
path: root/src/ByteArrayDiskWriter.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/ByteArrayDiskWriter.cc')
-rw-r--r--src/ByteArrayDiskWriter.cc14
1 files changed, 11 insertions, 3 deletions
diff --git a/src/ByteArrayDiskWriter.cc b/src/ByteArrayDiskWriter.cc
index 011ed25b..dbe22cc3 100644
--- a/src/ByteArrayDiskWriter.cc
+++ b/src/ByteArrayDiskWriter.cc
@@ -66,9 +66,10 @@ void ByteArrayDiskWriter::openExistingFile(const std::string& filename,
void ByteArrayDiskWriter::writeData(const unsigned char* data, size_t dataLength, off_t position)
{
- if(size() < (uint64_t)position) {
- buf.seekp(size(), std::ios::beg);
- for(uint64_t i = size(); i < (uint64_t)position; ++i) {
+ uint64_t length = size();
+ if(length < (uint64_t)position) {
+ buf.seekp(length, std::ios::beg);
+ for(uint64_t i = length; i < (uint64_t)position; ++i) {
buf.put('\0');
}
} else {
@@ -85,4 +86,11 @@ ssize_t ByteArrayDiskWriter::readData(unsigned char* data, size_t len, off_t pos
return buf.gcount();
}
+uint64_t ByteArrayDiskWriter::size()
+{
+ buf.seekg(0, std::ios::end);
+ buf.clear();
+ return buf.tellg();
+}
+
} // namespace aria2