diff options
author | Havoc Pennington <hp@redhat.com> | 2003-01-28 03:53:29 +0000 |
---|---|---|
committer | Havoc Pennington <hp@redhat.com> | 2003-01-28 03:53:29 +0000 |
commit | 05a4ad6994919b352b5229d0b1b0a8ebebe2a42f (patch) | |
tree | ef8adeefdea46a6ae4b673cd4014d5f8d2ea792b /dbus/dbus-string.c | |
parent | ee1133de4dc5e181be5d09f084d8823388d5f693 (diff) |
2003-01-27 Havoc Pennington <hp@pobox.com>
* dbus/dbus-mempool.c (time_for_size): replace printf with
_dbus_verbose
* dbus/dbus-message-builder.c (_dbus_message_data_load): allow
empty lines; fix the SAVE_LENGTH stuff to be
START_LENGTH/END_LENGTH so it actually works; couple other
bugfixes
* test/Makefile.am (dist-hook): add dist-hook for .message files
* dbus/dbus-string.c (DBUS_STRING_COPY_PREAMBLE): source of a copy
can be constant or locked.
(_dbus_string_free): allow freeing a const string as
documented/intended
* dbus/dbus-sysdeps.c (_dbus_concat_dir_and_file): utility
* dbus/dbus-test-main.c (main): take an argument which is the
directory containing test data
* dbus/dbus-message.c (_dbus_message_test): pass a test_data_dir
argument to this and load all the messages in test/data/
checking that they can be loaded or not loaded as appropriate.
Diffstat (limited to 'dbus/dbus-string.c')
-rw-r--r-- | dbus/dbus-string.c | 46 |
1 files changed, 42 insertions, 4 deletions
diff --git a/dbus/dbus-string.c b/dbus/dbus-string.c index ac84cda8..246c9a1d 100644 --- a/dbus/dbus-string.c +++ b/dbus/dbus-string.c @@ -252,11 +252,11 @@ _dbus_string_init_const_len (DBusString *str, void _dbus_string_free (DBusString *str) { - DBUS_LOCKED_STRING_PREAMBLE (str); + DBusRealString *real = (DBusRealString*) str; + DBUS_GENERIC_STRING_PREAMBLE (real); if (real->constant) return; - dbus_free (real->str); real->invalid = TRUE; @@ -864,8 +864,6 @@ copy (DBusRealString *source, _dbus_assert ((source) != (dest)); \ DBUS_GENERIC_STRING_PREAMBLE (real_source); \ DBUS_GENERIC_STRING_PREAMBLE (real_dest); \ - _dbus_assert (!real_source->constant); \ - _dbus_assert (!real_source->locked); \ _dbus_assert (!real_dest->constant); \ _dbus_assert (!real_dest->locked); \ _dbus_assert ((start) >= 0); \ @@ -1404,6 +1402,46 @@ _dbus_string_starts_with_c_str (const DBusString *a, return FALSE; } +/** + * Returns whether a string ends with the given suffix + * + * @param a the string + * @param c_str the C-style string + * @returns #TRUE if the string ends with the suffix + */ +dbus_bool_t +_dbus_string_ends_with_c_str (const DBusString *a, + const char *c_str) +{ + const unsigned char *ap; + const unsigned char *bp; + const unsigned char *a_end; + int c_str_len; + const DBusRealString *real_a = (const DBusRealString*) a; + DBUS_GENERIC_STRING_PREAMBLE (real_a); + + c_str_len = strlen (c_str); + if (real_a->len < c_str_len) + return FALSE; + + ap = real_a->str + (real_a->len - c_str_len); + bp = (const unsigned char*) c_str; + a_end = real_a->str + real_a->len; + while (ap != a_end) + { + if (*ap != *bp) + return FALSE; + + ++ap; + ++bp; + } + + _dbus_assert (*ap == '\0'); + _dbus_assert (*bp == '\0'); + + return TRUE; +} + static const signed char base64_table[] = { /* 0 */ 'A', /* 1 */ 'B', |