aboutsummaryrefslogtreecommitdiffstats
path: root/libqpdf/Pl_Buffer.cc
diff options
context:
space:
mode:
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();
+}