dovecot: Added functions for building an "environment array". It...

dovecot at dovecot.org dovecot at dovecot.org
Wed Jan 2 01:36:55 EET 2008


details:   http://hg.dovecot.org/dovecot/rev/c8878d66c4a1
changeset: 7090:c8878d66c4a1
user:      Timo Sirainen <tss at iki.fi>
date:      Wed Jan 02 01:35:21 2008 +0200
description:
Added functions for building an "environment array". It can be passed later
to execve().

diffstat:

2 files changed, 31 insertions(+)
src/lib/env-util.c |   23 +++++++++++++++++++++++
src/lib/env-util.h |    8 ++++++++

diffs (53 lines):

diff -r 10d49a20b04e -r c8878d66c4a1 src/lib/env-util.c
--- a/src/lib/env-util.c	Wed Jan 02 00:03:41 2008 +0200
+++ b/src/lib/env-util.c	Wed Jan 02 01:35:21 2008 +0200
@@ -1,6 +1,7 @@
 /* Copyright (c) 2002-2008 Dovecot authors, see the included COPYING file */
 
 #include "lib.h"
+#include "array.h"
 #include "env-util.h"
 
 #include <stdlib.h>
@@ -26,3 +27,25 @@ void env_clean(void)
 	if (pool != NULL)
 		pool_unref(&pool);
 }
+
+void envarr_add(ARRAY_TYPE(const_string) *arr,
+		const char *key, const char *value)
+{
+	const char *str = t_strconcat(key, "=", value, NULL);
+
+	array_append(arr, &str, 1);
+}
+
+void envarr_addi(ARRAY_TYPE(const_string) *arr, const char *key,
+		 unsigned int value)
+{
+	char str[MAX_INT_STRLEN];
+
+	i_snprintf(str, sizeof(str), "%u", value);
+	envarr_add(arr, key, str);
+}
+
+void envarr_addb(ARRAY_TYPE(const_string) *arr, const char *key)
+{
+	envarr_add(arr, key, "1");
+}
diff -r 10d49a20b04e -r c8878d66c4a1 src/lib/env-util.h
--- a/src/lib/env-util.h	Wed Jan 02 00:03:41 2008 +0200
+++ b/src/lib/env-util.h	Wed Jan 02 01:35:21 2008 +0200
@@ -7,4 +7,12 @@ void env_put(const char *env);
 /* Clear all environment variables. */
 void env_clean(void);
 
+/* Append a string containing key=value to the array */
+void envarr_add(ARRAY_TYPE(const_string) *arr,
+		const char *key, const char *value);
+void envarr_addi(ARRAY_TYPE(const_string) *arr, const char *key,
+		 unsigned int value);
+/* Append a string containing key=1 to the array */
+void envarr_addb(ARRAY_TYPE(const_string) *arr, const char *key);
+
 #endif


More information about the dovecot-cvs mailing list