]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib: Add env_put_array()
authorTimo Sirainen <timo.sirainen@open-xchange.com>
Wed, 20 Jan 2021 18:42:40 +0000 (20:42 +0200)
committerAki Tuomi <aki.tuomi@open-xchange.com>
Mon, 10 May 2021 06:24:24 +0000 (09:24 +0300)
src/lib/env-util.c
src/lib/env-util.h

index e19cc7cd27102880c0cfb95152b16473548a5304..231b1bcc0cc0a37b81f0ddb679964cedc4f19570 100644 (file)
@@ -25,6 +25,14 @@ void env_put(const char *env)
                i_fatal("putenv(%s) failed: %m", env);
 }
 
+void env_put_array(const char *const *envs)
+{
+       for (unsigned int i = 0; envs[i] != NULL; i++) {
+               i_assert(strchr(envs[i], '=') != NULL);
+               env_put(envs[i]);
+       }
+}
+
 void env_remove(const char *name)
 {
 #ifdef HAVE_UNSETENV
@@ -128,11 +136,8 @@ struct env_backup *env_backup_save(void)
 
 void env_backup_restore(struct env_backup *env)
 {
-       unsigned int i;
-
        env_clean();
-       for (i = 0; env->strings[i] != NULL; i++)
-               env_put(env->strings[i]);
+       env_put_array(env->strings);
 }
 
 void env_backup_free(struct env_backup **_env)
index f793da8bd42c7b0e50928aafedd0c80ef49522b4..d1aa51663914f8a1a56fb8c949d530033cd76b1b 100644 (file)
@@ -4,6 +4,8 @@
 /* Add new environment variable. Wrapper to putenv(). Note that calls to this
    function allocates memory which isn't free'd until env_clean() is called. */
 void env_put(const char *env);
+/* env_put() NULL-terminated array of name=value strings */
+void env_put_array(const char *const *envs);
 /* Remove a single environment. */
 void env_remove(const char *name);
 /* Clear all environment variables. */