From c12ded991ed38fc9d4aaaa3cce10695cbcfa6efb Mon Sep 17 00:00:00 2001 From: devans Date: Wed, 28 Sep 2011 19:04:30 +0000 Subject: include/ * libiberty.h (countargv): Declare. libiberty/ * argv.c (countargv): New function. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@179318 138bc75d-0d04-0410-961f-82ee72b054a4 --- libiberty/ChangeLog | 4 ++++ libiberty/argv.c | 23 +++++++++++++++++++++++ 2 files changed, 27 insertions(+) (limited to 'libiberty') diff --git a/libiberty/ChangeLog b/libiberty/ChangeLog index 0547f9b08ed..ccee83fb3a2 100644 --- a/libiberty/ChangeLog +++ b/libiberty/ChangeLog @@ -1,3 +1,7 @@ +2011-09-28 Doug Evans + + * argv.c (countargv): New function. + 2011-09-23 Cary Coutant PR 40831 diff --git a/libiberty/argv.c b/libiberty/argv.c index 8476c8fda9e..ca53f91493d 100644 --- a/libiberty/argv.c +++ b/libiberty/argv.c @@ -492,6 +492,29 @@ 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++) + continue; + return argc; +} + #ifdef MAIN /* Simple little test driver. */ -- cgit v1.2.1