From fee7489ee4c90c6dbd11e57ecc8e888c8f038716 Mon Sep 17 00:00:00 2001 From: Jay Berkenbilt Date: Fri, 17 Dec 2021 07:33:42 -0500 Subject: Add Pl_Buffer::getMallocBuffer --- libqpdf/Pl_Buffer.cc | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'libqpdf/Pl_Buffer.cc') 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 #include #include +#include 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(malloc(this->m->total_size)); + memcpy(*buf, this->m->data->getBuffer(), this->m->total_size); + } + else + { + *buf = nullptr; + } + this->m = new Members(); +} -- cgit v1.2.3-54-g00ecf