summaryrefslogtreecommitdiff
path: root/tools.c
diff options
context:
space:
mode:
Diffstat (limited to 'tools.c')
-rw-r--r--tools.c40
1 files changed, 39 insertions, 1 deletions
diff --git a/tools.c b/tools.c
index adfff1c3..754673db 100644
--- a/tools.c
+++ b/tools.c
@@ -4,7 +4,7 @@
* See the main source file 'vdr.c' for copyright information and
* how to reach the author.
*
- * $Id: tools.c 4.4 2015/09/10 13:17:55 kls Exp $
+ * $Id: tools.c 4.5 2016/12/23 14:03:40 kls Exp $
*/
#include "tools.h"
@@ -2272,6 +2272,44 @@ void cListBase::Sort(void)
free(a);
}
+// --- cDynamicBuffer --------------------------------------------------------
+
+cDynamicBuffer::cDynamicBuffer(int InitialSize)
+{
+ initialSize = InitialSize;
+ buffer = NULL;
+ size = used = 0;
+}
+
+cDynamicBuffer::~cDynamicBuffer()
+{
+ free(buffer);
+}
+
+bool cDynamicBuffer::Realloc(int NewSize)
+{
+ if (size < NewSize) {
+ NewSize = max(NewSize, size ? size * 3 / 2 : initialSize); // increase size by at least 50%
+ if (uchar *NewBuffer = (uchar *)realloc(buffer, NewSize)) {
+ buffer = NewBuffer;
+ size = NewSize;
+ }
+ else {
+ esyslog("ERROR: out of memory");
+ return false;
+ }
+ }
+ return true;
+}
+
+void cDynamicBuffer::Append(const uchar *Data, int Length)
+{
+ if (Assert(used + Length)) {
+ memcpy(buffer + used, Data, Length);
+ used += Length;
+ }
+}
+
// --- cHashBase -------------------------------------------------------------
cHashBase::cHashBase(int Size)