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

guillem pushed a commit to branch main
in repository dpkg.

View the commit online:
https://git.dpkg.org/cgit/dpkg/dpkg.git/commit/?id=8f17d79ce7da7eb44a68db65ecd6c9d118c174e0

commit 8f17d79ce7da7eb44a68db65ecd6c9d118c174e0
Author: Guillem Jover <guil...@debian.org>
AuthorDate: Wed Sep 30 13:55:24 2009 +0200

    libdpkg: Add varbuf_add_strn()
---
 lib/dpkg/t/t-varbuf.c | 29 ++++++++++++++++++++++++++++-
 lib/dpkg/varbuf.h     |  1 +
 2 files changed, 29 insertions(+), 1 deletion(-)

diff --git a/lib/dpkg/t/t-varbuf.c b/lib/dpkg/t/t-varbuf.c
index da9dd9a9f..3329e8695 100644
--- a/lib/dpkg/t/t-varbuf.c
+++ b/lib/dpkg/t/t-varbuf.c
@@ -199,6 +199,32 @@ test_varbuf_add_buf(void)
        varbuf_destroy(&vb);
 }
 
+static void
+test_varbuf_add_str(void)
+{
+       struct varbuf vb;
+
+       varbuf_init(&vb, 5);
+
+       varbuf_add_str(&vb, "1234567890");
+       varbuf_end_str(&vb);
+       test_str(vb.buf, ==, "1234567890");
+
+       varbuf_add_str(&vb, "abcd");
+       varbuf_end_str(&vb);
+       test_str(vb.buf, ==, "1234567890abcd");
+
+       varbuf_add_strn(&vb, "1234567890", 5);
+       varbuf_end_str(&vb);
+       test_str(vb.buf, ==, "1234567890abcd12345");
+
+       varbuf_add_strn(&vb, "abcd", 0);
+       varbuf_end_str(&vb);
+       test_str(vb.buf, ==, "1234567890abcd12345");
+
+       varbuf_destroy(&vb);
+}
+
 static void
 test_varbuf_add_char(void)
 {
@@ -477,7 +503,7 @@ test_varbuf_detach(void)
 
 TEST_ENTRY(test)
 {
-       test_plan(158);
+       test_plan(162);
 
        test_varbuf_init();
        test_varbuf_prealloc();
@@ -486,6 +512,7 @@ TEST_ENTRY(test)
        test_varbuf_trunc();
        test_varbuf_add_varbuf();
        test_varbuf_add_buf();
+       test_varbuf_add_str();
        test_varbuf_add_char();
        test_varbuf_dup_char();
        test_varbuf_map_char();
diff --git a/lib/dpkg/varbuf.h b/lib/dpkg/varbuf.h
index 9b10bdc8b..3fd973e26 100644
--- a/lib/dpkg/varbuf.h
+++ b/lib/dpkg/varbuf.h
@@ -88,6 +88,7 @@ void varbuf_add_char(struct varbuf *v, int c);
 void varbuf_dup_char(struct varbuf *v, int c, size_t n);
 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))
+#define varbuf_add_strn(v, s, n) varbuf_add_buf(v, s, strnlen(s, n))
 void varbuf_add_dir(struct varbuf *v, const char *dirname);
 void varbuf_add_buf(struct varbuf *v, const void *s, size_t size);
 void varbuf_end_str(struct varbuf *v);

-- 
Dpkg.Org's dpkg

Reply via email to