summaryrefslogtreecommitdiffstats
path: root/dbus/dbus-string.c
diff options
context:
space:
mode:
Diffstat (limited to 'dbus/dbus-string.c')
-rw-r--r--dbus/dbus-string.c24
1 files changed, 24 insertions, 0 deletions
diff --git a/dbus/dbus-string.c b/dbus/dbus-string.c
index 5088bca9..86d3eb83 100644
--- a/dbus/dbus-string.c
+++ b/dbus/dbus-string.c
@@ -708,6 +708,30 @@ _dbus_string_copy_data (const DBusString *str,
return TRUE;
}
+/**
+ * Copies the contents of a DBusString into a different
+ * buffer. The resulting buffer will be nul-terminated.
+ *
+ * @param str a string
+ * @param buffer a C buffer to copy data to
+ * @param avail_len maximum length of C buffer
+ */
+void
+_dbus_string_copy_to_buffer (const DBusString *str,
+ char *buffer,
+ int avail_len)
+{
+ int copy_len;
+ DBUS_CONST_STRING_PREAMBLE (str);
+
+ _dbus_assert (avail_len >= 0);
+
+ copy_len = MIN (avail_len, real->len+1);
+ memcpy (buffer, real->str, copy_len);
+ if (avail_len > 0 && avail_len == copy_len)
+ buffer[avail_len-1] = '\0';
+}
+
#ifdef DBUS_BUILD_TESTS
/**
* Copies a segment of the string into a char*