diff options
author | Ray Strode <rstrode@redhat.com> | 2008-07-10 12:45:36 -0400 |
---|---|---|
committer | Ray Strode <rstrode@redhat.com> | 2008-07-11 23:58:53 -0400 |
commit | 417c41f6c1ca122e1ce72a920bfc8c3ee841bf3c (patch) | |
tree | 7692ed07a2cae94fb8443a0f8b52a67c453ca5e9 /dbus/dbus-sysdeps.c | |
parent | 458c6ead8572f8cea248844b6860156a00f3f45b (diff) |
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.
Diffstat (limited to 'dbus/dbus-sysdeps.c')
-rw-r--r-- | dbus/dbus-sysdeps.c | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/dbus/dbus-sysdeps.c b/dbus/dbus-sysdeps.c index 1a736e42..d740f875 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. * |