From ef9416e5c3c12bee483d74cddb752e68453e177f Mon Sep 17 00:00:00 2001 From: Ralf Habacker Date: Fri, 27 Nov 2015 12:54:48 +0100 Subject: [PATCH] Add new functions _dbus_string_array_replace() _dbus_string_array_append(). These functions are required by dbus-run-session on windows. Bug: https://bugs.freedesktop.org/show_bug.cgi?id=92899 --- dbus/dbus-internals.c | 58 +++++++++++++++++++++++++++++++++++++++++++++++++++ dbus/dbus-internals.h | 7 +++++++ 2 files changed, 65 insertions(+) diff --git a/dbus/dbus-internals.c b/dbus/dbus-internals.c index 0c52995..b4b4967 100644 --- a/dbus/dbus-internals.c +++ b/dbus/dbus-internals.c @@ -655,6 +655,64 @@ _dbus_string_array_length (const char **array) return i; } +/** + * Replace complete string from a string array + * + * @param array array to search. + * @param search string to search for. + * @returns replace string to replace. + * @returns TRUE if search string has been found, FALSE otherwise. + */ +dbus_bool_t +_dbus_string_array_replace (const char **array, const char *search, const char *replace) +{ + size_t i, len = _dbus_string_array_length (array); + for (i=0 ; i < len; i++) + { + if (strstr (array[i], search)) + { + char *s = _dbus_strdup (replace); + if (!s) + return FALSE; + dbus_free ((char *)array[i]); + array[i] = s; + return TRUE; + } + } + return FALSE; +} + +/** + * Append string to a string array + * + * @param array array to append string. + * @param append string to append. + * @returns new string array or NULL in case of errors. + */ +char ** +_dbus_string_array_append (char **array, const char *append) +{ + size_t len, i; + char **copy; + + if (!array) + return NULL; + + len = _dbus_string_array_length ((const char **) array); + copy = dbus_new0 (char *, len +1); + if (!copy) + return NULL; + + for (i=0 ; i < len; i++) + { + copy[i] = array[i]; + } + copy[len] = _dbus_strdup (append); + copy[len+1] = NULL; + + dbus_free (array); + return copy; +} /** * Generates a new UUID. If you change how this is done, diff --git a/dbus/dbus-internals.h b/dbus/dbus-internals.h index 6f92fa4..5e08762 100644 --- a/dbus/dbus-internals.h +++ b/dbus/dbus-internals.h @@ -248,6 +248,13 @@ dbus_bool_t _dbus_string_array_contains (const char **array, const char *str); DBUS_PRIVATE_EXPORT size_t _dbus_string_array_length (const char **array); +DBUS_PRIVATE_EXPORT +dbus_bool_t _dbus_string_array_replace (const char **array, + const char *search, + const char *replace); +DBUS_PRIVATE_EXPORT +char ** _dbus_string_array_append (char **array, + const char *append); char** _dbus_dup_string_array (const char **array); #define _DBUS_INT16_MIN ((dbus_int16_t) 0x8000) -- 1.8.4.5