* [RFA] Add libiberty/argv.c:countargv
@ 2011-09-20 18:49 Doug Evans
2011-09-26 17:32 ` Doug Evans
2011-09-28 18:58 ` Ian Lance Taylor
0 siblings, 2 replies; 3+ messages in thread
From: Doug Evans @ 2011-09-20 18:49 UTC (permalink / raw)
To: gcc-patches
Hi.
Part of the abstraction of an argv is a count of the number elements.
This patch adds countargv which I have use for in gdb.
Ok to check in?
2011-09-20 Doug Evans <dje@google.com>
include/
* libiberty.h (countargv): Declare.
libiberty/
* argv.c (countargv): New function.
Index: include/libiberty.h
===================================================================
RCS file: /cvs/src/src/include/libiberty.h,v
retrieving revision 1.64
diff -u -p -r1.64 libiberty.h
--- include/libiberty.h 22 Jul 2011 14:37:51 -0000 1.64
+++ include/libiberty.h 20 Sep 2011 18:18:07 -0000
@@ -91,6 +91,10 @@ extern void expandargv PARAMS ((int *, c
extern int writeargv PARAMS ((char **, FILE *));
+/* Return the number of elements in argv. */
+
+extern int countargv (char**);
+
/* Return the last component of a path name. Note that we can't use a
prototype here because the parameter is declared inconsistently
across different systems, sometimes as "char *" and sometimes as
Index: libiberty/argv.c
===================================================================
RCS file: /cvs/src/src/libiberty/argv.c,v
retrieving revision 1.22
diff -u -p -r1.22 argv.c
--- libiberty/argv.c 13 Aug 2010 11:36:10 -0000 1.22
+++ libiberty/argv.c 20 Sep 2011 18:21:28 -0000
@@ -492,6 +492,28 @@ expandargv (int *argcp, char ***argvp)
}
}
+/*
+
+@deftypefn Extension int countargv (char **@var{argv})
+
+Return the number of elements in @var{argv}.
+Returns zero if @var{argv} is NULL.
+
+@end deftypefn
+
+*/
+
+int
+countargv (char **argv)
+{
+ int argc;
+
+ if (argv == NULL)
+ return 0;
+ for (argc = 0; argv[argc] != NULL; argc++);
+ return argc;
+}
+
#ifdef MAIN
/* Simple little test driver. */
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [RFA] Add libiberty/argv.c:countargv
2011-09-20 18:49 [RFA] Add libiberty/argv.c:countargv Doug Evans
@ 2011-09-26 17:32 ` Doug Evans
2011-09-28 18:58 ` Ian Lance Taylor
1 sibling, 0 replies; 3+ messages in thread
From: Doug Evans @ 2011-09-26 17:32 UTC (permalink / raw)
To: gcc-patches
On Tue, Sep 20, 2011 at 11:23 AM, Doug Evans <dje@google.com> wrote:
> Hi.
>
> Part of the abstraction of an argv is a count of the number elements.
> This patch adds countargv which I have use for in gdb.
>
> Ok to check in?
>
> 2011-09-20 Doug Evans <dje@google.com>
>
> include/
> * libiberty.h (countargv): Declare.
>
> libiberty/
> * argv.c (countargv): New function.
Ping.
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [RFA] Add libiberty/argv.c:countargv
2011-09-20 18:49 [RFA] Add libiberty/argv.c:countargv Doug Evans
2011-09-26 17:32 ` Doug Evans
@ 2011-09-28 18:58 ` Ian Lance Taylor
1 sibling, 0 replies; 3+ messages in thread
From: Ian Lance Taylor @ 2011-09-28 18:58 UTC (permalink / raw)
To: Doug Evans; +Cc: gcc-patches
On Tue, Sep 20, 2011 at 11:23 AM, Doug Evans <dje@google.com> wrote:
>
> 2011-09-20 Doug Evans <dje@google.com>
>
> include/
> * libiberty.h (countargv): Declare.
>
> libiberty/
> * argv.c (countargv): New function.
> + for (argc = 0; argv[argc] != NULL; argc++);
Please write the semicolon on the next line. I think it is too easy
to get confused when written that way.
for (argc = 0; argv[argc] != NULL; argc++)
;
This is OK with that change.
Thanks.
Ian
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2011-09-28 18:23 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-09-20 18:49 [RFA] Add libiberty/argv.c:countargv Doug Evans
2011-09-26 17:32 ` Doug Evans
2011-09-28 18:58 ` Ian Lance Taylor
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).