From 978e30e84dcfb06bfdc8b943bcae3b9a0c72e1d5 Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Wed, 22 Jun 2011 15:22:09 +0100 Subject: [PATCH] _dbus_get_environment: move from shared library to dbus-sysdeps-util --- dbus/dbus-sysdeps-util.c | 53 +++++++++++++++++++++++++++++++++++++++++++++- dbus/dbus-sysdeps.c | 41 ----------------------------------- 2 files changed, 52 insertions(+), 42 deletions(-) diff --git a/dbus/dbus-sysdeps-util.c b/dbus/dbus-sysdeps-util.c index 68669cf..4bd9312 100644 --- a/dbus/dbus-sysdeps-util.c +++ b/dbus/dbus-sysdeps-util.c @@ -28,8 +28,59 @@ #include "dbus-string.h" #include "dbus-test.h" -#ifdef DBUS_BUILD_TESTS #include + +#ifdef DBUS_WIN + /* do nothing, it's in stdlib.h */ +#elif (defined __APPLE__) +# include +# define environ (*_NSGetEnviron()) +#else +extern char **environ; +#endif + +/** + * 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; + 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; +} + +#ifdef DBUS_BUILD_TESTS static void check_dirname (const char *filename, const char *dirname) diff --git a/dbus/dbus-sysdeps.c b/dbus/dbus-sysdeps.c index bab516d..655a54d 100644 --- a/dbus/dbus-sysdeps.c +++ b/dbus/dbus-sysdeps.c @@ -208,47 +208,6 @@ _dbus_clearenv (void) } /** - * 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; - 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; -} - -/** * Split paths into a list of char strings * * @param dirs string with pathes -- 1.7.7