From patchwork Tue Jan 5 20:25:46 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mike Frysinger X-Patchwork-Id: 10235 Received: (qmail 73783 invoked by alias); 5 Jan 2016 20:25:57 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 73727 invoked by uid 89); 5 Jan 2016 20:25:54 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.8 required=5.0 tests=AWL, BAYES_00, RP_MATCHES_RCVD, SPF_PASS autolearn=ham version=3.3.2 spammy=scans, freshly, boston, Boston X-Spam-User: qpsmtpd, 2 recipients X-HELO: smtp.gentoo.org Received: from smtp.gentoo.org (HELO smtp.gentoo.org) (140.211.166.183) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-GCM-SHA384 encrypted) ESMTPS; Tue, 05 Jan 2016 20:25:53 +0000 Received: from localhost.localdomain (localhost [127.0.0.1]) by smtp.gentoo.org (Postfix) with ESMTP id AACF334098F; Tue, 5 Jan 2016 20:25:50 +0000 (UTC) From: Mike Frysinger To: gdb-patches@sourceware.org, binutils@sourceware.org Subject: [PATCH] libiberty: {count, dup, write}argv: constify argv input slightly [committed] Date: Tue, 5 Jan 2016 15:25:46 -0500 Message-Id: <1452025546-17106-1-git-send-email-vapier@gentoo.org> X-IsSubscribed: yes This is in the gcc tree already. Would be more useful if we could use "const char * const *", but there's a long standing bug where gcc warns about incompatible pointers when you try to pass in "char **". We can at least constify the array itself as gcc will not warn in that case. --- include/ChangeLog | 5 +++++ include/libiberty.h | 6 +++--- libiberty/ChangeLog | 6 ++++++ libiberty/argv.c | 12 ++++++------ libiberty/functions.texi | 6 +++--- 5 files changed, 23 insertions(+), 12 deletions(-) diff --git a/include/ChangeLog b/include/ChangeLog index 70e19b7..07c24d3 100644 --- a/include/ChangeLog +++ b/include/ChangeLog @@ -1,3 +1,8 @@ +2016-01-05 Mike Frysinger + + * libiberty.h (dupargv): Change arg to char * const *. + (writeargv, countargv): Likewise. + 2016-01-01 Alan Modra Update year range in copyright notice of all files. diff --git a/include/libiberty.h b/include/libiberty.h index 6aa8700..8f7d5f6 100644 --- a/include/libiberty.h +++ b/include/libiberty.h @@ -80,7 +80,7 @@ extern void freeargv (char **); /* Duplicate an argument vector. Allocates memory using malloc. Use freeargv to free the vector. */ -extern char **dupargv (char **) ATTRIBUTE_MALLOC; +extern char **dupargv (char * const *) ATTRIBUTE_MALLOC; /* Expand "@file" arguments in argv. */ @@ -88,11 +88,11 @@ extern void expandargv (int *, char ***); /* Write argv to an @-file, inserting necessary quoting. */ -extern int writeargv (char **, FILE *); +extern int writeargv (char * const *, FILE *); /* Return the number of elements in argv. */ -extern int countargv (char**); +extern int countargv (char * const *); /* Return the last component of a path name. Note that we can't use a prototype here because the parameter is declared inconsistently diff --git a/libiberty/ChangeLog b/libiberty/ChangeLog index ba1e0a5..77c1ecb 100644 --- a/libiberty/ChangeLog +++ b/libiberty/ChangeLog @@ -1,5 +1,11 @@ 2016-01-05 Mike Frysinger + * argv.c (dupargv): Change arg to char * const *. Update comment. + (writeargv, countargv): Likewise. + * functions.texi (dupargv, writeargv, countargv): Likewise. + +2016-01-05 Mike Frysinger + * argv.c (dupargv): Replace strlen/xmalloc/strcpy with xstrdup. 2015-12-28 Patrick Palka diff --git a/libiberty/argv.c b/libiberty/argv.c index 5c3dd70..994dd35 100644 --- a/libiberty/argv.c +++ b/libiberty/argv.c @@ -49,7 +49,7 @@ Boston, MA 02110-1301, USA. */ /* -@deftypefn Extension char** dupargv (char **@var{vector}) +@deftypefn Extension char** dupargv (char * const *@var{vector}) Duplicate an argument vector. Simply scans through @var{vector}, duplicating each argument until the terminating @code{NULL} is found. @@ -62,7 +62,7 @@ argument vector. */ char ** -dupargv (char **argv) +dupargv (char * const *argv) { int argc; char **copy; @@ -279,7 +279,7 @@ char **buildargv (const char *input) /* -@deftypefn Extension int writeargv (const char **@var{argv}, FILE *@var{file}) +@deftypefn Extension int writeargv (char * const *@var{argv}, FILE *@var{file}) Write each member of ARGV, handling all necessary quoting, to the file named by FILE, separated by whitespace. Return 0 on success, non-zero @@ -290,7 +290,7 @@ if an error occurred while writing to FILE. */ int -writeargv (char **argv, FILE *f) +writeargv (char * const *argv, FILE *f) { int status = 0; @@ -463,7 +463,7 @@ expandargv (int *argcp, char ***argvp) /* -@deftypefn Extension int countargv (char **@var{argv}) +@deftypefn Extension int countargv (char * const *@var{argv}) Return the number of elements in @var{argv}. Returns zero if @var{argv} is NULL. @@ -473,7 +473,7 @@ Returns zero if @var{argv} is NULL. */ int -countargv (char **argv) +countargv (char * const *argv) { int argc; diff --git a/libiberty/functions.texi b/libiberty/functions.texi index b5f4e80..24dcc37 100644 --- a/libiberty/functions.texi +++ b/libiberty/functions.texi @@ -176,7 +176,7 @@ Concatenate zero or more of strings and return the result in freshly @end deftypefn @c argv.c:470 -@deftypefn Extension int countargv (char **@var{argv}) +@deftypefn Extension int countargv (char * const *@var{argv}) Return the number of elements in @var{argv}. Returns zero if @var{argv} is NULL. @@ -213,7 +213,7 @@ make it easy to compose the values of multiple blocks. @end deftypefn @c argv.c:52 -@deftypefn Extension char** dupargv (char **@var{vector}) +@deftypefn Extension char** dupargv (char * const *@var{vector}) Duplicate an argument vector. Simply scans through @var{vector}, duplicating each argument until the terminating @code{NULL} is found. @@ -1915,7 +1915,7 @@ does the return value. The third argument is unused in @libib{}. @end deftypefn @c argv.c:286 -@deftypefn Extension int writeargv (const char **@var{argv}, FILE *@var{file}) +@deftypefn Extension int writeargv (char * const *@var{argv}, FILE *@var{file}) Write each member of ARGV, handling all necessary quoting, to the file named by FILE, separated by whitespace. Return 0 on success, non-zero