From patchwork Thu Nov 22 23:05:22 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul-Sebastian Ungureanu X-Patchwork-Id: 10694927 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 8C1601926 for ; Thu, 22 Nov 2018 23:06:29 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7C4272C1A6 for ; Thu, 22 Nov 2018 23:06:29 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6ECF62C1D6; Thu, 22 Nov 2018 23:06:29 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id F30792C1A6 for ; Thu, 22 Nov 2018 23:06:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2438942AbeKWJry (ORCPT ); Fri, 23 Nov 2018 04:47:54 -0500 Received: from mail-wr1-f65.google.com ([209.85.221.65]:38424 "EHLO mail-wr1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2392523AbeKWJry (ORCPT ); Fri, 23 Nov 2018 04:47:54 -0500 Received: by mail-wr1-f65.google.com with SMTP id v13so7167726wrw.5 for ; Thu, 22 Nov 2018 15:06:14 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Rjnnj9TRwqeyN5UUhaUTnY9uBMV8NNt3+VQkPm2ty4w=; b=czxhzeZhJZWkk/kbMzKFkueZ+hL13UuJ2m4Y0Ew0I2J/QzCVeUsm/8ijrPO1Z8JdnT ixC9aZoOWp1uF4OCnwcpWvI4+KBqllWSCK060BKHLvvZKihcw2wBNhn3TGQg1MZXx+u1 H77037zpjXotcf8iXGmf+XTKyS2tSv4GP6JmvHtLlXUc5s1zVCmRUkSFkDPRD+eZpF4L 8mlLdFOV4dvFGMDUkXPt09f2Sz5b56E/SsFDyqO0AhCgmpMlXnp220lFIHAXtFy188pr DhxprI8WSMwJdqRRitaw1gz7g+LOAVeSKVGRujbdydQ3Do4Qb9c5+oTswjZQda5Ka0KN 5dpw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Rjnnj9TRwqeyN5UUhaUTnY9uBMV8NNt3+VQkPm2ty4w=; b=ubn4Bl51fk7I+tA/cjYX80cygx5nMhiMMLd4LYi26wQaLZY3ftVPVE7CJeKtdpZEaV i1OEN827UWTAIBjNtdnOMN79HCFY98y1Rjwk8clsMqHYwPZ87BU/MgFBznLCcFwEhwM7 YR9Ai3tXj7506XJBaOA2H1dQlru8WjLjxLh3MLaAIIungidRNgfJNqA4PatNAN4fRmzH rZqcDhplqA56PgWhH8NgTvMdN5rbASFUq1Iex2a4qsSTWYFAOuNGhD4cJv8LyvxzMURg 98mqUn9mD/TqFOrXz2TDz4Oud7LbLF4O/hR+5CldgJim433f/UPQBGC3EIuA7TiFSjwM xcrg== X-Gm-Message-State: AA+aEWb8C+OdDG/hqpmGUHnHkDR8oueYMwD878CUJXpwcfBmLNzyDYI5 XRHgHf4jCOHxomy1MRR4IIZMNbC2 X-Google-Smtp-Source: AFSGD/X3TKSAgHAe24LIPLsGOlr4iX9IyYcaFhKR2V4HbwymzI9R1NyecBLikKRhCbPWXoxAsNksgA== X-Received: by 2002:adf:ef0d:: with SMTP id e13mr11331541wro.29.1542927973371; Thu, 22 Nov 2018 15:06:13 -0800 (PST) Received: from localhost.localdomain ([91.250.255.197]) by smtp.gmail.com with ESMTPSA id v5sm11099670wrr.11.2018.11.22.15.06.12 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 22 Nov 2018 15:06:12 -0800 (PST) From: Paul-Sebastian Ungureanu To: git@vger.kernel.org Cc: t.gummerer@gmail.com Subject: [PATCH v11 02/22] strbuf.c: add `strbuf_join_argv()` Date: Fri, 23 Nov 2018 01:05:22 +0200 Message-Id: X-Mailer: git-send-email 2.19.1.878.g0482332a22 In-Reply-To: References: MIME-Version: 1.0 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Implement `strbuf_join_argv()` to join arguments into a strbuf. Signed-off-by: Paul-Sebastian Ungureanu --- strbuf.c | 15 +++++++++++++++ strbuf.h | 7 +++++++ 2 files changed, 22 insertions(+) diff --git a/strbuf.c b/strbuf.c index f6a6cf78b9..82e90f1dfe 100644 --- a/strbuf.c +++ b/strbuf.c @@ -268,6 +268,21 @@ void strbuf_addbuf(struct strbuf *sb, const struct strbuf *sb2) strbuf_setlen(sb, sb->len + sb2->len); } +const char *strbuf_join_argv(struct strbuf *buf, + int argc, const char **argv, char delim) +{ + if (!argc) + return buf->buf; + + strbuf_addstr(buf, *argv); + while (--argc) { + strbuf_addch(buf, delim); + strbuf_addstr(buf, *(++argv)); + } + + return buf->buf; +} + void strbuf_addchars(struct strbuf *sb, int c, size_t n) { strbuf_grow(sb, n); diff --git a/strbuf.h b/strbuf.h index fc40873b65..be02150df3 100644 --- a/strbuf.h +++ b/strbuf.h @@ -288,6 +288,13 @@ static inline void strbuf_addstr(struct strbuf *sb, const char *s) */ void strbuf_addbuf(struct strbuf *sb, const struct strbuf *sb2); +/** + * Join the arguments into a buffer. `delim` is put between every + * two arguments. + */ +const char *strbuf_join_argv(struct strbuf *buf, int argc, + const char **argv, char delim); + /** * This function can be used to expand a format string containing * placeholders. To that end, it parses the string and calls the specified