_dbus_get_environment: move from shared library to dbus-sysdeps-util
authorSimon McVittie <simon.mcvittie@collabora.co.uk>
Wed, 22 Jun 2011 14:22:09 +0000 (15:22 +0100)
committerSimon McVittie <simon.mcvittie@collabora.co.uk>
Wed, 8 Feb 2012 19:30:22 +0000 (19:30 +0000)
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=34976
Signed-off-by: Simon McVittie <simon.mcvittie@collabora.co.uk>
Reviewed-by: Cosimo Alfarano <cosimo.alfarano@collabora.co.uk>
dbus/dbus-sysdeps-util.c
dbus/dbus-sysdeps.c

index 68669cf..4bd9312 100644 (file)
 #include "dbus-string.h"
 #include "dbus-test.h"
 
-#ifdef DBUS_BUILD_TESTS
 #include <stdlib.h>
+
+#ifdef DBUS_WIN
+  /* do nothing, it's in stdlib.h */
+#elif (defined __APPLE__)
+# include <crt_externs.h>
+# 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)
index bab516d..655a54d 100644 (file)
@@ -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