Commit b129afbb authored by Simon McVittie's avatar Simon McVittie

_dbus_get_environment: move from shared library to dbus-sysdeps-util

Bug: https://bugs.freedesktop.org/show_bug.cgi?id=34976Signed-off-by: default avatarSimon McVittie <simon.mcvittie@collabora.co.uk>
Reviewed-by: default avatarCosimo Alfarano <cosimo.alfarano@collabora.co.uk>
parent 2e23700b
......@@ -28,8 +28,59 @@
#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)
......
......@@ -207,47 +207,6 @@ _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;
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
*
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment