X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=dbus%2Fdbus-sysdeps-util.c;h=6b361ef0d26decc82947945bb4590b51311576dd;hb=61d97215c317a4154df47fbfb882aab60b92fbab;hp=1f6ceb9b670004af131e6db0140e5ed44000ac91;hpb=ee721d13c455b5780af5989662ff7fca68374327;p=platform%2Fupstream%2Fdbus.git diff --git a/dbus/dbus-sysdeps-util.c b/dbus/dbus-sysdeps-util.c index 1f6ceb9..6b361ef 100644 --- a/dbus/dbus-sysdeps-util.c +++ b/dbus/dbus-sysdeps-util.c @@ -1,4 +1,4 @@ -/* -*- mode: C; c-file-style: "gnu" -*- */ +/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */ /* dbus-sysdeps-util.c Tests for dbus-sysdeps.h API * * Copyright (C) 2002, 2003, 2004, 2005 Red Hat, Inc. @@ -18,16 +18,69 @@ * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * */ + +#include #include "dbus-sysdeps.h" #include "dbus-internals.h" #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_ENABLE_EMBEDDED_TESTS static void check_dirname (const char *filename, const char *dirname) @@ -78,10 +131,6 @@ check_path_absolute (const char *path, dbus_bool_t _dbus_sysdeps_test (void) { - DBusString str; - double val; - int pos; - #ifdef DBUS_WIN check_dirname ("foo\\bar", "foo"); check_dirname ("foo\\\\bar", "foo"); @@ -123,42 +172,6 @@ _dbus_sysdeps_test (void) check_dirname ("", "."); #endif - _dbus_string_init_const (&str, "3.5"); - if (!_dbus_string_parse_double (&str, - 0, &val, &pos)) - { - _dbus_warn ("Failed to parse double"); - exit (1); - } - if (ABS(3.5 - val) > 1e-6) - { - _dbus_warn ("Failed to parse 3.5 correctly, got: %f", val); - exit (1); - } - if (pos != 3) - { - _dbus_warn ("_dbus_string_parse_double of \"3.5\" returned wrong position %d", pos); - exit (1); - } - - _dbus_string_init_const (&str, "0xff"); - if (!_dbus_string_parse_double (&str, - 0, &val, &pos)) - { - _dbus_warn ("Failed to parse double"); - exit (1); - } - if (ABS (0xff - val) > 1e-6) - { - _dbus_warn ("Failed to parse 0xff correctly, got: %f\n", val); - exit (1); - } - if (pos != 4) - { - _dbus_warn ("_dbus_string_parse_double of \"0xff\" returned wrong position %d", pos); - exit (1); - } - #ifdef DBUS_WIN check_path_absolute ("c:/", TRUE); check_path_absolute ("c:/foo", TRUE); @@ -183,4 +196,4 @@ _dbus_sysdeps_test (void) return TRUE; } -#endif /* DBUS_BUILD_TESTS */ +#endif /* DBUS_ENABLE_EMBEDDED_TESTS */