diff options
author | Miles Bader <miles@gnu.org> | 1995-12-21 16:33:14 +0000 |
---|---|---|
committer | Miles Bader <miles@gnu.org> | 1995-12-21 16:33:14 +0000 |
commit | a3a4f0e6abd77e7f873d74a4bd3f813677f4ea56 (patch) | |
tree | ed6936833878d04bc8285ddbc7b93ccdddc4f3df | |
parent | 0721ca63fab1108269056eec439591cb71470a31 (diff) |
(argz_insert): Instead of an integer position N, take a pointer BEFORE into
ARGZ to insert before.
(argz_next): New inline function.
-rw-r--r-- | libshouldbeinlibc/=argz.h | 39 |
1 files changed, 37 insertions, 2 deletions
diff --git a/libshouldbeinlibc/=argz.h b/libshouldbeinlibc/=argz.h index 5533bfb5..da52cf8c 100644 --- a/libshouldbeinlibc/=argz.h +++ b/libshouldbeinlibc/=argz.h @@ -48,7 +48,42 @@ error_t argz_add (char **argz, unsigned *argz_len, char *str); /* Remove ENTRY from ARGZ & ARGZ_LEN, if any. */ void argz_remove (char **argz, unsigned *argz_len, char *entry); -/* Insert ENTRY into ARGZ & ARGZ_LEN at position N. */ -error_t argz_insert (char **argz, unsigned *argz_len, unsigned n, char *entry); +/* Insert ENTRY into ARGZ & ARGZ_LEN before BEFORE, which should be an + existing entry in ARGZ; if BEFORE is NULL, ENTRY is appended to the end. + Since ARGZ's first entry is the same as ARGZ, argz_insert (ARGZ, ARGZ_LEN, + ARGZ, ENTRY) will insert ENTRY at the beginning of ARGZ. If BEFORE is not + in ARGZ, EINVAL is returned, else if memory can't be allocated for the new + ARGZ, ENOMEM is returned, else 0. */ +error_t +argz_insert (char **argz, unsigned *argz_len, char *before, char *entry); + +/* Returns the next entry in ARGZ & ARGZ_LEN after ENTRY, or NULL if there + are no more. If entry is NULL, then the first entry is returned. This + behavior allows two convenient iteration styles: + + char *entry = 0; + while (entry = argz_next (argz, argz_len, entry)) + ...; + + or + + char *entry; + for (entry = argz; entry; entry = argz_next (argz, argz_len, entry)) + ...; +*/ +extern inline char * +argz_next (char *argz, unsigned argz_len, char *entry) +{ + if (entry) + if (entry >= argz + argz_len) + return 0; + else + return entry + strlen (entry) + 1; + else + if (argz_len > 0) + return argz; + else + return 0; +} #endif /* __ARGZ_H__ */ |