aboutsummaryrefslogtreecommitdiffstats
path: root/libqpdf/Pl_Buffer.cc
diff options
context:
space:
mode:
authorJay Berkenbilt <ejb@ql.org>2021-12-17 13:33:42 +0100
committerJay Berkenbilt <ejb@ql.org>2021-12-17 18:38:52 +0100
commitfee7489ee4c90c6dbd11e57ecc8e888c8f038716 (patch)
tree9a1872d7e52b2db3ec2cb44109a3a3918927621d /libqpdf/Pl_Buffer.cc
parent8c4ad6b946a762fd57443a3647e0cc620ad6eae4 (diff)
downloadqpdf-fee7489ee4c90c6dbd11e57ecc8e888c8f038716.tar.zst
Add Pl_Buffer::getMallocBuffer
Diffstat (limited to 'libqpdf/Pl_Buffer.cc')
-rw-r--r--libqpdf/Pl_Buffer.cc23
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();
+}