From d9b6333d9040987333185fa74dec5e6a8bdc0949 Mon Sep 17 00:00:00 2001 From: Ralf Habacker Date: Fri, 5 Sep 2014 18:02:44 +0200 Subject: [PATCH 3/4] Add dbus string convenience function _dbus_string_init_from_string(). Bug: https://bugs.freedesktop.org/show_bug.cgi?id=57272 --- dbus/dbus-string.c | 17 +++++++++++++++++ dbus/dbus-string.h | 3 +++ 2 files changed, 20 insertions(+) diff --git a/dbus/dbus-string.c b/dbus/dbus-string.c index c4e2e7f..2001074 100644 --- a/dbus/dbus-string.c +++ b/dbus/dbus-string.c @@ -234,6 +234,23 @@ _dbus_string_init_const_len (DBusString *str, } /** + * Initializes a string from another string. The + * string must eventually be freed with _dbus_string_free(). + * + * @param str memory to hold the string + * @param from instance from which the string is initialized + * @returns #TRUE on success, #FALSE if no memory + */ +dbus_bool_t +_dbus_string_init_from_string(DBusString *str, + const DBusString *from) +{ + if (!_dbus_string_init (str)) + return FALSE; + return _dbus_string_append (str, _dbus_string_get_const_data (from)); +} + +/** * Frees a string created by _dbus_string_init(). * * @param str memory where the string is stored. diff --git a/dbus/dbus-string.h b/dbus/dbus-string.h index 86fb8c3..44860fe 100644 --- a/dbus/dbus-string.h +++ b/dbus/dbus-string.h @@ -75,6 +75,9 @@ void _dbus_string_init_const_len (DBusString *str, int len); dbus_bool_t _dbus_string_init_preallocated (DBusString *str, int allocate_size); + +dbus_bool_t _dbus_string_init_from_string (DBusString *str, + const DBusString *from); void _dbus_string_free (DBusString *str); void _dbus_string_lock (DBusString *str); dbus_bool_t _dbus_string_compact (DBusString *str, -- 1.8.4.5