aboutsummaryrefslogtreecommitdiffstats
path: root/common/membuf.c
diff options
context:
space:
mode:
authorWerner Koch <[email protected]>2014-02-26 15:16:30 +0000
committerWerner Koch <[email protected]>2014-02-26 15:16:30 +0000
commit556562086acd2bc2f8e3aa3126ebf155715e042b (patch)
tree52db5f1beed87ee62b64b0e15d6b97c956fc9e5d /common/membuf.c
parentagent: Fixed unresolved symbol under Windows. (diff)
downloadgnupg-556562086acd2bc2f8e3aa3126ebf155715e042b.tar.gz
gnupg-556562086acd2bc2f8e3aa3126ebf155715e042b.zip
common: New function get_membuf_shrink.
* common/membuf.c (get_membuf_shrink): New.
Diffstat (limited to '')
-rw-r--r--common/membuf.c25
1 files changed, 25 insertions, 0 deletions
diff --git a/common/membuf.c b/common/membuf.c
index 02f1b2795..884c08cf3 100644
--- a/common/membuf.c
+++ b/common/membuf.c
@@ -170,6 +170,31 @@ get_membuf (membuf_t *mb, size_t *len)
}
+/* Same as get_membuf but shrinks the reallocated space to the
+ required size. */
+void *
+get_membuf_shrink (membuf_t *mb, size_t *len)
+{
+ void *p, *pp;
+ size_t dummylen;
+
+ if (!len)
+ len = &dummylen;
+
+ p = get_membuf (mb, &len);
+ if (!p)
+ return NULL;
+ if (len)
+ {
+ pp = xtryrealloc (p, len);
+ if (pp)
+ p = pp;
+ }
+
+ return p;
+}
+
+
/* Peek at the membuf MB. On success a pointer to the buffer is
returned which is valid until the next operation on MB. If LEN is
not NULL the current LEN of the buffer is stored there. On error