This is an automated email from the git hooks/post-receive script. guillem pushed a commit to branch master in repository dpkg.
View the commit online: https://git.dpkg.org/cgit/dpkg/dpkg.git/commit/?id=2edd9981db1f572588b2493f81d67915183865e8 commit 2edd9981db1f572588b2493f81d67915183865e8 Author: Guillem Jover <guil...@debian.org> AuthorDate: Sun Jun 17 20:34:19 2018 +0200 libdpkg: Add new varbuf_new() and varbuf_free() functions --- debian/changelog | 1 + lib/dpkg/libdpkg.map | 2 ++ lib/dpkg/t/t-varbuf.c | 23 ++++++++++++++++++++++- lib/dpkg/varbuf.c | 18 ++++++++++++++++++ lib/dpkg/varbuf.h | 2 ++ 5 files changed, 45 insertions(+), 1 deletion(-) diff --git a/debian/changelog b/debian/changelog index b61741174..4d0f1d143 100644 --- a/debian/changelog +++ b/debian/changelog @@ -194,6 +194,7 @@ dpkg (1.19.1) UNRELEASED; urgency=medium - libdpkg: Split push_cleanup() into push_cleanup_fallback(). - Switch from strchr() + strlen() to strchrnul(). - libdpkg: Change dpkg_error to track errno values. + - libdpkg: Add new varbuf_new() and varbuf_free() functions. * Build system: - Set distribution tarball format to ustar, instead of default v7 format. - Mark PO4A and POD2MAN as precious variables. diff --git a/lib/dpkg/libdpkg.map b/lib/dpkg/libdpkg.map index cd0bd255d..20eccb72a 100644 --- a/lib/dpkg/libdpkg.map +++ b/lib/dpkg/libdpkg.map @@ -100,6 +100,7 @@ LIBDPKG_PRIVATE { str_gen_crop; # Variable buffer support + varbuf_new; varbuf_init; varbuf_reset; varbuf_grow; @@ -116,6 +117,7 @@ LIBDPKG_PRIVATE { varbuf_snapshot; varbuf_rollback; varbuf_destroy; + varbuf_free; # Path, directory and file functions secure_unlink_statted; diff --git a/lib/dpkg/t/t-varbuf.c b/lib/dpkg/t/t-varbuf.c index 585251993..8df733b9b 100644 --- a/lib/dpkg/t/t-varbuf.c +++ b/lib/dpkg/t/t-varbuf.c @@ -60,6 +60,26 @@ test_varbuf_prealloc(void) } static void +test_varbuf_new(void) +{ + struct varbuf *vb; + + vb = varbuf_new(0); + test_pass(vb != NULL); + test_pass(vb->used == 0); + test_pass(vb->size == 0); + test_pass(vb->buf == NULL); + varbuf_free(vb); + + vb = varbuf_new(10); + test_pass(vb != NULL); + test_pass(vb->used == 0); + test_pass(vb->size >= 10); + test_pass(vb->buf != NULL); + varbuf_free(vb); +} + +static void test_varbuf_grow(void) { struct varbuf vb; @@ -350,10 +370,11 @@ test_varbuf_detach(void) TEST_ENTRY(test) { - test_plan(120); + test_plan(128); test_varbuf_init(); test_varbuf_prealloc(); + test_varbuf_new(); test_varbuf_grow(); test_varbuf_trunc(); test_varbuf_add_buf(); diff --git a/lib/dpkg/varbuf.c b/lib/dpkg/varbuf.c index 9a62f92e9..ee757bcc7 100644 --- a/lib/dpkg/varbuf.c +++ b/lib/dpkg/varbuf.c @@ -115,6 +115,17 @@ varbuf_get_str(struct varbuf *v) return v->buf; } +struct varbuf * +varbuf_new(size_t size) +{ + struct varbuf *v; + + v = m_malloc(sizeof(*v)); + varbuf_init(v, size); + + return v; +} + void varbuf_init(struct varbuf *v, size_t size) { @@ -186,3 +197,10 @@ varbuf_destroy(struct varbuf *v) { free(v->buf); v->buf=NULL; v->size=0; v->used=0; } + +void +varbuf_free(struct varbuf *v) +{ + free(v->buf); + free(v); +} diff --git a/lib/dpkg/varbuf.h b/lib/dpkg/varbuf.h index 9b9a30f95..06f09f5e8 100644 --- a/lib/dpkg/varbuf.h +++ b/lib/dpkg/varbuf.h @@ -72,12 +72,14 @@ struct varbuf { #define VARBUF_INIT { 0, 0, NULL } +struct varbuf *varbuf_new(size_t size); void varbuf_init(struct varbuf *v, size_t size); void varbuf_grow(struct varbuf *v, size_t need_size); void varbuf_trunc(struct varbuf *v, size_t used_size); char *varbuf_detach(struct varbuf *v); void varbuf_reset(struct varbuf *v); void varbuf_destroy(struct varbuf *v); +void varbuf_free(struct varbuf *v); void varbuf_add_char(struct varbuf *v, int c); void varbuf_dup_char(struct varbuf *v, int c, size_t n); -- Dpkg.Org's dpkg