diff options
author | Michael Haggerty <mhagger@alum.mit.edu> | 2012-09-12 16:04:42 +0200 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2012-09-12 11:43:24 -0700 |
commit | e448fed8e6ba9cd9237b7c8045c11cc40afc8595 (patch) | |
tree | 29417037d3510afd9623a3f35c371a312179ee83 /string-list.c | |
parent | The fourth batch for 1.8.0 (diff) | |
download | tgif-e448fed8e6ba9cd9237b7c8045c11cc40afc8595.tar.xz |
string_list: add function string_list_append_nodup()
Add a new function that appends a string to a string_list without
copying it. This can be used to pass ownership of an already-copied
string to a string_list that has strdup_strings set.
Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'string-list.c')
-rw-r--r-- | string-list.c | 20 |
1 files changed, 15 insertions, 5 deletions
diff --git a/string-list.c b/string-list.c index d9810aba42..ad2aa5af91 100644 --- a/string-list.c +++ b/string-list.c @@ -148,13 +148,23 @@ void print_string_list(const struct string_list *p, const char *text) printf("%s:%p\n", p->items[i].string, p->items[i].util); } -struct string_list_item *string_list_append(struct string_list *list, const char *string) +struct string_list_item *string_list_append_nodup(struct string_list *list, + char *string) { + struct string_list_item *retval; ALLOC_GROW(list->items, list->nr + 1, list->alloc); - list->items[list->nr].string = - list->strdup_strings ? xstrdup(string) : (char *)string; - list->items[list->nr].util = NULL; - return list->items + list->nr++; + retval = &list->items[list->nr++]; + retval->string = string; + retval->util = NULL; + return retval; +} + +struct string_list_item *string_list_append(struct string_list *list, + const char *string) +{ + return string_list_append_nodup( + list, + list->strdup_strings ? xstrdup(string) : (char *)string); } static int cmp_items(const void *a, const void *b) |