summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org>2017-07-06 21:16:38 +0300
committerSergey Poznyakoff <gray@gnu.org>2017-07-06 21:27:54 +0300
commit90f38b62659a2673c02571ad0f3741ca1f524ad5 (patch)
tree426118b397f6375d3db5c9dca1e801747b741b4c
parentee8ede905a301f2fa1e85f47b4fd0f1cd087921f (diff)
downloadmailutils-90f38b62659a2673c02571ad0f3741ca1f524ad5.tar.gz
mailutils-90f38b62659a2673c02571ad0f3741ca1f524ad5.tar.bz2
Implement new opool function
* include/mailutils/opool.h (mu_opool_less): New function. * libmailutils/base/opool.c: Likewise.
-rw-r--r--include/mailutils/opool.h3
-rw-r--r--libmailutils/base/opool.c29
2 files changed, 32 insertions, 0 deletions
diff --git a/include/mailutils/opool.h b/include/mailutils/opool.h
index 5c50e8754..9aebd900b 100644
--- a/include/mailutils/opool.h
+++ b/include/mailutils/opool.h
@@ -63,6 +63,9 @@ int mu_opool_union (mu_opool_t *dst, mu_opool_t *src);
begin a new object. */
void mu_opool_clear (mu_opool_t opool);
+/* Reset the length of the current object to SIZE bytes */
+void mu_opool_less (mu_opool_t opool, size_t size);
+
/* Free object OBJ from the pool. If OBJ is NULL, free all created objects,
including the one being built */
void mu_opool_free (mu_opool_t pool, void *obj);
diff --git a/libmailutils/base/opool.c b/libmailutils/base/opool.c
index d8a4d155a..30c019bab 100644
--- a/libmailutils/base/opool.c
+++ b/libmailutils/base/opool.c
@@ -182,6 +182,35 @@ mu_opool_clear (mu_opool_t opool)
}
void
+mu_opool_less (mu_opool_t opool, size_t sz)
+{
+ union mu_opool_bucket *p;
+ size_t total = 0;
+
+ if (!opool)
+ return;
+ for (p = opool->bkt_head; p; p = p->hdr.next)
+ {
+ if (total + p->hdr.level >= sz)
+ {
+ union mu_opool_bucket *t;
+ p->hdr.level = sz - total;
+ t = p->hdr.next;
+ p->hdr.next = NULL;
+
+ while (t)
+ {
+ union mu_opool_bucket *next = t->hdr.next;
+ free (t);
+ t = next;
+ }
+ break;
+ }
+ total += p->hdr.level;
+ }
+}
+
+void
mu_opool_destroy (mu_opool_t *popool)
{
union mu_opool_bucket *p;

Return to:

Send suggestions and report system problems to the System administrator.