From fe510c586a3b51aca8ca57652fb9dcee4898d6da Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Thu, 10 Feb 2011 13:52:20 +0000 Subject: [PATCH 1/2] DBusString: add _dbus_string_get_allocated --- dbus/dbus-string.c | 16 ++++++++++++++++ dbus/dbus-string.h | 4 ++++ 2 files changed, 20 insertions(+), 0 deletions(-) diff --git a/dbus/dbus-string.c b/dbus/dbus-string.c index e2eb93b..bb5dba0 100644 --- a/dbus/dbus-string.c +++ b/dbus/dbus-string.c @@ -848,6 +848,22 @@ _dbus_string_get_length (const DBusString *str) } #endif /* !_dbus_string_get_length */ +/* Only have the function if we don't have the macro */ +#ifndef _dbus_string_get_allocated +/** + * Gets the length of a string (not including nul termination). + * + * @returns the length. + */ +int +_dbus_string_get_allocated (const DBusString *str) +{ + DBUS_CONST_STRING_PREAMBLE (str); + + return real->allocated; +} +#endif /* !_dbus_string_get_allocated */ + /** * Makes a string longer by the given number of bytes. Checks whether * adding additional_length to the current length would overflow an diff --git a/dbus/dbus-string.h b/dbus/dbus-string.h index 2f1ed31..ccd06a7 100644 --- a/dbus/dbus-string.h +++ b/dbus/dbus-string.h @@ -62,6 +62,7 @@ struct DBusString */ #define _dbus_string_get_data(s) ((char*)(((DBusString*)(s))->dummy1)) #define _dbus_string_get_length(s) (((DBusString*)(s))->dummy2) +#define _dbus_string_get_allocated(s) (((DBusString*)(s))->dummy2) #define _dbus_string_set_byte(s, i, b) ((((unsigned char*)(((DBusString*)(s))->dummy1))[(i)]) = (unsigned char) (b)) #define _dbus_string_get_byte(s, i) (((const unsigned char*)(((DBusString*)(s))->dummy1))[(i)]) #define _dbus_string_get_const_data(s) ((const char*)(((DBusString*)(s))->dummy1)) @@ -131,6 +132,9 @@ void _dbus_string_copy_to_buffer_with_nul (const DBusString *str, #ifndef _dbus_string_get_length int _dbus_string_get_length (const DBusString *str); #endif /* !_dbus_string_get_length */ +#ifndef _dbus_string_get_allocated +int _dbus_string_get_allocated (const DBusString *str); +#endif /* !_dbus_string_get_allocated */ dbus_bool_t _dbus_string_lengthen (DBusString *str, int additional_length); -- 1.7.4.1