From 4d5adf29957f697f0a77ae13b7057cba844c19a0 Mon Sep 17 00:00:00 2001 From: Miles Bader Date: Thu, 18 May 1995 14:35:32 +0000 Subject: 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. --- libshouldbeinlibc/=argz.c | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) (limited to 'libshouldbeinlibc') 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 -- cgit v1.2.3