const char **strings;
};
-static pool_t env_pool = NULL;
-
void env_put(const char *name, const char *value)
{
i_assert(strchr(name, '=') == NULL);
- if (env_pool == NULL) {
- env_pool = pool_alloconly_create(MEMPOOL_GROWING"Environment",
- 2048);
- }
- if (putenv(p_strdup_printf(env_pool, "%s=%s", name, value)) != 0)
- i_fatal("putenv(%s=%s) failed: %m", name, value);
+ if (setenv(name, value, 1) != 0)
+ i_fatal("setenv(%s, %s) failed: %m", name, value);
}
void env_put_array(const char *const *envs)
*/
*environ_p = calloc(1, sizeof(**environ_p));
#endif
- if (env_pool != NULL)
- p_clear(env_pool);
}
static void env_clean_except_real(const char *const preserve_envs[])
return &environ;
#endif
}
-
-void env_deinit(void)
-{
- pool_unref(&env_pool);
-}
#ifndef ENV_UTIL_H
#define ENV_UTIL_H
-/* 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. */
+/* Add a new environment variable or replace an existing one.
+ Wrapper to setenv(). Note that setenv() often doesn't free memory used by
+ replaced environment, so don't keep repeatedly changing values in
+ environment. */
void env_put(const char *name, const char *value);
/* env_put() NULL-terminated array of name=value strings */
void env_put_array(const char *const *envs);
directly. */
char ***env_get_environ_p(void);
-/* Free all memory used by env_put() function. Environment must not be
- accessed afterwards. */
-void env_deinit(void);
#endif