From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 20951 invoked by alias); 11 Nov 2013 06:38:02 -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 20909 invoked by uid 89); 11 Nov 2013 06:38:01 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-0.7 required=5.0 tests=AWL,BAYES_00,RDNS_NONE,SPF_PASS autolearn=no version=3.3.2 X-HELO: rock.gnat.com Received: from Unknown (HELO rock.gnat.com) (205.232.38.15) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-SHA encrypted) ESMTPS; Mon, 11 Nov 2013 06:38:00 +0000 Received: from localhost (localhost.localdomain [127.0.0.1]) by filtered-rock.gnat.com (Postfix) with ESMTP id E030A1164D7 for ; Mon, 11 Nov 2013 01:38:23 -0500 (EST) Received: from rock.gnat.com ([127.0.0.1]) by localhost (rock.gnat.com [127.0.0.1]) (amavisd-new, port 10024) with LMTP id Dr9b7zvoSDJ5 for ; Mon, 11 Nov 2013 01:38:23 -0500 (EST) Received: from joel.gnat.com (localhost.localdomain [127.0.0.1]) by rock.gnat.com (Postfix) with ESMTP id 752E11165A1 for ; Mon, 11 Nov 2013 01:38:23 -0500 (EST) Received: by joel.gnat.com (Postfix, from userid 1000) id 51BCCE07B7; Mon, 11 Nov 2013 10:37:41 +0400 (RET) From: Joel Brobecker To: gdb-patches@sourceware.org Subject: [RFA 2/3] New function cli-utils.c:extract_arg_const Date: Mon, 11 Nov 2013 06:39:00 -0000 Message-Id: <1384151855-12926-2-git-send-email-brobecker@adacore.com> In-Reply-To: <1384151855-12926-1-git-send-email-brobecker@adacore.com> References: <1384151855-12926-1-git-send-email-brobecker@adacore.com> X-SW-Source: 2013-11/txt/msg00272.txt.bz2 Hello, This function provides the exact same functionality as extract_arg, except that it takes a "const char**" instead of a "char **". This will be useful in the context of my next patch. gdb/ChangeLog: * cli/cli-utils.h (extract_arg_const): Add declaration. * cli/cli-utils.c (extract_arg_const): New function. Tested on x86_64-linux. OK to push? Thank you, -- Joel --- gdb/cli/cli-utils.c | 30 ++++++++++++++++++++++++++++++ gdb/cli/cli-utils.h | 7 +++++++ 2 files changed, 37 insertions(+) diff --git a/gdb/cli/cli-utils.c b/gdb/cli/cli-utils.c index f74e6b1..98afe1f 100644 --- a/gdb/cli/cli-utils.c +++ b/gdb/cli/cli-utils.c @@ -289,6 +289,36 @@ extract_arg (char **arg) /* See documentation in cli-utils.h. */ +char * +extract_arg_const (const char **arg) +{ + const char *result; + char *copy; + + if (!*arg) + return NULL; + + /* Find the start of the argument. */ + *arg = skip_spaces_const (*arg); + if (!**arg) + return NULL; + result = *arg; + + /* Find the end of the argument. */ + *arg = skip_to_space_const (*arg + 1); + + if (result == *arg) + return NULL; + + copy = xmalloc (*arg - result + 1); + memcpy (copy, result, *arg - result); + copy[*arg - result] = '\0'; + + return copy; +} + +/* See documentation in cli-utils.h. */ + int check_for_argument (char **str, char *arg, int arg_len) { diff --git a/gdb/cli/cli-utils.h b/gdb/cli/cli-utils.h index 152fb89..ebae2d2 100644 --- a/gdb/cli/cli-utils.h +++ b/gdb/cli/cli-utils.h @@ -118,6 +118,13 @@ extern char *remove_trailing_whitespace (const char *start, char *s); extern char *extract_arg (char **arg); +/* A const-correct version of "extract_arg". + + Since the returned value is xmalloc'd, it eventually needs to be + xfree'ed, which prevents us from making it const as well. */ + +extern char *extract_arg_const (const char **arg); + /* A helper function that looks for an argument at the start of a string. The argument must also either be at the end of the string, or be followed by whitespace. Returns 1 if it finds the argument, -- 1.8.1.2