]> git.saurik.com Git - apt.git/commitdiff
simple_buffer: Allow buffer size to change
authorJulian Andres Klode <jak@debian.org>
Mon, 28 Dec 2015 14:04:57 +0000 (15:04 +0100)
committerJulian Andres Klode <jak@debian.org>
Sun, 3 Jan 2016 13:29:23 +0000 (14:29 +0100)
Gbp-Dch: ignore

apt-pkg/contrib/fileutl.cc

index 7f3ed673a13144e7563a7c8e136d57371c98415a..54af2536921fe1102cf4b834941d713ec43e30c4 100644 (file)
@@ -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
    {