diff options
author | Jay Berkenbilt <ejb@ql.org> | 2021-12-17 13:33:42 +0100 |
---|---|---|
committer | Jay Berkenbilt <ejb@ql.org> | 2021-12-17 18:38:52 +0100 |
commit | fee7489ee4c90c6dbd11e57ecc8e888c8f038716 (patch) | |
tree | 9a1872d7e52b2db3ec2cb44109a3a3918927621d /libqpdf/Pl_Buffer.cc | |
parent | 8c4ad6b946a762fd57443a3647e0cc620ad6eae4 (diff) | |
download | qpdf-fee7489ee4c90c6dbd11e57ecc8e888c8f038716.tar.zst |
Add Pl_Buffer::getMallocBuffer
Diffstat (limited to 'libqpdf/Pl_Buffer.cc')
-rw-r--r-- | libqpdf/Pl_Buffer.cc | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/libqpdf/Pl_Buffer.cc b/libqpdf/Pl_Buffer.cc index 70d906ea..0743de75 100644 --- a/libqpdf/Pl_Buffer.cc +++ b/libqpdf/Pl_Buffer.cc @@ -3,6 +3,7 @@ #include <algorithm> #include <assert.h> #include <string.h> +#include <stdlib.h> Pl_Buffer::Members::Members() : ready(true), @@ -80,3 +81,25 @@ Pl_Buffer::getBuffer() this->m = new Members(); return b; } + +void +Pl_Buffer::getMallocBuffer(unsigned char **buf, size_t* len) +{ + if (! this->m->ready) + { + throw std::logic_error( + "Pl_Buffer::getMallocBuffer() called when not ready"); + } + + *len = this->m->total_size; + if (this->m->total_size > 0) + { + *buf = reinterpret_cast<unsigned char*>(malloc(this->m->total_size)); + memcpy(*buf, this->m->data->getBuffer(), this->m->total_size); + } + else + { + *buf = nullptr; + } + this->m = new Members(); +} |