#include "hash.h"
#include "network.h"
#include "istream.h"
+#include "env-util.h"
#include "execv-const.h"
#include "str.h"
#include "strescape.h"
int settings_parse_environ(struct setting_parser_context *ctx)
{
- extern char **environ;
+ char **environ = *env_get_environ_p();
ARRAY_TYPE(string) sorted_envs_arr;
const char *key, *value;
char *const *sorted_envs;
#include "env-util.h"
#include <stdlib.h>
+#ifdef __APPLE__
+# include <crt_externs.h>
+#endif
struct env_backup {
pool_t pool;
struct env_backup *env_backup_save(void)
{
+ char **environ = *env_get_environ_p();
struct env_backup *env;
- extern char **environ;
unsigned int i, count;
pool_t pool;
pool_unref(&env->pool);
}
+char ***env_get_environ_p(void)
+{
+#ifdef __APPLE__
+ return _NSGetEnviron();
+#else
+ extern char **environ;
+
+ return &environ;
+#endif
+}
+
void env_deinit(void)
{
if (env_pool != NULL)
/* Free the memory used by environment backup. */
void env_backup_free(struct env_backup **env);
+/* Returns the value of "&environ". This is more portable than using it
+ 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);
/* Copyright (c) 2002-2010 Dovecot authors, see the included COPYING file */
#include "lib.h"
+#include "env-util.h"
#include "process-title.h"
#include <stdlib.h> /* NetBSD, OpenBSD */
void process_title_init(char **argv[])
{
#ifdef PROCTITLE_HACK
- extern char **environ;
+ char ***environ_p = env_get_environ_p();
char **orig_argv = *argv;
- char **orig_environ = environ;
+ char **orig_environ = *environ_p;
*argv = argv_dup(orig_argv, &argv_memblock);
- environ = argv_dup(orig_environ, &environ_memblock);
+ *environ_p = argv_dup(orig_environ, &environ_memblock);
proctitle_hack_init(orig_argv, orig_environ);
#endif
process_name = (*argv)[0];