mirror of
https://gitlab.freedesktop.org/dbus/dbus.git
synced 2026-01-18 04:00:33 +01:00
_dbus_get_environment: move from shared library to dbus-sysdeps-util
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>
This commit is contained in:
parent
2e23700b39
commit
b129afbb7e
2 changed files with 52 additions and 42 deletions
|
|
@ -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
|
||||
*
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue