diff options
author | Miles Bader <miles@gnu.org> | 1995-05-18 14:35:32 +0000 |
---|---|---|
committer | Miles Bader <miles@gnu.org> | 1995-05-18 14:35:32 +0000 |
commit | 4d5adf29957f697f0a77ae13b7057cba844c19a0 (patch) | |
tree | 93b35e0e01956e2399f45ba4b13c9c8cccc52ea7 | |
parent | 090e5897b0e53b80811b9486981471cf6ba603d6 (diff) |
Add two new functions: argz_count returns the number of arguments in an argz
vector, and argz_extract extracts the arguments into an argv type vector.
-rw-r--r-- | libshouldbeinlibc/=argz.c | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/libshouldbeinlibc/=argz.c b/libshouldbeinlibc/=argz.c index 68fd6f5f..ee397160 100644 --- a/libshouldbeinlibc/=argz.c +++ b/libshouldbeinlibc/=argz.c @@ -58,6 +58,39 @@ argz_create(char **argv, char **argz, int *len) /* ---------------------------------------------------------------- */ +/* Returns the number of strings in ARGZ. */ +int +argz_count (char *argz, int len) +{ + int count = 0; + while (len > 0) + { + int part_len = strlen(argz); + argz += part_len + 1; + len -= part_len + 1; + count++; + } + return count; +} + +/* ---------------------------------------------------------------- */ + +/* Puts pointers to each string in ARGZ into ARGV, which must be large enough + to hold them all. */ +void +argz_extract (char *argz, int len, char **argv) +{ + while (len > 0) + { + int part_len = strlen(argz); + *argv++ = argz; + argz += part_len + 1; + len -= part_len + 1; + } +} + +/* ---------------------------------------------------------------- */ + /* Make '\0' separated arg vector ARGZ printable by converting all the '\0's except the last into spaces. */ void |