From be50fcea4e4482bff587119732223f1d4639f47b Mon Sep 17 00:00:00 2001 From: Doug Evans Date: Wed, 28 Sep 2011 19:04:30 +0000 Subject: [PATCH] libiberty.h (countargv): Declare. include/ * libiberty.h (countargv): Declare. libiberty/ * argv.c (countargv): New function. From-SVN: r179318 --- include/ChangeLog | 4 ++++ include/libiberty.h | 4 ++++ libiberty/ChangeLog | 4 ++++ libiberty/argv.c | 23 +++++++++++++++++++++++ 4 files changed, 35 insertions(+) diff --git a/include/ChangeLog b/include/ChangeLog index 3cc899606888..a09c287a6126 100644 --- a/include/ChangeLog +++ b/include/ChangeLog @@ -1,3 +1,7 @@ +2011-09-28 Doug Evans + + * libiberty.h (countargv): Declare. + 2011-09-26 Cary Coutant PR lto/47247 diff --git a/include/libiberty.h b/include/libiberty.h index 32eb83a049ee..cacde800ea3d 100644 --- a/include/libiberty.h +++ b/include/libiberty.h @@ -91,6 +91,10 @@ extern void expandargv PARAMS ((int *, char ***)); 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 diff --git a/libiberty/ChangeLog b/libiberty/ChangeLog index 0547f9b08ed4..ccee83fb3a22 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 8476c8fda9e1..ca53f91493db 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. */ -- 2.39.2