summaryrefslogtreecommitdiff
path: root/argv-array.c
diff options
context:
space:
mode:
authorLibravatar Jeff King <peff@peff.net>2016-02-22 17:44:15 -0500
committerLibravatar Junio C Hamano <gitster@pobox.com>2016-02-22 14:50:32 -0800
commitb992657ed0e2720e20302b0ac8c210dff55950b2 (patch)
treeda139d348ebf30385b1ff8ea758ba8befe0b44b1 /argv-array.c
parentadd helpers for allocating flex-array structs (diff)
downloadtgif-b992657ed0e2720e20302b0ac8c210dff55950b2.tar.xz
argv-array: add detach function
The usual pattern for an argv array is to initialize it, push in some strings, and then clear it when done. Very occasionally, though, we must do other exotic things with the memory, like freeing the list but keeping the strings. Let's provide a detach function so that callers can make use of our API to build up the array, and then take ownership of it. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'argv-array.c')
-rw-r--r--argv-array.c11
1 files changed, 11 insertions, 0 deletions
diff --git a/argv-array.c b/argv-array.c
index eaed47712b..5d370fa336 100644
--- a/argv-array.c
+++ b/argv-array.c
@@ -74,3 +74,14 @@ void argv_array_clear(struct argv_array *array)
}
argv_array_init(array);
}
+
+const char **argv_array_detach(struct argv_array *array)
+{
+ if (array->argv == empty_argv)
+ return xcalloc(1, sizeof(const char *));
+ else {
+ const char **ret = array->argv;
+ argv_array_init(array);
+ return ret;
+ }
+}