diff options
author | Julian Andres Klode <jak@debian.org> | 2015-12-28 15:04:57 +0100 |
---|---|---|
committer | Julian Andres Klode <jak@debian.org> | 2016-01-03 14:29:23 +0100 |
commit | 5bdba2ca232b1f49165fbfcff8341b0887076a34 (patch) | |
tree | e752409702d960db7f3ad2315480f9acc06d533e /apt-pkg/contrib | |
parent | 2c80abf922e948f8c96537faf1fa36cccd80e8d9 (diff) |
simple_buffer: Allow buffer size to change
Gbp-Dch: ignore
Diffstat (limited to 'apt-pkg/contrib')
-rw-r--r-- | apt-pkg/contrib/fileutl.cc | 20 |
1 files changed, 18 insertions, 2 deletions
diff --git a/apt-pkg/contrib/fileutl.cc b/apt-pkg/contrib/fileutl.cc index 7f3ed673a..54af25369 100644 --- a/apt-pkg/contrib/fileutl.cc +++ b/apt-pkg/contrib/fileutl.cc @@ -920,16 +920,32 @@ bool ChangeOwnerAndPermissionOfFile(char const * const requester, char const * c /*}}}*/ struct APT_HIDDEN simple_buffer { /*{{{*/ - static constexpr size_t buffersize_max = 4096; + size_t buffersize_max = 0; unsigned long long bufferstart = 0; unsigned long long bufferend = 0; - char buffer[buffersize_max]; + char *buffer = nullptr; + + simple_buffer() { + reset(4096); + } + ~simple_buffer() { + delete buffer; + } const char *get() const { return buffer + bufferstart; } char *get() { return buffer + bufferstart; } bool empty() const { return bufferend <= bufferstart; } bool full() const { return bufferend == buffersize_max; } unsigned long long size() const { return bufferend-bufferstart; } + void reset(size_t size) + { + if (size > buffersize_max) { + delete[] buffer; + buffersize_max = size; + buffer = new char[size]; + } + reset(); + } void reset() { bufferend = bufferstart = 0; } ssize_t read(void *to, unsigned long long requested_size) APT_MUSTCHECK { |