env-util.c revision c69a177207ed18d0f0210347430a60957136bd6c
02c335c23bf5fa225a467c19f2c063fb0dc7b8c3Timo Sirainen/* Copyright (c) 2002-2017 Dovecot authors, see the included COPYING file */
6ae6496c225238a2c55a8cd96744ad976c44a726Stephan Bosch const char **strings;
6ae6496c225238a2c55a8cd96744ad976c44a726Stephan Bosch env_pool = pool_alloconly_create(MEMPOOL_GROWING"Environment",
6ae6496c225238a2c55a8cd96744ad976c44a726Stephan Bosch extern char **environ;
6ae6496c225238a2c55a8cd96744ad976c44a726Stephan Bosch /* Try to clear the environment.
6ae6496c225238a2c55a8cd96744ad976c44a726Stephan Bosch a) environ = NULL crashes on OS X.
6ae6496c225238a2c55a8cd96744ad976c44a726Stephan Bosch b) *environ = NULL doesn't work on FreeBSD 7.0.
6ae6496c225238a2c55a8cd96744ad976c44a726Stephan Bosch c) environ = emptyenv doesn't work on Haiku OS
6ae6496c225238a2c55a8cd96744ad976c44a726Stephan Bosch d) environ = calloc() should work everywhere
6ae6496c225238a2c55a8cd96744ad976c44a726Stephan Boschstatic void env_clean_except_real(const char *const preserve_envs[])
6ae6496c225238a2c55a8cd96744ad976c44a726Stephan Bosch unsigned int i;
6ae6496c225238a2c55a8cd96744ad976c44a726Stephan Bosch /* Note that if the original environment was set with env_put(), the
6ae6496c225238a2c55a8cd96744ad976c44a726Stephan Bosch environment strings will be invalid after env_clean(). That's why
6ae6496c225238a2c55a8cd96744ad976c44a726Stephan Bosch we t_strconcat() them above. */
6ae6496c225238a2c55a8cd96744ad976c44a726Stephan Boschvoid env_clean_except(const char *const preserve_envs[])
6ae6496c225238a2c55a8cd96744ad976c44a726Stephan Bosch unsigned int i, count;
6ae6496c225238a2c55a8cd96744ad976c44a726Stephan Bosch for (count = 0; environ[count] != NULL; count++) ;
6ae6496c225238a2c55a8cd96744ad976c44a726Stephan Bosch pool = pool_alloconly_create("saved environment", 4096);
6ae6496c225238a2c55a8cd96744ad976c44a726Stephan Bosch env->strings = p_new(pool, const char *, count + 1);
6ae6496c225238a2c55a8cd96744ad976c44a726Stephan Bosch for (i = 0; i < count; i++)
6ae6496c225238a2c55a8cd96744ad976c44a726Stephan Boschvoid env_backup_restore(struct env_backup *env)
6ae6496c225238a2c55a8cd96744ad976c44a726Stephan Bosch unsigned int i;
6ae6496c225238a2c55a8cd96744ad976c44a726Stephan Bosch extern char **environ;