aboutsummaryrefslogtreecommitdiffstats
path: root/libqpdf/Buffer.cc
diff options
context:
space:
mode:
authorJay Berkenbilt <ejb@ql.org>2010-10-01 12:20:38 +0200
committerJay Berkenbilt <ejb@ql.org>2010-10-01 12:20:38 +0200
commit9f444ffef3c11201d0a460b14b6234d3319ce861 (patch)
treee9d89e8e9bc440b0ea2df3963833158d6dfdf866 /libqpdf/Buffer.cc
parent359999a59cc1befdc94115d3cd17cb95a0ebdb49 (diff)
downloadqpdf-9f444ffef3c11201d0a460b14b6234d3319ce861.tar.zst
add QPDF::processMemoryFile and API additions to support it
git-svn-id: svn+q:///qpdf/trunk@1034 71b93d88-0707-0410-a8cf-f5a4172ac649
Diffstat (limited to 'libqpdf/Buffer.cc')
-rw-r--r--libqpdf/Buffer.cc30
1 files changed, 23 insertions, 7 deletions
diff --git a/libqpdf/Buffer.cc b/libqpdf/Buffer.cc
index 0c2dd958..71e219a1 100644
--- a/libqpdf/Buffer.cc
+++ b/libqpdf/Buffer.cc
@@ -4,17 +4,22 @@
Buffer::Buffer()
{
- init(0);
+ init(0, 0, true);
}
Buffer::Buffer(unsigned long size)
{
- init(size);
+ init(size, 0, true);
+}
+
+Buffer::Buffer(unsigned char* buf, unsigned long size)
+{
+ init(size, buf, false);
}
Buffer::Buffer(Buffer const& rhs)
{
- init(0);
+ init(0, 0, true);
copy(rhs);
}
@@ -31,10 +36,18 @@ Buffer::~Buffer()
}
void
-Buffer::init(unsigned long size)
+Buffer::init(unsigned long size, unsigned char* buf, bool own_memory)
{
+ this->own_memory = own_memory;
this->size = size;
- this->buf = (size ? new unsigned char[size] : 0);
+ if (own_memory)
+ {
+ this->buf = (size ? new unsigned char[size] : 0);
+ }
+ else
+ {
+ this->buf = buf;
+ }
}
void
@@ -43,7 +56,7 @@ Buffer::copy(Buffer const& rhs)
if (this != &rhs)
{
this->destroy();
- this->init(rhs.size);
+ this->init(rhs.size, 0, true);
if (this->size)
{
memcpy(this->buf, rhs.buf, this->size);
@@ -54,7 +67,10 @@ Buffer::copy(Buffer const& rhs)
void
Buffer::destroy()
{
- delete [] this->buf;
+ if (this->own_memory)
+ {
+ delete [] this->buf;
+ }
this->size = 0;
this->buf = 0;
}