X-Git-Url: http://sjero.net/git/?p=wget;a=blobdiff_plain;f=src%2Futils.c;h=549f7a47ed44c2e1effd2fd9741066055a093ef7;hp=04968e6226e2b9f7d81baa1acf376f6593cb6a30;hb=0840de6605cf4ad83dc3c8d0797dfefeabdb3b53;hpb=082d2a5ab7da174e13371758bb872c70214cedda diff --git a/src/utils.c b/src/utils.c index 04968e62..549f7a47 100644 --- a/src/utils.c +++ b/src/utils.c @@ -1085,6 +1085,30 @@ merge_vecs (char **v1, char **v2) xfree (v2); return v1; } + +/* Append a freshly allocated copy of STR to VEC. If VEC is NULL, it + is allocated as needed. Return the new value of the vector. */ + +char ** +vec_append (char **vec, const char *str) +{ + int cnt; /* count of vector elements, including + the one we're about to append */ + if (vec != NULL) + { + for (cnt = 0; vec[cnt]; cnt++) + ; + ++cnt; + } + else + cnt = 1; + /* Reallocate the array to fit the new element and the NULL. */ + vec = xrealloc (vec, (cnt + 1) * sizeof (char *)); + /* Append a copy of STR to the vector. */ + vec[cnt - 1] = xstrdup (str); + vec[cnt] = NULL; + return vec; +} /* Sometimes it's useful to create "sets" of strings, i.e. special hash tables where you want to store strings as keys and merely