From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 10164 invoked by alias); 28 Sep 2017 19:50:20 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Received: (qmail 10118 invoked by uid 89); 28 Sep 2017 19:50:20 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-24.3 required=5.0 tests=AWL,BAYES_00,GIT_PATCH_0,GIT_PATCH_1,GIT_PATCH_2,GIT_PATCH_3,RCVD_IN_DNSWL_NONE,RCVD_IN_SORBS_SPAM,SPF_PASS autolearn=ham version=3.3.2 spammy=Hx-languages-length:1792 X-HELO: gproxy5-pub.mail.unifiedlayer.com Received: from gproxy5-pub.mail.unifiedlayer.com (HELO gproxy5-pub.mail.unifiedlayer.com) (67.222.38.55) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 28 Sep 2017 19:50:18 +0000 Received: from cmgw3 (unknown [10.0.90.84]) by gproxy5.mail.unifiedlayer.com (Postfix) with ESMTP id 233E41406EC for ; Thu, 28 Sep 2017 13:50:17 -0600 (MDT) Received: from box522.bluehost.com ([74.220.219.122]) by cmgw3 with id F7qD1w0282f2jeq017qGHt; Thu, 28 Sep 2017 13:50:17 -0600 X-Authority-Analysis: v=2.2 cv=K/VSJ2eI c=1 sm=1 tr=0 a=GsOEXm/OWkKvwdLVJsfwcA==:117 a=GsOEXm/OWkKvwdLVJsfwcA==:17 a=2JCJgTwv5E4A:10 a=zstS-IiYAAAA:8 a=vua6dwllI2bTI0ljDx8A:9 a=4G6NA9xxw8l3yy4pmD5M:22 Received: from 75-166-0-208.hlrn.qwest.net ([75.166.0.208]:56208 helo=bapiya.Home) by box522.bluehost.com with esmtpsa (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.87) (envelope-from ) id 1dxep3-003LpU-O3; Thu, 28 Sep 2017 13:50:13 -0600 From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [RFA 01/12] Introduce string_vprintf Date: Thu, 28 Sep 2017 19:50:00 -0000 Message-Id: <20170928195011.27382-2-tom@tromey.com> In-Reply-To: <20170928195011.27382-1-tom@tromey.com> References: <20170928195011.27382-1-tom@tromey.com> X-BWhitelist: no X-Exim-ID: 1dxep3-003LpU-O3 X-Source-Sender: 75-166-0-208.hlrn.qwest.net (bapiya.Home) [75.166.0.208]:56208 X-Source-Auth: tom+tromey.com X-Email-Count: 2 X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTIyLmJsdWVob3N0LmNvbQ== X-Local-Domain: yes X-SW-Source: 2017-09/txt/msg00871.txt.bz2 This adds string_vprintf, a va_list variant of string_printf. This will be used in later patches. gdb/ChangeLog 2017-09-28 Tom Tromey * common/common-utils.c (string_vprintf): New function. * common/common-utils.h (string_vprintf): Declare. --- gdb/ChangeLog | 5 +++++ gdb/common/common-utils.c | 21 +++++++++++++++++++++ gdb/common/common-utils.h | 4 ++++ 3 files changed, 30 insertions(+) diff --git a/gdb/common/common-utils.c b/gdb/common/common-utils.c index 6b10d11..d8c546a 100644 --- a/gdb/common/common-utils.c +++ b/gdb/common/common-utils.c @@ -174,6 +174,27 @@ string_printf (const char* fmt, ...) return str; } +/* See documentation in common-utils.h. */ + +std::string +string_vprintf (const char* fmt, va_list args) +{ + va_list vp; + size_t size; + + va_copy (vp, args); + size = vsnprintf (NULL, 0, fmt, vp); + va_end (vp); + + std::string str (size, '\0'); + + /* C++11 and later guarantee std::string uses contiguous memory and + always includes the terminating '\0'. */ + vsprintf (&str[0], fmt, args); + + return str; +} + char * savestring (const char *ptr, size_t len) { diff --git a/gdb/common/common-utils.h b/gdb/common/common-utils.h index 6475c28..19724f9 100644 --- a/gdb/common/common-utils.h +++ b/gdb/common/common-utils.h @@ -63,6 +63,10 @@ int xsnprintf (char *str, size_t size, const char *format, ...) std::string string_printf (const char* fmt, ...) ATTRIBUTE_PRINTF (1, 2); +/* Like string_printf, but takes a va_list. */ +std::string string_vprintf (const char* fmt, va_list args) + ATTRIBUTE_PRINTF (1, 0); + /* Make a copy of the string at PTR with LEN characters (and add a null character at the end in the copy). Uses malloc to get the space. Returns the address of the copy. */ -- 2.9.5