diff options
author | Trever L. Adams <trever.adams@gmail.com> | 2016-10-13 03:25:08 -0600 |
---|---|---|
committer | David Disseldorp <ddiss@samba.org> | 2016-10-14 01:44:02 +0200 |
commit | 22c92294ad06a1e3421cc66a11c6530675121ccf (patch) | |
tree | bec6800d066af887f3eaf3225ffb519608df713d /lib | |
parent | 001e23fd6250f8426b0866370fb4fdcbe5b29147 (diff) | |
download | samba-22c92294ad06a1e3421cc66a11c6530675121ccf.tar.gz |
strv.c: add strv_to_env for use with execle, etc.
Reviewed-by: Volker Lendecke <vl@samba.org>
Reviewed-by: David Disseldorp <ddiss@samba.org>
Signed-off-by: Trever L. Adams <trever.adams@gmail.com>
Autobuild-User(master): David Disseldorp <ddiss@samba.org>
Autobuild-Date(master): Fri Oct 14 01:44:02 CEST 2016 on sn-devel-144
Diffstat (limited to 'lib')
-rw-r--r-- | lib/util/strv.c | 26 | ||||
-rw-r--r-- | lib/util/strv.h | 1 |
2 files changed, 27 insertions, 0 deletions
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 |