X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=gio%2Fgdummyfile.c;h=4ac3bd9b36ef7382a04cd9a81e45e1e8e1167a9f;hb=7fd6f07d498063470903a886b4805a13bd333908;hp=d2dd249aabe8061700d3933bf9f7634233f828c8;hpb=7f3280230bc9448a5750fc17a6eabef691ba25f4;p=platform%2Fupstream%2Fglib.git diff --git a/gio/gdummyfile.c b/gio/gdummyfile.c index d2dd249..4ac3bd9 100644 --- a/gio/gdummyfile.c +++ b/gio/gdummyfile.c @@ -13,28 +13,25 @@ * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General - * Public License along with this library; if not, write to the - * Free Software Foundation, Inc., 59 Temple Place, Suite 330, - * Boston, MA 02111-1307, USA. + * Public License along with this library; if not, see . * * Author: Alexander Larsson */ -#include +#include "config.h" #include #include #include #include #include -#include #include #include "gdummyfile.h" +#include "gfile.h" -#include "gioalias.h" -static void g_dummy_file_file_iface_init (GFileIface *iface); +static void g_dummy_file_file_iface_init (GFileIface *iface); typedef struct { char *scheme; @@ -54,6 +51,7 @@ struct _GDummyFile char *text_uri; }; +#define g_dummy_file_get_type _g_dummy_file_get_type G_DEFINE_TYPE_WITH_CODE (GDummyFile, g_dummy_file, G_TYPE_OBJECT, G_IMPLEMENT_INTERFACE (G_TYPE_FILE, g_dummy_file_file_iface_init)) @@ -69,7 +67,8 @@ static char * unescape_string (const gchar *escaped_string, const gchar *escaped_string_end, const gchar *illegal_characters); -static void g_string_append_encoded (GString *string, const char *encoded, +static void g_string_append_encoded (GString *string, + const char *encoded, const char *reserved_chars_allowed); static void @@ -83,9 +82,8 @@ g_dummy_file_finalize (GObject *object) _g_decoded_uri_free (dummy->decoded_uri); g_free (dummy->text_uri); - - if (G_OBJECT_CLASS (g_dummy_file_parent_class)->finalize) - (*G_OBJECT_CLASS (g_dummy_file_parent_class)->finalize) (object); + + G_OBJECT_CLASS (g_dummy_file_parent_class)->finalize (object); } static void @@ -101,14 +99,8 @@ g_dummy_file_init (GDummyFile *dummy) { } -/** - * g_dummy_file_new: - * @uri: Universal Resource Identifier for the dummy file object. - * - * Returns: a new #GFile. - **/ GFile * -g_dummy_file_new (const char *uri) +_g_dummy_file_new (const char *uri) { GDummyFile *dummy; @@ -140,10 +132,6 @@ g_dummy_file_get_basename (GFile *file) static char * g_dummy_file_get_path (GFile *file) { - GDummyFile *dummy = G_DUMMY_FILE (file); - - if (dummy->decoded_uri) - return g_strdup (dummy->decoded_uri->path); return NULL; } @@ -168,7 +156,8 @@ g_dummy_file_get_parent (GFile *file) char *uri; GDecodedUri new_decoded_uri; - if (dummy->decoded_uri == NULL) + if (dummy->decoded_uri == NULL || + g_strcmp0 (dummy->decoded_uri->path, "/") == 0) return NULL; dirname = g_path_get_dirname (dummy->decoded_uri->path); @@ -184,7 +173,7 @@ g_dummy_file_get_parent (GFile *file) uri = _g_encode_uri (&new_decoded_uri); g_free (dirname); - parent = g_dummy_file_new (uri); + parent = _g_dummy_file_new (uri); g_free (uri); return parent; @@ -195,7 +184,7 @@ g_dummy_file_dup (GFile *file) { GDummyFile *dummy = G_DUMMY_FILE (file); - return g_dummy_file_new (dummy->text_uri); + return _g_dummy_file_new (dummy->text_uri); } static guint @@ -217,7 +206,8 @@ g_dummy_file_equal (GFile *file1, } static int -safe_strcmp (const char *a, const char *b) +safe_strcmp (const char *a, + const char *b) { if (a == NULL) a = ""; @@ -244,7 +234,8 @@ uri_same_except_path (GDecodedUri *a, } static const char * -match_prefix (const char *path, const char *prefix) +match_prefix (const char *path, + const char *prefix) { int prefix_len; @@ -255,8 +246,7 @@ match_prefix (const char *path, const char *prefix) } static gboolean -g_dummy_file_contains_file (GFile *parent, - GFile *descendant) +g_dummy_file_prefix_matches (GFile *parent, GFile *descendant) { GDummyFile *parent_dummy = G_DUMMY_FILE (parent); GDummyFile *descendant_dummy = G_DUMMY_FILE (descendant); @@ -266,17 +256,18 @@ g_dummy_file_contains_file (GFile *parent, descendant_dummy->decoded_uri != NULL) { if (uri_same_except_path (parent_dummy->decoded_uri, - descendant_dummy->decoded_uri)) { - remainder = match_prefix (descendant_dummy->decoded_uri->path, - parent_dummy->decoded_uri->path); - if (remainder != NULL && *remainder == '/') - { - while (*remainder == '/') - remainder++; - if (*remainder != 0) - return TRUE; - } - } + descendant_dummy->decoded_uri)) + { + remainder = match_prefix (descendant_dummy->decoded_uri->path, + parent_dummy->decoded_uri->path); + if (remainder != NULL && *remainder == '/') + { + while (*remainder == '/') + remainder++; + if (*remainder != 0) + return TRUE; + } + } } else { @@ -306,17 +297,18 @@ g_dummy_file_get_relative_path (GFile *parent, descendant_dummy->decoded_uri != NULL) { if (uri_same_except_path (parent_dummy->decoded_uri, - descendant_dummy->decoded_uri)) { - remainder = match_prefix (descendant_dummy->decoded_uri->path, - parent_dummy->decoded_uri->path); - if (remainder != NULL && *remainder == '/') - { - while (*remainder == '/') - remainder++; - if (*remainder != 0) - return g_strdup (remainder); - } - } + descendant_dummy->decoded_uri)) + { + remainder = match_prefix (descendant_dummy->decoded_uri->path, + parent_dummy->decoded_uri->path); + if (remainder != NULL && *remainder == '/') + { + while (*remainder == '/') + remainder++; + if (*remainder != 0) + return g_strdup (remainder); + } + } } else { @@ -336,7 +328,7 @@ g_dummy_file_get_relative_path (GFile *parent, static GFile * -g_dummy_file_resolve_relative_path (GFile *file, +g_dummy_file_resolve_relative_path (GFile *file, const char *relative_path) { GDummyFile *dummy = G_DUMMY_FILE (file); @@ -350,7 +342,7 @@ g_dummy_file_resolve_relative_path (GFile *file, str = g_string_new (dummy->text_uri); g_string_append (str, "/"); g_string_append_encoded (str, relative_path, SUB_DELIM_CHARS ":@/"); - child = g_dummy_file_new (str->str); + child = _g_dummy_file_new (str->str); g_string_free (str, TRUE); } else @@ -365,7 +357,7 @@ g_dummy_file_resolve_relative_path (GFile *file, uri = _g_encode_uri (&new_decoded_uri); g_free (new_decoded_uri.path); - child = g_dummy_file_new (uri); + child = _g_dummy_file_new (uri); g_free (uri); } @@ -417,10 +409,12 @@ g_dummy_file_file_iface_init (GFileIface *iface) iface->get_uri = g_dummy_file_get_uri; iface->get_parse_name = g_dummy_file_get_parse_name; iface->get_parent = g_dummy_file_get_parent; - iface->contains_file = g_dummy_file_contains_file; + iface->prefix_matches = g_dummy_file_prefix_matches; iface->get_relative_path = g_dummy_file_get_relative_path; iface->resolve_relative_path = g_dummy_file_resolve_relative_path; iface->get_child_for_display_name = g_dummy_file_get_child_for_display_name; + + iface->supports_thread_contexts = TRUE; } /* Uri handling helper functions: */ @@ -460,33 +454,35 @@ unescape_string (const gchar *escaped_string, result = g_malloc (escaped_string_end - escaped_string + 1); out = result; - for (in = escaped_string; in < escaped_string_end; in++) { - character = *in; - if (*in == '%') { - in++; - if (escaped_string_end - in < 2) - { - g_free (result); - return NULL; - } + for (in = escaped_string; in < escaped_string_end; in++) + { + character = *in; + if (*in == '%') + { + in++; + if (escaped_string_end - in < 2) + { + g_free (result); + return NULL; + } - character = unescape_character (in); + character = unescape_character (in); - /* Check for an illegal character. We consider '\0' illegal here. */ - if (character <= 0 || - (illegal_characters != NULL && - strchr (illegal_characters, (char)character) != NULL)) - { - g_free (result); - return NULL; - } - in++; /* The other char will be eaten in the loop header */ + /* Check for an illegal character. We consider '\0' illegal here. */ + if (character <= 0 || + (illegal_characters != NULL && + strchr (illegal_characters, (char)character) != NULL)) + { + g_free (result); + return NULL; + } + in++; /* The other char will be eaten in the loop header */ + } + *out++ = (char)character; } - *out++ = (char)character; - } *out = '\0'; - g_assert (out - result <= strlen (escaped_string)); + g_warn_if_fail (out - result <= strlen (escaped_string)); return result; } @@ -682,15 +678,13 @@ is_valid (char c, const char *reserved_chars_allowed) } static void -g_string_append_encoded (GString *string, const char *encoded, +g_string_append_encoded (GString *string, + const char *encoded, const char *reserved_chars_allowed) { unsigned char c; - const char *end; static const gchar hex[16] = "0123456789ABCDEF"; - end = encoded + strlen (encoded); - while ((c = *encoded) != 0) { if (is_valid (c, reserved_chars_allowed))