From 22c92294ad06a1e3421cc66a11c6530675121ccf Mon Sep 17 00:00:00 2001 From: "Trever L. Adams" Date: Thu, 13 Oct 2016 03:25:08 -0600 Subject: strv.c: add strv_to_env for use with execle, etc. Reviewed-by: Volker Lendecke Reviewed-by: David Disseldorp Signed-off-by: Trever L. Adams Autobuild-User(master): David Disseldorp Autobuild-Date(master): Fri Oct 14 01:44:02 CEST 2016 on sn-devel-144 --- lib/util/strv.c | 26 ++++++++++++++++++++++++++ lib/util/strv.h | 1 + 2 files changed, 27 insertions(+) (limited to 'lib') diff --git a/lib/util/strv.c b/lib/util/strv.c index 577cd4da983..99ce76f54fd 100644 --- a/lib/util/strv.c +++ b/lib/util/strv.c @@ -155,3 +155,29 @@ void strv_delete(char **strv, char *entry) *strv = talloc_realloc(NULL, *strv, char, len - entry_len); } + +char * const *strv_to_env(TALLOC_CTX *mem_ctx, char *strv) +{ + char **data; + char *next = NULL; + size_t i; + size_t count = strv_count(strv); + + if (strv == NULL) { + return NULL; + } + + data = talloc_array(mem_ctx, char *, count + 1); + + if (data == NULL) { + return NULL; + } + + for(i = 0; i < count; i++) { + next = strv_next(strv, next); + data[i] = next; + } + data[count] = NULL; + + return data; +} diff --git a/lib/util/strv.h b/lib/util/strv.h index a3fe7ab3c5a..398e8ead171 100644 --- a/lib/util/strv.h +++ b/lib/util/strv.h @@ -29,5 +29,6 @@ char *strv_next(char *strv, const char *entry); char *strv_find(char *strv, const char *entry); size_t strv_count(char *strv); void strv_delete(char **strv, char *entry); +char * const *strv_to_env(TALLOC_CTX *mem_ctx, char *strv); #endif -- cgit v1.2.1