[Reproducible-commits] [dpkg] 17/32: libdpkg: Add new varbuf_get_str()

Jérémy Bobbio lunar at moszumanska.debian.org
Fri Nov 6 14:02:18 UTC 2015


This is an automated email from the git hooks/post-receive script.

lunar pushed a commit to branch pu/reproducible_builds
in repository dpkg.

commit e7a32556af38b5630412de406d2f0842150ff086
Author: Guillem Jover <guillem at debian.org>
Date:   Sat Oct 17 04:25:56 2015 +0200

    libdpkg: Add new varbuf_get_str()
---
 lib/dpkg/t/t-varbuf.c | 34 ++++++++++++++++++++++++++++++++--
 lib/dpkg/varbuf.c     | 10 +++++++++-
 lib/dpkg/varbuf.h     |  3 ++-
 3 files changed, 43 insertions(+), 4 deletions(-)

diff --git a/lib/dpkg/t/t-varbuf.c b/lib/dpkg/t/t-varbuf.c
index b556c7a..7757eb7 100644
--- a/lib/dpkg/t/t-varbuf.c
+++ b/lib/dpkg/t/t-varbuf.c
@@ -2,7 +2,7 @@
  * libdpkg - Debian packaging suite library routines
  * t-verbuf.c - test varbuf implementation
  *
- * Copyright © 2009-2011 Guillem Jover <guillem at debian.org>
+ * Copyright © 2009-2011, 2013-2015 Guillem Jover <guillem at debian.org>
  *
  * This is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -223,6 +223,35 @@ test_varbuf_end_str(void)
 }
 
 static void
+test_varbuf_get_str(void)
+{
+	struct varbuf vb;
+	const char *str;
+
+	varbuf_init(&vb, 10);
+
+	varbuf_add_buf(&vb, "1234567890", 10);
+	str = varbuf_get_str(&vb);
+	test_pass(vb.buf == str);
+	test_pass(vb.used == 10);
+	test_pass(vb.buf[vb.used] == '\0');
+	test_pass(str[vb.used] == '\0');
+	test_str(vb.buf, ==, "1234567890");
+	test_str(str, ==, "1234567890");
+
+	varbuf_add_buf(&vb, "abcde", 5);
+	str = varbuf_get_str(&vb);
+	test_pass(vb.buf == str);
+	test_pass(vb.used == 15);
+	test_pass(vb.buf[vb.used] == '\0');
+	test_pass(str[vb.used] == '\0');
+	test_str(vb.buf, ==, "1234567890abcde");
+	test_str(str, ==, "1234567890abcde");
+
+	varbuf_destroy(&vb);
+}
+
+static void
 test_varbuf_printf(void)
 {
 	struct varbuf vb;
@@ -322,7 +351,7 @@ test_varbuf_detach(void)
 static void
 test(void)
 {
-	test_plan(108);
+	test_plan(120);
 
 	test_varbuf_init();
 	test_varbuf_prealloc();
@@ -333,6 +362,7 @@ test(void)
 	test_varbuf_dup_char();
 	test_varbuf_map_char();
 	test_varbuf_end_str();
+	test_varbuf_get_str();
 	test_varbuf_printf();
 	test_varbuf_reset();
 	test_varbuf_snapshot();
diff --git a/lib/dpkg/varbuf.c b/lib/dpkg/varbuf.c
index 7791e76..9a62f92 100644
--- a/lib/dpkg/varbuf.c
+++ b/lib/dpkg/varbuf.c
@@ -3,7 +3,7 @@
  * varbuf.c - variable length expandable buffer handling
  *
  * Copyright © 1994,1995 Ian Jackson <ijackson at chiark.greenend.org.uk>
- * Copyright © 2008-2014 Guillem Jover <guillem at debian.org>
+ * Copyright © 2008-2015 Guillem Jover <guillem at debian.org>
  *
  * This is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -107,6 +107,14 @@ varbuf_end_str(struct varbuf *v)
   v->buf[v->used] = '\0';
 }
 
+const char *
+varbuf_get_str(struct varbuf *v)
+{
+  varbuf_end_str(v);
+
+  return v->buf;
+}
+
 void
 varbuf_init(struct varbuf *v, size_t size)
 {
diff --git a/lib/dpkg/varbuf.h b/lib/dpkg/varbuf.h
index 43f00bc..ebadf08 100644
--- a/lib/dpkg/varbuf.h
+++ b/lib/dpkg/varbuf.h
@@ -3,7 +3,7 @@
  * varbuf.h - variable length expandable buffer handling
  *
  * Copyright © 1994, 1995 Ian Jackson <ijackson at chiark.greenend.org.uk>
- * Copyright © 2008-2011 Guillem Jover <guillem at debian.org>
+ * Copyright © 2008-2015 Guillem Jover <guillem at debian.org>
  *
  * This is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -84,6 +84,7 @@ void varbuf_map_char(struct varbuf *v, int c_src, int c_dst);
 #define varbuf_add_str(v, s) varbuf_add_buf(v, s, strlen(s))
 void varbuf_add_buf(struct varbuf *v, const void *s, size_t size);
 void varbuf_end_str(struct varbuf *v);
+const char *varbuf_get_str(struct varbuf *v);
 
 int varbuf_printf(struct varbuf *v, const char *fmt, ...) DPKG_ATTR_PRINTF(2);
 int varbuf_vprintf(struct varbuf *v, const char *fmt, va_list va)

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/reproducible/dpkg.git



More information about the Reproducible-commits mailing list