NAME

strlist -- dynamically growing list of strings


SYNOPSIS

   #include <afblib/strlist.h>
   typedef struct strlist {
      char** list;
      unsigned int len;
      unsigned int allocated;
   } strlist;
   int strlist_ready(strlist* list, unsigned int len);
   int strlist_readyplus(strlist* list, unsigned int len);
   int strlist_clear(strlist* list);
   int strlist_push(strlist* list, char* string);
   int strlist_push0(strlist* list);
   int strlist_free(strlist* list);


DESCRIPTION

Objects of type strlist represent lists of character strings. Any number of strings may be added to such a list. Already added list members cannot be removed except by clearing the whole list. This data structure is mainly useful in building up arguments lists, e.g. for execvp.

There is no function that creates or initializes a list. Instead an initializer is to be used:

   strlist argv = {0};

strlist objects grow by themselves. However, if the number of elements can be estimated or is known, it might be preferably to use strlist_read to assure that there is space ready allocated for at least len entries. strlist_readyplus works similar to strlist_ready but adds implicitly the current number of list members to len.

strlist_clear empties the entire list. strlist_push adds the given string to the list. strlist_push0 adds a null-pointer to the list. This is particularly useful in case of null-pointer-terminated argument or environment lists.

strlist_free frees the allocated memory associated with list.


AUTHOR

Andreas F. Borchert