This is an automated email from the git hooks/post-receive script. guillem pushed a commit to branch master in repository dpkg.
commit ac3134292ecb5ea5f203c3fa1376cbc093d35518 Author: Guillem Jover <guil...@debian.org> Date: Fri Mar 16 04:17:16 2018 +0100 libdpkg: Add new str_concat() function --- lib/dpkg/libdpkg.map | 1 + lib/dpkg/string.c | 19 +++++++++++++++++++ lib/dpkg/string.h | 1 + lib/dpkg/t/t-string.c | 34 +++++++++++++++++++++++++++++++++- 4 files changed, 54 insertions(+), 1 deletion(-) diff --git a/lib/dpkg/libdpkg.map b/lib/dpkg/libdpkg.map index 5e685c9..85b8a1f 100644 --- a/lib/dpkg/libdpkg.map +++ b/lib/dpkg/libdpkg.map @@ -90,6 +90,7 @@ LIBDPKG_PRIVATE { str_match_end; str_fnv_hash; + str_concat; str_fmt; str_escape_fmt; str_strip_quotes; diff --git a/lib/dpkg/string.c b/lib/dpkg/string.c index 220e278..ff97159 100644 --- a/lib/dpkg/string.c +++ b/lib/dpkg/string.c @@ -28,6 +28,25 @@ #include <dpkg/string.h> #include <dpkg/dpkg.h> +char * +str_concat(char *dst, ...) +{ + va_list args; + const char *src; + size_t len; + + va_start(args, dst); + while ((src = va_arg(args, const char *))) { + len = strlen(src); + memcpy(dst, src, len); + dst += len; + } + va_end(args); + *dst = '\0'; + + return dst; +} + /** * Match the end of a string. * diff --git a/lib/dpkg/string.h b/lib/dpkg/string.h index 927aeae..d0f6bd7 100644 --- a/lib/dpkg/string.h +++ b/lib/dpkg/string.h @@ -56,6 +56,7 @@ bool str_match_end(const char *str, const char *end); unsigned int str_fnv_hash(const char *str); +char *str_concat(char *dst, ...) DPKG_ATTR_SENTINEL; char *str_fmt(const char *fmt, ...) DPKG_ATTR_PRINTF(1); char *str_escape_fmt(char *dest, const char *src, size_t n); char *str_quote_meta(const char *src); diff --git a/lib/dpkg/t/t-string.c b/lib/dpkg/t/t-string.c index 038de84..1f5ee4c 100644 --- a/lib/dpkg/t/t-string.c +++ b/lib/dpkg/t/t-string.c @@ -77,6 +77,37 @@ test_str_fnv_hash(void) } static void +test_str_concat(void) +{ + char buf[1024], *str; + + memset(buf, 0, sizeof(buf)); + str = str_concat(buf, NULL); + test_pass(str == buf); + test_str(buf, ==, ""); + + memset(buf, 0, sizeof(buf)); + str = str_concat(buf, "aaa", NULL); + test_str(buf, ==, "aaa"); + test_pass(str == buf + 3); + + memset(buf, 0, sizeof(buf)); + str = str_concat(buf, "zzzz", "yy", "xxxx", NULL); + test_str(buf, ==, "zzzzyyxxxx"); + test_pass(str == buf + 10); + + memset(buf, 0, sizeof(buf)); + str = str_concat(buf, "1234", "", "5678", NULL); + test_str(buf, ==, "12345678"); + test_pass(str == buf + 8); + + memset(buf, ' ', sizeof(buf)); + str = str_concat(buf, "eol", NULL, "bom", NULL); + test_str(buf, ==, "eol"); + test_pass(str == buf + 3); +} + +static void test_str_fmt(void) { char *str; @@ -197,11 +228,12 @@ test_str_strip_quotes(void) TEST_ENTRY(test) { - test_plan(50); + test_plan(60); test_str_is_set(); test_str_match_end(); test_str_fnv_hash(); + test_str_concat(); test_str_fmt(); test_str_escape_fmt(); test_str_quote_meta(); -- Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/dpkg/dpkg.git