From ab0854c413e4ea48af8795710867d43da031f6d9 Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Tue, 19 Feb 2013 15:46:02 +0000 Subject: [PATCH 3/8] Move _dbus_string_get_dirname into the shared library DBusServer is about to need it. --- dbus/dbus-string-util.c | 37 --------------------- dbus/dbus-string.c | 38 +++++++++++++++++++++ dbus/dbus-sysdeps-unix.c | 54 ++++++++++++++++++++++++++++++ dbus/dbus-sysdeps-util-unix.c | 54 ------------------------------ dbus/dbus-sysdeps-util-win.c | 74 ----------------------------------------- dbus/dbus-sysdeps-win.c | 74 +++++++++++++++++++++++++++++++++++++++++ 6 files changed, 166 insertions(+), 165 deletions(-) diff --git a/dbus/dbus-string-util.c b/dbus/dbus-string-util.c index 922580d..8bb863e 100644 --- a/dbus/dbus-string-util.c +++ b/dbus/dbus-string-util.c @@ -76,43 +76,6 @@ _dbus_string_ends_with_c_str (const DBusString *a, return TRUE; } -/** - * Find the given byte scanning backward from the given start. - * Sets *found to -1 if the byte is not found. - * - * @param str the string - * @param start the place to start scanning (will not find the byte at this point) - * @param byte the byte to find - * @param found return location for where it was found - * @returns #TRUE if found - */ -dbus_bool_t -_dbus_string_find_byte_backward (const DBusString *str, - int start, - unsigned char byte, - int *found) -{ - int i; - DBUS_CONST_STRING_PREAMBLE (str); - _dbus_assert (start <= real->len); - _dbus_assert (start >= 0); - _dbus_assert (found != NULL); - - i = start - 1; - while (i >= 0) - { - if (real->str[i] == byte) - break; - - --i; - } - - if (found) - *found = i; - - return i >= 0; -} - /** @} */ #ifdef DBUS_BUILD_TESTS diff --git a/dbus/dbus-string.c b/dbus/dbus-string.c index 9accdb1..54a384f 100644 --- a/dbus/dbus-string.c +++ b/dbus/dbus-string.c @@ -2693,6 +2693,44 @@ _dbus_string_zero (DBusString *str) memset (real->str - real->align_offset, '\0', real->allocated); } + +/** + * Find the given byte scanning backward from the given start. + * Sets *found to -1 if the byte is not found. + * + * @param str the string + * @param start the place to start scanning (will not find the byte at this point) + * @param byte the byte to find + * @param found return location for where it was found + * @returns #TRUE if found + */ +dbus_bool_t +_dbus_string_find_byte_backward (const DBusString *str, + int start, + unsigned char byte, + int *found) +{ + int i; + DBUS_CONST_STRING_PREAMBLE (str); + _dbus_assert (start <= real->len); + _dbus_assert (start >= 0); + _dbus_assert (found != NULL); + + i = start - 1; + while (i >= 0) + { + if (real->str[i] == byte) + break; + + --i; + } + + if (found) + *found = i; + + return i >= 0; +} + /** @} */ /* tests are in dbus-string-util.c */ diff --git a/dbus/dbus-sysdeps-unix.c b/dbus/dbus-sysdeps-unix.c index a031059..654eaee 100644 --- a/dbus/dbus-sysdeps-unix.c +++ b/dbus/dbus-sysdeps-unix.c @@ -4225,4 +4225,58 @@ _dbus_append_address_from_socket (int fd, return FALSE; } +/** + * @addtogroup DBusString + * + * @{ + */ +/** + * Get the directory name from a complete filename + * @param filename the filename + * @param dirname string to append directory name to + * @returns #FALSE if no memory + */ +dbus_bool_t +_dbus_string_get_dirname (const DBusString *filename, + DBusString *dirname) +{ + int sep; + + _dbus_assert (filename != dirname); + _dbus_assert (filename != NULL); + _dbus_assert (dirname != NULL); + + /* Ignore any separators on the end */ + sep = _dbus_string_get_length (filename); + if (sep == 0) + return _dbus_string_append (dirname, "."); /* empty string passed in */ + + while (sep > 0 && _dbus_string_get_byte (filename, sep - 1) == '/') + --sep; + + _dbus_assert (sep >= 0); + + if (sep == 0) + return _dbus_string_append (dirname, "/"); + + /* Now find the previous separator */ + _dbus_string_find_byte_backward (filename, sep, '/', &sep); + if (sep < 0) + return _dbus_string_append (dirname, "."); + + /* skip multiple separators */ + while (sep > 0 && _dbus_string_get_byte (filename, sep - 1) == '/') + --sep; + + _dbus_assert (sep >= 0); + + if (sep == 0 && + _dbus_string_get_byte (filename, 0) == '/') + return _dbus_string_append (dirname, "/"); + else + return _dbus_string_copy_len (filename, 0, sep - 0, + dirname, _dbus_string_get_length (dirname)); +} +/** @} */ /* DBusString stuff */ + /* tests in dbus-sysdeps-util.c */ diff --git a/dbus/dbus-sysdeps-util-unix.c b/dbus/dbus-sysdeps-util-unix.c index 6cff3fe..82c6a65 100644 --- a/dbus/dbus-sysdeps-util-unix.c +++ b/dbus/dbus-sysdeps-util-unix.c @@ -1012,60 +1012,6 @@ _dbus_windows_user_is_process_owner (const char *windows_sid) /** @} */ /* End of DBusInternalsUtils functions */ -/** - * @addtogroup DBusString - * - * @{ - */ -/** - * Get the directory name from a complete filename - * @param filename the filename - * @param dirname string to append directory name to - * @returns #FALSE if no memory - */ -dbus_bool_t -_dbus_string_get_dirname (const DBusString *filename, - DBusString *dirname) -{ - int sep; - - _dbus_assert (filename != dirname); - _dbus_assert (filename != NULL); - _dbus_assert (dirname != NULL); - - /* Ignore any separators on the end */ - sep = _dbus_string_get_length (filename); - if (sep == 0) - return _dbus_string_append (dirname, "."); /* empty string passed in */ - - while (sep > 0 && _dbus_string_get_byte (filename, sep - 1) == '/') - --sep; - - _dbus_assert (sep >= 0); - - if (sep == 0) - return _dbus_string_append (dirname, "/"); - - /* Now find the previous separator */ - _dbus_string_find_byte_backward (filename, sep, '/', &sep); - if (sep < 0) - return _dbus_string_append (dirname, "."); - - /* skip multiple separators */ - while (sep > 0 && _dbus_string_get_byte (filename, sep - 1) == '/') - --sep; - - _dbus_assert (sep >= 0); - - if (sep == 0 && - _dbus_string_get_byte (filename, 0) == '/') - return _dbus_string_append (dirname, "/"); - else - return _dbus_string_copy_len (filename, 0, sep - 0, - dirname, _dbus_string_get_length (dirname)); -} -/** @} */ /* DBusString stuff */ - static void string_squash_nonprintable (DBusString *str) { diff --git a/dbus/dbus-sysdeps-util-win.c b/dbus/dbus-sysdeps-util-win.c index 111db9e..0366a9a 100644 --- a/dbus/dbus-sysdeps-util-win.c +++ b/dbus/dbus-sysdeps-util-win.c @@ -685,78 +685,6 @@ _dbus_directory_close (DBusDirIter *iter) /** @} */ /* End of DBusInternalsUtils functions */ /** - * @addtogroup DBusString - * - * @{ - */ -/** - * Get the directory name from a complete filename - * @param filename the filename - * @param dirname string to append directory name to - * @returns #FALSE if no memory - */ -dbus_bool_t -_dbus_string_get_dirname(const DBusString *filename, - DBusString *dirname) -{ - int sep; - - _dbus_assert (filename != dirname); - _dbus_assert (filename != NULL); - _dbus_assert (dirname != NULL); - - /* Ignore any separators on the end */ - sep = _dbus_string_get_length (filename); - if (sep == 0) - return _dbus_string_append (dirname, "."); /* empty string passed in */ - - while (sep > 0 && - (_dbus_string_get_byte (filename, sep - 1) == '/' || - _dbus_string_get_byte (filename, sep - 1) == '\\')) - --sep; - - _dbus_assert (sep >= 0); - - if (sep == 0 || - (sep == 2 && - _dbus_string_get_byte (filename, 1) == ':' && - isalpha (_dbus_string_get_byte (filename, 0)))) - return _dbus_string_copy_len (filename, 0, sep + 1, - dirname, _dbus_string_get_length (dirname)); - - { - int sep1, sep2; - _dbus_string_find_byte_backward (filename, sep, '/', &sep1); - _dbus_string_find_byte_backward (filename, sep, '\\', &sep2); - - sep = MAX (sep1, sep2); - } - if (sep < 0) - return _dbus_string_append (dirname, "."); - - while (sep > 0 && - (_dbus_string_get_byte (filename, sep - 1) == '/' || - _dbus_string_get_byte (filename, sep - 1) == '\\')) - --sep; - - _dbus_assert (sep >= 0); - - if ((sep == 0 || - (sep == 2 && - _dbus_string_get_byte (filename, 1) == ':' && - isalpha (_dbus_string_get_byte (filename, 0)))) - && - (_dbus_string_get_byte (filename, sep) == '/' || - _dbus_string_get_byte (filename, sep) == '\\')) - return _dbus_string_copy_len (filename, 0, sep + 1, - dirname, _dbus_string_get_length (dirname)); - else - return _dbus_string_copy_len (filename, 0, sep - 0, - dirname, _dbus_string_get_length (dirname)); -} - - -/** * Checks to see if the UNIX user ID matches the UID of * the process. Should always return #FALSE on Windows. * @@ -848,8 +776,6 @@ _dbus_unix_groups_from_uid (dbus_uid_t uid, -/** @} */ /* DBusString stuff */ - /************************************************************************ error handling diff --git a/dbus/dbus-sysdeps-win.c b/dbus/dbus-sysdeps-win.c index 5a2fb20..1ff783f 100644 --- a/dbus/dbus-sysdeps-win.c +++ b/dbus/dbus-sysdeps-win.c @@ -3649,5 +3649,79 @@ _dbus_check_setuid (void) } /** @} end of sysdeps-win */ + +/** + * @addtogroup DBusString + * + * @{ + */ +/** + * Get the directory name from a complete filename + * @param filename the filename + * @param dirname string to append directory name to + * @returns #FALSE if no memory + */ +dbus_bool_t +_dbus_string_get_dirname(const DBusString *filename, + DBusString *dirname) +{ + int sep; + + _dbus_assert (filename != dirname); + _dbus_assert (filename != NULL); + _dbus_assert (dirname != NULL); + + /* Ignore any separators on the end */ + sep = _dbus_string_get_length (filename); + if (sep == 0) + return _dbus_string_append (dirname, "."); /* empty string passed in */ + + while (sep > 0 && + (_dbus_string_get_byte (filename, sep - 1) == '/' || + _dbus_string_get_byte (filename, sep - 1) == '\\')) + --sep; + + _dbus_assert (sep >= 0); + + if (sep == 0 || + (sep == 2 && + _dbus_string_get_byte (filename, 1) == ':' && + isalpha (_dbus_string_get_byte (filename, 0)))) + return _dbus_string_copy_len (filename, 0, sep + 1, + dirname, _dbus_string_get_length (dirname)); + + { + int sep1, sep2; + _dbus_string_find_byte_backward (filename, sep, '/', &sep1); + _dbus_string_find_byte_backward (filename, sep, '\\', &sep2); + + sep = MAX (sep1, sep2); + } + if (sep < 0) + return _dbus_string_append (dirname, "."); + + while (sep > 0 && + (_dbus_string_get_byte (filename, sep - 1) == '/' || + _dbus_string_get_byte (filename, sep - 1) == '\\')) + --sep; + + _dbus_assert (sep >= 0); + + if ((sep == 0 || + (sep == 2 && + _dbus_string_get_byte (filename, 1) == ':' && + isalpha (_dbus_string_get_byte (filename, 0)))) + && + (_dbus_string_get_byte (filename, sep) == '/' || + _dbus_string_get_byte (filename, sep) == '\\')) + return _dbus_string_copy_len (filename, 0, sep + 1, + dirname, _dbus_string_get_length (dirname)); + else + return _dbus_string_copy_len (filename, 0, sep - 0, + dirname, _dbus_string_get_length (dirname)); +} + +/** @} */ /* DBusString stuff */ + /* tests in dbus-sysdeps-util.c */ -- 1.7.10.4