From: Ray Strode Date: Thu, 10 Jul 2008 16:45:36 +0000 (-0400) Subject: Add new _dbus_get_environment call X-Git-Tag: dbus-1.2.3~6^2~6 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=417c41f6c1ca122e1ce72a920bfc8c3ee841bf3c;p=thirdparty%2Fdbus.git Add new _dbus_get_environment call It's a wrapper around the environ external variable. It will be important in the future when we allow bus clients to modify the environment of future activated clients. Presently, we just always use the bus daemon environment wholesale. --- diff --git a/dbus/dbus-sysdeps.c b/dbus/dbus-sysdeps.c index 1a736e422..d740f875c 100644 --- a/dbus/dbus-sysdeps.c +++ b/dbus/dbus-sysdeps.c @@ -200,6 +200,48 @@ _dbus_clearenv (void) return rc; } +/** + * Gets a #NULL-terminated list of key=value pairs from the + * environment. Use dbus_free_string_array to free it. + * + * @returns the environment or #NULL on OOM + */ +char ** +_dbus_get_environment (void) +{ + int i, length; + extern char **environ; + char **environment; + + _dbus_assert (environ != NULL); + + for (length = 0; environ[length] != NULL; length++); + + /* Add one for NULL */ + length++; + + environment = dbus_new0 (char *, length); + + if (environment == NULL) + return NULL; + + for (i = 0; environ[i] != NULL; i++) + { + environment[i] = _dbus_strdup (environ[i]); + + if (environment[i] == NULL) + break; + } + + if (environ[i] != NULL) + { + dbus_free_string_array (environment); + environment = NULL; + } + + return environment; +} + /* * init a pipe instance. * diff --git a/dbus/dbus-sysdeps.h b/dbus/dbus-sysdeps.h index 5ff138842..80236f05e 100644 --- a/dbus/dbus-sysdeps.h +++ b/dbus/dbus-sysdeps.h @@ -101,6 +101,7 @@ const char* _dbus_getenv (const char *varname); dbus_bool_t _dbus_setenv (const char *varname, const char *value); dbus_bool_t _dbus_clearenv (void); +char ** _dbus_get_environment (void); /** A process ID */ typedef unsigned long dbus_pid_t;