diff --git a/gio/xdgmime/xdgmime.c b/gio/xdgmime/xdgmime.c index 846be39f7..f73b7f213 100644 --- a/gio/xdgmime/xdgmime.c +++ b/gio/xdgmime/xdgmime.c @@ -741,19 +741,28 @@ xdg_mime_media_type_equal (const char *mime_a, #if 1 static int -xdg_mime_is_super_type (const char *mime) +ends_with (const char *str, + const char *suffix) { int length; - const char *type; + int suffix_length; - length = strlen (mime); - type = &(mime[length - 2]); + length = strlen (str); + suffix_length = strlen (suffix); + if (length < suffix_length) + return 0; - if (strcmp (type, "/*") == 0) + if (strcmp (str + length - suffix_length, suffix) == 0) return 1; return 0; } + +static int +xdg_mime_is_super_type (const char *mime) +{ + return ends_with (mime, "/*"); +} #endif int diff --git a/gio/xdgmime/xdgmimecache.c b/gio/xdgmime/xdgmimecache.c index 87a3cd00b..3a64debd7 100644 --- a/gio/xdgmime/xdgmimecache.c +++ b/gio/xdgmime/xdgmimecache.c @@ -837,19 +837,28 @@ _xdg_mime_cache_get_mime_types_from_file_name (const char *file_name, #if 1 static int -is_super_type (const char *mime) +ends_with (const char *str, + const char *suffix) { int length; - const char *type; + int suffix_length; - length = strlen (mime); - type = &(mime[length - 2]); + length = strlen (str); + suffix_length = strlen (suffix); + if (length < suffix_length) + return 0; - if (strcmp (type, "/*") == 0) + if (strcmp (str + length - suffix_length, suffix) == 0) return 1; return 0; } + +static int +is_super_type (const char *mime) +{ + return ends_with (mime, "/*"); +} #endif int