aboutsummaryrefslogtreecommitdiff
path: root/argv-array.c
diff options
context:
space:
mode:
authorFlorian Achleitner <florian.achleitner.2.6.31@gmail.com>2012-09-19 17:21:18 +0200
committerJunio C Hamano <gitster@pobox.com>2012-10-07 14:10:16 -0700
commitdf7428eca46ec25df5ef14bc7e90120bdc267328 (patch)
tree33678e8a765a07b1f7e989232d025a2ea83198d3 /argv-array.c
parentfd871b94f6d564864194befa10c621586b7b8bcf (diff)
downloadgit-df7428eca46ec25df5ef14bc7e90120bdc267328.tar.gz
git-df7428eca46ec25df5ef14bc7e90120bdc267328.tar.xz
Add argv_array_detach and argv_array_free_detached
Allow detaching of ownership of the argv_array's contents and add a function to free those detached argv_arrays later. This makes it possible to use argv_array efficiently with the exiting struct child_process which only contains a member char **argv. Add to documentation. Signed-off-by: Florian Achleitner <florian.achleitner.2.6.31@gmail.com> Acked-by: David Michael Barr <b@rr-dav.id.au> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'argv-array.c')
-rw-r--r--argv-array.c20
1 files changed, 20 insertions, 0 deletions
diff --git a/argv-array.c b/argv-array.c
index 0b5f8898a..aab50d6a9 100644
--- a/argv-array.c
+++ b/argv-array.c
@@ -59,3 +59,23 @@ void argv_array_clear(struct argv_array *array)
}
argv_array_init(array);
}
+
+const char **argv_array_detach(struct argv_array *array, int *argc)
+{
+ const char **argv =
+ array->argv == empty_argv || array->argc == 0 ? NULL : array->argv;
+ if (argc)
+ *argc = array->argc;
+ argv_array_init(array);
+ return argv;
+}
+
+void argv_array_free_detached(const char **argv)
+{
+ if (argv) {
+ int i;
+ for (i = 0; argv[i]; i++)
+ free((char **)argv[i]);
+ free(argv);
+ }
+}