Add a threading framework
[apps/pfixtools.git] / mem.h
diff --git a/mem.h b/mem.h
index cc171a7..44630ef 100644 (file)
--- a/mem.h
+++ b/mem.h
@@ -1,5 +1,5 @@
 /******************************************************************************/
-/*          postlicyd: a postfix policy daemon with a lot of features         */
+/*          pfixtools: a collection of postfix related tools                  */
 /*          ~~~~~~~~~                                                         */
 /*  ________________________________________________________________________  */
 /*                                                                            */
@@ -33,8 +33,8 @@
  * Copyright © 2006 Pierre Habouzit
  */
 
-#ifndef POSTLICYD_MEM_H
-#define POSTLICYD_MEM_H
+#ifndef PFIXTOOLS_MEM_H
+#define PFIXTOOLS_MEM_H
 
 #include <assert.h>
 #include <ctype.h>
 #define p_dupstr(p, len)        xmemdupstr((p), (len))
 #define p_realloc(pp, count)    xrealloc((void*)(pp), sizeof(**(pp)) * (count))
 
+#  define p_alloc_nr(x) (((x) + 16) * 3 / 2)
+#  define p_allocgrow(pp, goalnb, allocnb)                  \
+    do {                                                    \
+        if ((goalnb) > *(allocnb)) {                        \
+            if (p_alloc_nr(goalnb) > *(allocnb)) {          \
+                *(allocnb) = (goalnb);                      \
+            } else {                                        \
+                *(allocnb) = p_alloc_nr(goalnb);            \
+            }                                               \
+            p_realloc(pp, *(allocnb));                      \
+        }                                                   \
+    } while (0)
+
 #ifdef __GNUC__
 
 #  define p_delete(mem_pp)                          \
@@ -131,4 +144,4 @@ static inline void *xmemdupstr(const void *src, ssize_t len) {
         }                                                   \
     }
 
-#endif /* POSTLICYD_MEM_H */
+#endif /* PFIXTOOLS_MEM_H */