From 7cb43a7996afa4a2a2578f1ce3302866bb79f55b Mon Sep 17 00:00:00 2001 From: Joseph Hunkeler Date: Tue, 4 Feb 2020 11:50:49 -0500 Subject: Initial commit of strlist.[c,h] --- src/strlist.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'src') diff --git a/src/strlist.c b/src/strlist.c index ccd1925..5f93201 100644 --- a/src/strlist.c +++ b/src/strlist.c @@ -139,6 +139,30 @@ size_t strlist_count(StrList *pStrList) { return pStrList->num_inuse; } +/** + * Set value at index + * @param pStrList + * @param value string + * @return + */ +void strlist_set(StrList *pStrList, size_t index, char *value) { + char *tmp = NULL; + char *item = NULL; + if (index > strlist_count(pStrList)) { + return; + } + if ((item = strlist_item(pStrList, index)) == NULL) { + return; + } + if ((tmp = realloc(pStrList->data[index], strlen(value) + 1)) == NULL) { + perror("realloc strlist_set replacement value"); + return; + } + pStrList->data[index] = tmp; + memset(pStrList->data[index], '\0', strlen(value) + 1); + strncpy(pStrList->data[index], value, strlen(value)); +} + /** * Retrieve data from a `StrList` * @param pStrList -- cgit