chiark / gitweb /
bus: parse matches locally and allow registration of callbacks for them
[elogind.git] / src / shared / util.c
index 873c95820ae09aad32f10b1b7a8d2e9ee8bfd339..760013c1fb5b95128391e140845389e61436dc8e 100644 (file)
@@ -5855,3 +5855,20 @@ char *strrep(const char *s, unsigned n) {
         *p = 0;
         return r;
 }
+
+void* greedy_realloc(void **p, size_t *allocated, size_t need) {
+        size_t a;
+        void *q;
+
+        if (*allocated >= need)
+                return *p;
+
+        a = MAX(64, need * 2);
+        q = realloc(*p, a);
+        if (!q)
+                return NULL;
+
+        *p = q;
+        *allocated = a;
+        return q;
+}