Tizen 2.1 base
[platform/upstream/glib2.0.git] / gio / gfileinfo.c
index 23cc888..3e957b9 100644 (file)
@@ -1,5 +1,5 @@
 /* GIO - GLib Input, Output and Streaming Library
- * 
+ *
  * Copyright (C) 2006-2007 Red Hat, Inc.
  *
  * This library is free software; you can redistribute it and/or
@@ -62,7 +62,6 @@
 #include "gicon.h"
 #include "glibintl.h"
 
-#include "gioalias.h"
 
 /* We use this nasty thing, because NULL is a valid attribute matcher (matches nothing) */
 #define NO_ATTRIBUTE_MASK ((GFileAttributeMatcher *)1)
@@ -101,8 +100,8 @@ static char ***attributes = NULL;
 
 /* Attribute ids are 32bit, we split it up like this:
  * |------------|--------------------|
- *   12 bit          20 bit       
- *   namespace      attribute id    
+ *   12 bit          20 bit
+ *   namespace      attribute id
  *
  * This way the attributes gets sorted in namespace order
  */
@@ -125,7 +124,7 @@ static NSInfo *
 _lookup_namespace (const char *namespace)
 {
   NSInfo *ns_info;
-  
+
   ns_info = g_hash_table_lookup (ns_hash, namespace);
   if (ns_info == NULL)
     {
@@ -133,7 +132,8 @@ _lookup_namespace (const char *namespace)
       ns_info->id = ++namespace_id_counter;
       g_hash_table_insert (ns_hash, g_strdup (namespace), ns_info);
       attributes = g_realloc (attributes, (ns_info->id + 1) * sizeof (char **));
-      attributes[ns_info->id] = NULL;
+      attributes[ns_info->id] = g_new (char *, 1);
+      attributes[ns_info->id][0] = g_strconcat (namespace, "::*", NULL);
     }
   return ns_info;
 }
@@ -145,7 +145,7 @@ _lookup_attribute (const char *attribute)
   char *ns;
   const char *colon;
   NSInfo *ns_info;
-  
+
   attr_id = GPOINTER_TO_UINT (g_hash_table_lookup (attribute_hash, attribute));
 
   if (attr_id != 0)
@@ -163,7 +163,7 @@ _lookup_attribute (const char *attribute)
   id = ++ns_info->attribute_id_counter;
   attributes[ns_info->id] = g_realloc (attributes[ns_info->id], (id + 1) * sizeof (char *));
   attributes[ns_info->id][id] = g_strdup (attribute);
-  
+
   attr_id = MAKE_ATTR_ID (ns_info->id, id);
 
   g_hash_table_insert (attribute_hash, attributes[ns_info->id][id], GUINT_TO_POINTER (attr_id));
@@ -270,16 +270,16 @@ lookup_namespace (const char *namespace)
 {
   NSInfo *ns_info;
   guint32 id;
-  
+
   G_LOCK (attribute_hash);
-  
+
   ensure_attribute_hash ();
 
   ns_info = _lookup_namespace (namespace);
   id = 0;
   if (ns_info)
     id = ns_info->id;
-  
+
   G_UNLOCK (attribute_hash);
 
   return id;
@@ -299,14 +299,14 @@ static guint32
 lookup_attribute (const char *attribute)
 {
   guint32 attr_id;
-  
+
   G_LOCK (attribute_hash);
   ensure_attribute_hash ();
 
   attr_id = _lookup_attribute (attribute);
-  
+
   G_UNLOCK (attribute_hash);
-  
+
   return attr_id;
 }
 
@@ -334,7 +334,7 @@ static void
 g_file_info_class_init (GFileInfoClass *klass)
 {
   GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
-  
+
   gobject_class->finalize = g_file_info_finalize;
 }
 
@@ -348,9 +348,9 @@ g_file_info_init (GFileInfo *info)
 
 /**
  * g_file_info_new:
- * 
+ *
  * Creates a new file info structure.
- * 
+ *
  * Returns: a #GFileInfo.
  **/
 GFileInfo *
@@ -363,11 +363,12 @@ g_file_info_new (void)
  * g_file_info_copy_into:
  * @src_info: source to copy attributes from.
  * @dest_info: destination to copy attributes to.
- * 
- * Copies all of the #GFileAttribute<!-- -->s from @src_info to @dest_info.
+ *
+ * Copies all of the <link linkend="gio-GFileAttribute">GFileAttribute</link>s
+ * from @src_info to @dest_info.
  **/
 void
-g_file_info_copy_into (GFileInfo *src_info, 
+g_file_info_copy_into (GFileInfo *src_info,
                        GFileInfo *dest_info)
 {
   GFileAttribute *source, *dest;
@@ -379,13 +380,13 @@ g_file_info_copy_into (GFileInfo *src_info,
   dest = (GFileAttribute *)dest_info->attributes->data;
   for (i = 0; i < dest_info->attributes->len; i++)
     _g_file_attribute_value_clear (&dest[i].value);
-  
+
   g_array_set_size (dest_info->attributes,
                    src_info->attributes->len);
 
   source = (GFileAttribute *)src_info->attributes->data;
   dest = (GFileAttribute *)dest_info->attributes->data;
-  
+
   for (i = 0; i < src_info->attributes->len; i++)
     {
       dest[i].attribute = source[i].attribute;
@@ -405,18 +406,18 @@ g_file_info_copy_into (GFileInfo *src_info,
 /**
  * g_file_info_dup:
  * @other: a #GFileInfo.
- * 
+ *
  * Duplicates a file info structure.
- * 
- * Returns: a duplicate #GFileInfo of @other.
+ *
+ * Returns: (transfer full): a duplicate #GFileInfo of @other.
  **/
 GFileInfo *
 g_file_info_dup (GFileInfo *other)
 {
   GFileInfo *new;
-  
+
   g_return_val_if_fail (G_IS_FILE_INFO (other), NULL);
-  
+
   new = g_file_info_new ();
   g_file_info_copy_into (other, new);
   return new;
@@ -435,9 +436,9 @@ g_file_info_set_attribute_mask (GFileInfo             *info,
 {
   GFileAttribute *attr;
   int i;
-  
+
   g_return_if_fail (G_IS_FILE_INFO (info));
-  
+
   if (mask != info->mask)
     {
       if (info->mask != NO_ATTRIBUTE_MASK)
@@ -462,7 +463,7 @@ g_file_info_set_attribute_mask (GFileInfo             *info,
 /**
  * g_file_info_unset_attribute_mask:
  * @info: #GFileInfo.
- * 
+ *
  * Unsets a mask set by g_file_info_set_attribute_mask(), if one
  * is set.
  **/
@@ -487,7 +488,7 @@ g_file_info_clear_status (GFileInfo  *info)
 {
   GFileAttribute *attrs;
   int i;
-  
+
   g_return_if_fail (G_IS_FILE_INFO (info));
 
   attrs = (GFileAttribute *)info->attributes->data;
@@ -538,7 +539,7 @@ g_file_info_find_value (GFileInfo *info,
   if (i < info->attributes->len &&
       attrs[i].attribute == attr_id)
     return &attrs[i].value;
-  
+
   return NULL;
 }
 
@@ -556,10 +557,10 @@ g_file_info_find_value_by_name (GFileInfo  *info,
  * g_file_info_has_attribute:
  * @info: a #GFileInfo.
  * @attribute: a file attribute key.
- * 
+ *
  * Checks if a file info structure has an attribute named @attribute.
- * 
- * Returns: %TRUE if @Ginfo has an attribute named @attribute, 
+ *
+ * Returns: %TRUE if @Ginfo has an attribute named @attribute,
  *     %FALSE otherwise.
  **/
 gboolean
@@ -615,11 +616,11 @@ g_file_info_has_namespace (GFileInfo  *info,
  * g_file_info_list_attributes:
  * @info: a #GFileInfo.
  * @name_space: a file attribute key's namespace.
- * 
+ *
  * Lists the file info structure's attributes.
- * 
- * Returns: a null-terminated array of strings of all of the 
- * possible attribute types for the given @name_space, or 
+ *
+ * Returns: (array zero-terminated=1) (transfer full): a null-terminated array of strings of all of the
+ * possible attribute types for the given @name_space, or
  * %NULL on error.
  **/
 char **
@@ -631,7 +632,7 @@ g_file_info_list_attributes (GFileInfo  *info,
   guint32 attribute;
   guint32 ns_id = (name_space) ? lookup_namespace (name_space) : 0;
   int i;
+
   g_return_val_if_fail (G_IS_FILE_INFO (info), NULL);
 
   names = g_ptr_array_new ();
@@ -645,7 +646,7 @@ g_file_info_list_attributes (GFileInfo  *info,
 
   /* NULL terminate */
   g_ptr_array_add (names, NULL);
-  
+
   return (char **)g_ptr_array_free (names, FALSE);
 }
 
@@ -653,10 +654,10 @@ g_file_info_list_attributes (GFileInfo  *info,
  * g_file_info_get_attribute_type:
  * @info: a #GFileInfo.
  * @attribute: a file attribute key.
- * 
+ *
  * Gets the attribute type for an attribute key.
- * 
- * Returns: a #GFileAttributeType for the given @attribute, or 
+ *
+ * Returns: a #GFileAttributeType for the given @attribute, or
  * %G_FILE_ATTRIBUTE_TYPE_INVALID if the key is not set.
  **/
 GFileAttributeType
@@ -664,7 +665,7 @@ g_file_info_get_attribute_type (GFileInfo  *info,
                                const char *attribute)
 {
   GFileAttributeValue *value;
-  
+
   g_return_val_if_fail (G_IS_FILE_INFO (info), G_FILE_ATTRIBUTE_TYPE_INVALID);
   g_return_val_if_fail (attribute != NULL && *attribute != '\0', G_FILE_ATTRIBUTE_TYPE_INVALID);
 
@@ -679,7 +680,7 @@ g_file_info_get_attribute_type (GFileInfo  *info,
  * g_file_info_remove_attribute:
  * @info: a #GFileInfo.
  * @attribute: a file attribute key.
- * 
+ *
  * Removes all cases of @attribute from @info if it exists.
  **/
 void
@@ -694,7 +695,7 @@ g_file_info_remove_attribute (GFileInfo  *info,
   g_return_if_fail (attribute != NULL && *attribute != '\0');
 
   attr_id = lookup_attribute (attribute);
-  
+
   i = g_file_info_find_place (info, attr_id);
   attrs = (GFileAttribute *)info->attributes->data;
   if (i < info->attributes->len &&
@@ -709,13 +710,13 @@ g_file_info_remove_attribute (GFileInfo  *info,
  * g_file_info_get_attribute_data:
  * @info: a #GFileInfo
  * @attribute: a file attribute key
- * @type: return location for the attribute type, or %NULL
- * @value_pp: return location for the attribute value, or %NULL
- * @status: return location for the attribute status, or %NULL
+ * @type: (out) (allow-none): return location for the attribute type, or %NULL
+ * @value_pp: (out) (allow-none): return location for the attribute value, or %NULL
+ * @status: (out) (allow-none): return location for the attribute status, or %NULL
  *
  * Gets the attribute type, value and status for an attribute key.
  *
- * Returns: %TRUE if @info has an attribute named @attribute, 
+ * Returns: (transfer none): %TRUE if @info has an attribute named @attribute,
  *      %FALSE otherwise.
  */
 gboolean
@@ -739,18 +740,18 @@ g_file_info_get_attribute_data (GFileInfo            *info,
 
   if (value_pp)
     *value_pp = _g_file_attribute_value_peek_as_pointer (value);
-  
+
   return TRUE;
 }
 
-/** 
+/**
  * g_file_info_get_attribute_status:
  * @info: a #GFileInfo
  * @attribute: a file attribute key
  *
  * Gets the attribute status for an attribute key.
  *
- * Returns: a #GFileAttributeStatus for the given @attribute, or 
+ * Returns: a #GFileAttributeStatus for the given @attribute, or
  *    %G_FILE_ATTRIBUTE_STATUS_UNSET if the key is invalid.
  *
  */
@@ -759,7 +760,7 @@ g_file_info_get_attribute_status (GFileInfo  *info,
                                  const char *attribute)
 {
   GFileAttributeValue *val;
-  
+
   g_return_val_if_fail (G_IS_FILE_INFO (info), 0);
   g_return_val_if_fail (attribute != NULL && *attribute != '\0', 0);
 
@@ -794,8 +795,8 @@ g_file_info_set_attribute_status (GFileInfo  *info,
 {
   GFileAttributeValue *val;
 
-  g_return_val_if_fail (G_IS_FILE_INFO (info), 0);
-  g_return_val_if_fail (attribute != NULL && *attribute != '\0', 0);
+  g_return_val_if_fail (G_IS_FILE_INFO (info), FALSE);
+  g_return_val_if_fail (attribute != NULL && *attribute != '\0', FALSE);
 
   val = g_file_info_find_value_by_name (info, attribute);
   if (val)
@@ -810,7 +811,7 @@ g_file_info_set_attribute_status (GFileInfo  *info,
 GFileAttributeValue *
 _g_file_info_get_attribute_value (GFileInfo  *info,
                                  const char *attribute)
-  
+
 {
   g_return_val_if_fail (G_IS_FILE_INFO (info), NULL);
   g_return_val_if_fail (attribute != NULL && *attribute != '\0', NULL);
@@ -822,11 +823,11 @@ _g_file_info_get_attribute_value (GFileInfo  *info,
  * g_file_info_get_attribute_as_string:
  * @info: a #GFileInfo.
  * @attribute: a file attribute key.
- * 
+ *
  * Gets the value of a attribute, formated as a string.
  * This escapes things as needed to make the string valid
  * utf8.
- * 
+ *
  * Returns: a UTF-8 string associated with the given @attribute.
  *    When you're done with the string it must be freed with g_free().
  **/
@@ -836,7 +837,7 @@ g_file_info_get_attribute_as_string (GFileInfo  *info,
 {
   GFileAttributeValue *val;
   val = _g_file_info_get_attribute_value (info, attribute);
-  if (val) 
+  if (val)
     return _g_file_attribute_value_as_string (val);
   return NULL;
 }
@@ -846,11 +847,11 @@ g_file_info_get_attribute_as_string (GFileInfo  *info,
  * g_file_info_get_attribute_object:
  * @info: a #GFileInfo.
  * @attribute: a file attribute key.
- * 
- * Gets the value of a #GObject attribute. If the attribute does 
+ *
+ * Gets the value of a #GObject attribute. If the attribute does
  * not contain a #GObject, %NULL will be returned.
- * 
- * Returns: a #GObject associated with the given @attribute, or
+ *
+ * Returns: (transfer none): a #GObject associated with the given @attribute, or
  * %NULL otherwise.
  **/
 GObject *
@@ -858,7 +859,7 @@ g_file_info_get_attribute_object (GFileInfo  *info,
                                  const char *attribute)
 {
   GFileAttributeValue *value;
-  
+
   g_return_val_if_fail (G_IS_FILE_INFO (info), NULL);
   g_return_val_if_fail (attribute != NULL && *attribute != '\0', NULL);
 
@@ -870,11 +871,11 @@ g_file_info_get_attribute_object (GFileInfo  *info,
  * g_file_info_get_attribute_string:
  * @info: a #GFileInfo.
  * @attribute: a file attribute key.
- * 
- * Gets the value of a string attribute. If the attribute does 
+ *
+ * Gets the value of a string attribute. If the attribute does
  * not contain a string, %NULL will be returned.
- * 
- * Returns: the contents of the @attribute value as a string, or 
+ *
+ * Returns: the contents of the @attribute value as a UTF-8 string, or
  * %NULL otherwise.
  **/
 const char *
@@ -882,7 +883,7 @@ g_file_info_get_attribute_string (GFileInfo  *info,
                                  const char *attribute)
 {
   GFileAttributeValue *value;
-  
+
   g_return_val_if_fail (G_IS_FILE_INFO (info), NULL);
   g_return_val_if_fail (attribute != NULL && *attribute != '\0', NULL);
 
@@ -894,11 +895,11 @@ g_file_info_get_attribute_string (GFileInfo  *info,
  * g_file_info_get_attribute_byte_string:
  * @info: a #GFileInfo.
  * @attribute: a file attribute key.
- * 
- * Gets the value of a byte string attribute. If the attribute does 
+ *
+ * Gets the value of a byte string attribute. If the attribute does
  * not contain a byte string, %NULL will be returned.
- * 
- * Returns: the contents of the @attribute value as a byte string, or 
+ *
+ * Returns: the contents of the @attribute value as a byte string, or
  * %NULL otherwise.
  **/
 const char *
@@ -906,7 +907,7 @@ g_file_info_get_attribute_byte_string (GFileInfo  *info,
                                       const char *attribute)
 {
   GFileAttributeValue *value;
-  
+
   g_return_val_if_fail (G_IS_FILE_INFO (info), NULL);
   g_return_val_if_fail (attribute != NULL && *attribute != '\0', NULL);
 
@@ -922,8 +923,8 @@ g_file_info_get_attribute_byte_string (GFileInfo  *info,
  * Gets the value of a stringv attribute. If the attribute does
  * not contain a stringv, %NULL will be returned.
  *
- * Returns: the contents of the @attribute value as a stringv, or
- * %NULL otherwise. Do not free.
+ * Returns: (transfer none): the contents of the @attribute value as a stringv, or
+ * %NULL otherwise. Do not free. These returned strings are UTF-8.
  *
  * Since: 2.22
  **/
@@ -944,18 +945,18 @@ g_file_info_get_attribute_stringv (GFileInfo  *info,
  * g_file_info_get_attribute_boolean:
  * @info: a #GFileInfo.
  * @attribute: a file attribute key.
- * 
+ *
  * Gets the value of a boolean attribute. If the attribute does not
  * contain a boolean value, %FALSE will be returned.
- * 
- * Returns: the boolean value contained within the attribute. 
+ *
+ * Returns: the boolean value contained within the attribute.
  **/
 gboolean
 g_file_info_get_attribute_boolean (GFileInfo  *info,
                                   const char *attribute)
 {
   GFileAttributeValue *value;
-  
+
   g_return_val_if_fail (G_IS_FILE_INFO (info), FALSE);
   g_return_val_if_fail (attribute != NULL && *attribute != '\0', FALSE);
 
@@ -967,19 +968,19 @@ g_file_info_get_attribute_boolean (GFileInfo  *info,
  * g_file_info_get_attribute_uint32:
  * @info: a #GFileInfo.
  * @attribute: a file attribute key.
- * 
- * Gets an unsigned 32-bit integer contained within the attribute. If the 
- * attribute does not contain an unsigned 32-bit integer, or is invalid, 
+ *
+ * Gets an unsigned 32-bit integer contained within the attribute. If the
+ * attribute does not contain an unsigned 32-bit integer, or is invalid,
  * 0 will be returned.
- * 
- * Returns: an unsigned 32-bit integer from the attribute. 
+ *
+ * Returns: an unsigned 32-bit integer from the attribute.
  **/
 guint32
 g_file_info_get_attribute_uint32 (GFileInfo  *info,
                                  const char *attribute)
 {
   GFileAttributeValue *value;
-  
+
   g_return_val_if_fail (G_IS_FILE_INFO (info), 0);
   g_return_val_if_fail (attribute != NULL && *attribute != '\0', 0);
 
@@ -991,11 +992,11 @@ g_file_info_get_attribute_uint32 (GFileInfo  *info,
  * g_file_info_get_attribute_int32:
  * @info: a #GFileInfo.
  * @attribute: a file attribute key.
- * 
- * Gets a signed 32-bit integer contained within the attribute. If the 
- * attribute does not contain a signed 32-bit integer, or is invalid, 
+ *
+ * Gets a signed 32-bit integer contained within the attribute. If the
+ * attribute does not contain a signed 32-bit integer, or is invalid,
  * 0 will be returned.
- * 
+ *
  * Returns: a signed 32-bit integer from the attribute.
  **/
 gint32
@@ -1015,12 +1016,12 @@ g_file_info_get_attribute_int32 (GFileInfo  *info,
  * g_file_info_get_attribute_uint64:
  * @info: a #GFileInfo.
  * @attribute: a file attribute key.
- * 
- * Gets a unsigned 64-bit integer contained within the attribute. If the 
- * attribute does not contain an unsigned 64-bit integer, or is invalid, 
+ *
+ * Gets a unsigned 64-bit integer contained within the attribute. If the
+ * attribute does not contain an unsigned 64-bit integer, or is invalid,
  * 0 will be returned.
- * 
- * Returns: a unsigned 64-bit integer from the attribute. 
+ *
+ * Returns: a unsigned 64-bit integer from the attribute.
  **/
 guint64
 g_file_info_get_attribute_uint64 (GFileInfo  *info,
@@ -1039,12 +1040,12 @@ g_file_info_get_attribute_uint64 (GFileInfo  *info,
  * g_file_info_get_attribute_int64:
  * @info: a #GFileInfo.
  * @attribute: a file attribute key.
- * 
- * Gets a signed 64-bit integer contained within the attribute. If the 
- * attribute does not contain an signed 64-bit integer, or is invalid, 
+ *
+ * Gets a signed 64-bit integer contained within the attribute. If the
+ * attribute does not contain an signed 64-bit integer, or is invalid,
  * 0 will be returned.
- * 
- * Returns: a signed 64-bit integer from the attribute. 
+ *
+ * Returns: a signed 64-bit integer from the attribute.
  **/
 gint64
 g_file_info_get_attribute_int64  (GFileInfo  *info,
@@ -1069,9 +1070,9 @@ g_file_info_create_value (GFileInfo *info,
   if (info->mask != NO_ATTRIBUTE_MASK &&
       !_g_file_attribute_matcher_matches_id (info->mask, attr_id))
     return NULL;
-  
+
   i = g_file_info_find_place (info, attr_id);
-  
+
   attrs = (GFileAttribute *)info->attributes->data;
   if (i < info->attributes->len &&
       attrs[i].attribute == attr_id)
@@ -1107,8 +1108,9 @@ _g_file_info_set_attribute_by_id (GFileInfo                 *info,
  * @attribute: a file attribute key.
  * @type: a #GFileAttributeType
  * @value_p: pointer to the value
- * 
- * Sets the @attribute to contain the given value, if possible.
+ *
+ * Sets the @attribute to contain the given value, if possible. To unset the
+ * attribute, use %G_ATTRIBUTE_TYPE_INVALID for @type.
  **/
 void
 g_file_info_set_attribute (GFileInfo                 *info,
@@ -1139,8 +1141,8 @@ _g_file_info_set_attribute_object_by_id (GFileInfo *info,
  * @info: a #GFileInfo.
  * @attribute: a file attribute key.
  * @attr_value: a #GObject.
- * 
- * Sets the @attribute to contain the given @attr_value, 
+ *
+ * Sets the @attribute to contain the given @attr_value,
  * if possible.
  **/
 void
@@ -1172,8 +1174,8 @@ _g_file_info_set_attribute_stringv_by_id (GFileInfo *info,
 /**
  * g_file_info_set_attribute_stringv:
  * @info: a #GFileInfo.
- * @attribute: a file attribute key.
- * @attr_value: a %NULL terminated string array
+ * @attribute: a file attribute key
+ * @attr_value: (array) (element-type utf8): a %NULL terminated array of UTF-8 strings.
  *
  * Sets the @attribute to contain the given @attr_value,
  * if possible.
@@ -1189,7 +1191,7 @@ g_file_info_set_attribute_stringv (GFileInfo  *info,
   g_return_if_fail (attribute != NULL && *attribute != '\0');
   g_return_if_fail (attr_value != NULL);
 
-  _g_file_info_set_attribute_stringv_by_id (info, 
+  _g_file_info_set_attribute_stringv_by_id (info,
                                             lookup_attribute (attribute),
                                             attr_value);
 }
@@ -1210,9 +1212,9 @@ _g_file_info_set_attribute_string_by_id (GFileInfo  *info,
  * g_file_info_set_attribute_string:
  * @info: a #GFileInfo.
  * @attribute: a file attribute key.
- * @attr_value: a string.
- * 
- * Sets the @attribute to contain the given @attr_value, 
+ * @attr_value: a UTF-8 string.
+ *
+ * Sets the @attribute to contain the given @attr_value,
  * if possible.
  **/
 void
@@ -1246,8 +1248,8 @@ _g_file_info_set_attribute_byte_string_by_id (GFileInfo  *info,
  * @info: a #GFileInfo.
  * @attribute: a file attribute key.
  * @attr_value: a byte string.
- * 
- * Sets the @attribute to contain the given @attr_value, 
+ *
+ * Sets the @attribute to contain the given @attr_value,
  * if possible.
  **/
 void
@@ -1281,8 +1283,8 @@ _g_file_info_set_attribute_boolean_by_id (GFileInfo *info,
  * @info: a #GFileInfo.
  * @attribute: a file attribute key.
  * @attr_value: a boolean value.
- * 
- * Sets the @attribute to contain the given @attr_value, 
+ *
+ * Sets the @attribute to contain the given @attr_value,
  * if possible.
  **/
 void
@@ -1315,8 +1317,8 @@ _g_file_info_set_attribute_uint32_by_id (GFileInfo *info,
  * @info: a #GFileInfo.
  * @attribute: a file attribute key.
  * @attr_value: an unsigned 32-bit integer.
- * 
- * Sets the @attribute to contain the given @attr_value, 
+ *
+ * Sets the @attribute to contain the given @attr_value,
  * if possible.
  **/
 void
@@ -1349,8 +1351,8 @@ _g_file_info_set_attribute_int32_by_id (GFileInfo *info,
  * @info: a #GFileInfo.
  * @attribute: a file attribute key.
  * @attr_value: a signed 32-bit integer
- * 
- * Sets the @attribute to contain the given @attr_value, 
+ *
+ * Sets the @attribute to contain the given @attr_value,
  * if possible.
  **/
 void
@@ -1383,8 +1385,8 @@ _g_file_info_set_attribute_uint64_by_id (GFileInfo *info,
  * @info: a #GFileInfo.
  * @attribute: a file attribute key.
  * @attr_value: an unsigned 64-bit integer.
- * 
- * Sets the @attribute to contain the given @attr_value, 
+ *
+ * Sets the @attribute to contain the given @attr_value,
  * if possible.
  **/
 void
@@ -1417,10 +1419,10 @@ _g_file_info_set_attribute_int64_by_id (GFileInfo *info,
  * @info: a #GFileInfo.
  * @attribute: attribute name to set.
  * @attr_value: int64 value to set attribute to.
- * 
- * Sets the @attribute to contain the given @attr_value, 
+ *
+ * Sets the @attribute to contain the given @attr_value,
  * if possible.
- * 
+ *
  **/
 void
 g_file_info_set_attribute_int64  (GFileInfo  *info,
@@ -1439,10 +1441,10 @@ g_file_info_set_attribute_int64  (GFileInfo  *info,
 /**
  * g_file_info_get_file_type:
  * @info: a #GFileInfo.
- * 
- * Gets a file's type (whether it is a regular file, symlink, etc). 
+ *
+ * Gets a file's type (whether it is a regular file, symlink, etc).
  * This is different from the file's content type, see g_file_info_get_content_type().
- * 
+ *
  * Returns: a #GFileType for the given file.
  **/
 GFileType
@@ -1452,10 +1454,10 @@ g_file_info_get_file_type (GFileInfo *info)
   GFileAttributeValue *value;
 
   g_return_val_if_fail (G_IS_FILE_INFO (info), G_FILE_TYPE_UNKNOWN);
-  
+
   if (attr == 0)
     attr = lookup_attribute (G_FILE_ATTRIBUTE_STANDARD_TYPE);
-  
+
   value = g_file_info_find_value (info, attr);
   return (GFileType)_g_file_attribute_value_get_uint32 (value);
 }
@@ -1463,9 +1465,9 @@ g_file_info_get_file_type (GFileInfo *info)
 /**
  * g_file_info_get_is_hidden:
  * @info: a #GFileInfo.
- * 
+ *
  * Checks if a file is hidden.
- * 
+ *
  * Returns: %TRUE if the file is a hidden file, %FALSE otherwise.
  **/
 gboolean
@@ -1473,12 +1475,12 @@ g_file_info_get_is_hidden (GFileInfo *info)
 {
   static guint32 attr = 0;
   GFileAttributeValue *value;
-  
+
   g_return_val_if_fail (G_IS_FILE_INFO (info), FALSE);
-  
+
   if (attr == 0)
     attr = lookup_attribute (G_FILE_ATTRIBUTE_STANDARD_IS_HIDDEN);
-  
+
   value = g_file_info_find_value (info, attr);
   return (GFileType)_g_file_attribute_value_get_boolean (value);
 }
@@ -1486,9 +1488,9 @@ g_file_info_get_is_hidden (GFileInfo *info)
 /**
  * g_file_info_get_is_backup:
  * @info: a #GFileInfo.
- * 
+ *
  * Checks if a file is a backup file.
- * 
+ *
  * Returns: %TRUE if file is a backup file, %FALSE otherwise.
  **/
 gboolean
@@ -1496,12 +1498,12 @@ g_file_info_get_is_backup (GFileInfo *info)
 {
   static guint32 attr = 0;
   GFileAttributeValue *value;
-  
+
   g_return_val_if_fail (G_IS_FILE_INFO (info), FALSE);
-  
+
   if (attr == 0)
     attr = lookup_attribute (G_FILE_ATTRIBUTE_STANDARD_IS_BACKUP);
-  
+
   value = g_file_info_find_value (info, attr);
   return (GFileType)_g_file_attribute_value_get_boolean (value);
 }
@@ -1509,9 +1511,9 @@ g_file_info_get_is_backup (GFileInfo *info)
 /**
  * g_file_info_get_is_symlink:
  * @info: a #GFileInfo.
- * 
+ *
  * Checks if a file is a symlink.
- * 
+ *
  * Returns: %TRUE if the given @info is a symlink.
  **/
 gboolean
@@ -1519,12 +1521,12 @@ g_file_info_get_is_symlink (GFileInfo *info)
 {
   static guint32 attr = 0;
   GFileAttributeValue *value;
-  
+
   g_return_val_if_fail (G_IS_FILE_INFO (info), FALSE);
-  
+
   if (attr == 0)
     attr = lookup_attribute (G_FILE_ATTRIBUTE_STANDARD_IS_SYMLINK);
-  
+
   value = g_file_info_find_value (info, attr);
   return (GFileType)_g_file_attribute_value_get_boolean (value);
 }
@@ -1532,9 +1534,9 @@ g_file_info_get_is_symlink (GFileInfo *info)
 /**
  * g_file_info_get_name:
  * @info: a #GFileInfo.
- * 
+ *
  * Gets the name for a file.
- * 
+ *
  * Returns: a string containing the file name.
  **/
 const char *
@@ -1542,12 +1544,12 @@ g_file_info_get_name (GFileInfo *info)
 {
   static guint32 attr = 0;
   GFileAttributeValue *value;
-  
+
   g_return_val_if_fail (G_IS_FILE_INFO (info), NULL);
-  
+
   if (attr == 0)
     attr = lookup_attribute (G_FILE_ATTRIBUTE_STANDARD_NAME);
-  
+
   value = g_file_info_find_value (info, attr);
   return _g_file_attribute_value_get_byte_string (value);
 }
@@ -1555,9 +1557,9 @@ g_file_info_get_name (GFileInfo *info)
 /**
  * g_file_info_get_display_name:
  * @info: a #GFileInfo.
- * 
+ *
  * Gets a display name for a file.
- * 
+ *
  * Returns: a string containing the display name.
  **/
 const char *
@@ -1565,12 +1567,12 @@ g_file_info_get_display_name (GFileInfo *info)
 {
   static guint32 attr = 0;
   GFileAttributeValue *value;
-  
+
   g_return_val_if_fail (G_IS_FILE_INFO (info), NULL);
-  
+
   if (attr == 0)
     attr = lookup_attribute (G_FILE_ATTRIBUTE_STANDARD_DISPLAY_NAME);
-  
+
   value = g_file_info_find_value (info, attr);
   return _g_file_attribute_value_get_string (value);
 }
@@ -1578,9 +1580,9 @@ g_file_info_get_display_name (GFileInfo *info)
 /**
  * g_file_info_get_edit_name:
  * @info: a #GFileInfo.
- * 
+ *
  * Gets the edit name for a file.
- * 
+ *
  * Returns: a string containing the edit name.
  **/
 const char *
@@ -1588,12 +1590,12 @@ g_file_info_get_edit_name (GFileInfo *info)
 {
   static guint32 attr = 0;
   GFileAttributeValue *value;
-  
+
   g_return_val_if_fail (G_IS_FILE_INFO (info), NULL);
-  
+
   if (attr == 0)
     attr = lookup_attribute (G_FILE_ATTRIBUTE_STANDARD_EDIT_NAME);
-  
+
   value = g_file_info_find_value (info, attr);
   return _g_file_attribute_value_get_string (value);
 }
@@ -1601,10 +1603,10 @@ g_file_info_get_edit_name (GFileInfo *info)
 /**
  * g_file_info_get_icon:
  * @info: a #GFileInfo.
- * 
+ *
  * Gets the icon for a file.
- * 
- * Returns: #GIcon for the given @info.
+ *
+ * Returns: (transfer none): #GIcon for the given @info.
  **/
 GIcon *
 g_file_info_get_icon (GFileInfo *info)
@@ -1612,12 +1614,12 @@ g_file_info_get_icon (GFileInfo *info)
   static guint32 attr = 0;
   GFileAttributeValue *value;
   GObject *obj;
-  
+
   g_return_val_if_fail (G_IS_FILE_INFO (info), NULL);
-  
+
   if (attr == 0)
     attr = lookup_attribute (G_FILE_ATTRIBUTE_STANDARD_ICON);
-  
+
   value = g_file_info_find_value (info, attr);
   obj = _g_file_attribute_value_get_object (value);
   if (G_IS_ICON (obj))
@@ -1628,9 +1630,9 @@ g_file_info_get_icon (GFileInfo *info)
 /**
  * g_file_info_get_content_type:
  * @info: a #GFileInfo.
- * 
+ *
  * Gets the file's content type.
- * 
+ *
  * Returns: a string containing the file's content type.
  **/
 const char *
@@ -1638,12 +1640,12 @@ g_file_info_get_content_type (GFileInfo *info)
 {
   static guint32 attr = 0;
   GFileAttributeValue *value;
-  
+
   g_return_val_if_fail (G_IS_FILE_INFO (info), NULL);
-  
+
   if (attr == 0)
     attr = lookup_attribute (G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE);
-  
+
   value = g_file_info_find_value (info, attr);
   return _g_file_attribute_value_get_string (value);
 }
@@ -1651,22 +1653,22 @@ g_file_info_get_content_type (GFileInfo *info)
 /**
  * g_file_info_get_size:
  * @info: a #GFileInfo.
- * 
+ *
  * Gets the file's size.
- * 
- * Returns: a #goffset containing the file's size. 
+ *
+ * Returns: a #goffset containing the file's size.
  **/
 goffset
 g_file_info_get_size (GFileInfo *info)
 {
   static guint32 attr = 0;
   GFileAttributeValue *value;
+
   g_return_val_if_fail (G_IS_FILE_INFO (info), (goffset) 0);
-  
+
   if (attr == 0)
     attr = lookup_attribute (G_FILE_ATTRIBUTE_STANDARD_SIZE);
-  
+
   value = g_file_info_find_value (info, attr);
   return (goffset) _g_file_attribute_value_get_uint64 (value);
 }
@@ -1674,8 +1676,8 @@ g_file_info_get_size (GFileInfo *info)
 /**
  * g_file_info_get_modification_time:
  * @info: a #GFileInfo.
- * @result: a #GTimeVal.
- * 
+ * @result: (out caller-allocates): a #GTimeVal.
+ *
  * Gets the modification time of the current @info and sets it
  * in @result.
  **/
@@ -1688,13 +1690,13 @@ g_file_info_get_modification_time (GFileInfo *info,
 
   g_return_if_fail (G_IS_FILE_INFO (info));
   g_return_if_fail (result != NULL);
-  
+
   if (attr_mtime == 0)
     {
       attr_mtime = lookup_attribute (G_FILE_ATTRIBUTE_TIME_MODIFIED);
       attr_mtime_usec = lookup_attribute (G_FILE_ATTRIBUTE_TIME_MODIFIED_USEC);
     }
-  
+
   value = g_file_info_find_value (info, attr_mtime);
   result->tv_sec = _g_file_attribute_value_get_uint64 (value);
   value = g_file_info_find_value (info, attr_mtime_usec);
@@ -1704,9 +1706,9 @@ g_file_info_get_modification_time (GFileInfo *info,
 /**
  * g_file_info_get_symlink_target:
  * @info: a #GFileInfo.
- * 
+ *
  * Gets the symlink target for a given #GFileInfo.
- * 
+ *
  * Returns: a string containing the symlink target.
  **/
 const char *
@@ -1714,12 +1716,12 @@ g_file_info_get_symlink_target (GFileInfo *info)
 {
   static guint32 attr = 0;
   GFileAttributeValue *value;
-  
+
   g_return_val_if_fail (G_IS_FILE_INFO (info), NULL);
-  
+
   if (attr == 0)
     attr = lookup_attribute (G_FILE_ATTRIBUTE_STANDARD_SYMLINK_TARGET);
-  
+
   value = g_file_info_find_value (info, attr);
   return _g_file_attribute_value_get_byte_string (value);
 }
@@ -1727,10 +1729,10 @@ g_file_info_get_symlink_target (GFileInfo *info)
 /**
  * g_file_info_get_etag:
  * @info: a #GFileInfo.
- * 
- * Gets the <link linkend="gfile-etag">entity tag</link> for a given 
+ *
+ * Gets the <link linkend="gfile-etag">entity tag</link> for a given
  * #GFileInfo. See %G_FILE_ATTRIBUTE_ETAG_VALUE.
- * 
+ *
  * Returns: a string containing the value of the "etag:value" attribute.
  **/
 const char *
@@ -1738,12 +1740,12 @@ g_file_info_get_etag (GFileInfo *info)
 {
   static guint32 attr = 0;
   GFileAttributeValue *value;
-  
+
   g_return_val_if_fail (G_IS_FILE_INFO (info), NULL);
-  
+
   if (attr == 0)
     attr = lookup_attribute (G_FILE_ATTRIBUTE_ETAG_VALUE);
-  
+
   value = g_file_info_find_value (info, attr);
   return _g_file_attribute_value_get_string (value);
 }
@@ -1751,10 +1753,10 @@ g_file_info_get_etag (GFileInfo *info)
 /**
  * g_file_info_get_sort_order:
  * @info: a #GFileInfo.
- * 
+ *
  * Gets the value of the sort_order attribute from the #GFileInfo.
  * See %G_FILE_ATTRIBUTE_STANDARD_SORT_ORDER.
- * 
+ *
  * Returns: a #gint32 containing the value of the "standard::sort_order" attribute.
  **/
 gint32
@@ -1762,12 +1764,12 @@ g_file_info_get_sort_order (GFileInfo *info)
 {
   static guint32 attr = 0;
   GFileAttributeValue *value;
-  
+
   g_return_val_if_fail (G_IS_FILE_INFO (info), 0);
-  
+
   if (attr == 0)
     attr = lookup_attribute (G_FILE_ATTRIBUTE_STANDARD_SORT_ORDER);
-  
+
   value = g_file_info_find_value (info, attr);
   return _g_file_attribute_value_get_int32 (value);
 }
@@ -1777,7 +1779,7 @@ g_file_info_get_sort_order (GFileInfo *info)
  * g_file_info_set_file_type:
  * @info: a #GFileInfo.
  * @type: a #GFileType.
- * 
+ *
  * Sets the file type in a #GFileInfo to @type.
  * See %G_FILE_ATTRIBUTE_STANDARD_TYPE.
  **/
@@ -1787,12 +1789,12 @@ g_file_info_set_file_type (GFileInfo *info,
 {
   static guint32 attr = 0;
   GFileAttributeValue *value;
-  
+
   g_return_if_fail (G_IS_FILE_INFO (info));
-  
+
   if (attr == 0)
     attr = lookup_attribute (G_FILE_ATTRIBUTE_STANDARD_TYPE);
-  
+
   value = g_file_info_create_value (info, attr);
   if (value)
     _g_file_attribute_value_set_uint32 (value, type);
@@ -1802,7 +1804,7 @@ g_file_info_set_file_type (GFileInfo *info,
  * g_file_info_set_is_hidden:
  * @info: a #GFileInfo.
  * @is_hidden: a #gboolean.
- * 
+ *
  * Sets the "is_hidden" attribute in a #GFileInfo according to @is_symlink.
  * See %G_FILE_ATTRIBUTE_STANDARD_IS_HIDDEN.
  **/
@@ -1812,12 +1814,12 @@ g_file_info_set_is_hidden (GFileInfo *info,
 {
   static guint32 attr = 0;
   GFileAttributeValue *value;
-  
+
   g_return_if_fail (G_IS_FILE_INFO (info));
-  
+
   if (attr == 0)
     attr = lookup_attribute (G_FILE_ATTRIBUTE_STANDARD_IS_HIDDEN);
-  
+
   value = g_file_info_create_value (info, attr);
   if (value)
     _g_file_attribute_value_set_boolean (value, is_hidden);
@@ -1827,7 +1829,7 @@ g_file_info_set_is_hidden (GFileInfo *info,
  * g_file_info_set_is_symlink:
  * @info: a #GFileInfo.
  * @is_symlink: a #gboolean.
- * 
+ *
  * Sets the "is_symlink" attribute in a #GFileInfo according to @is_symlink.
  * See %G_FILE_ATTRIBUTE_STANDARD_IS_SYMLINK.
  **/
@@ -1837,12 +1839,12 @@ g_file_info_set_is_symlink (GFileInfo *info,
 {
   static guint32 attr = 0;
   GFileAttributeValue *value;
-  
+
   g_return_if_fail (G_IS_FILE_INFO (info));
-  
+
   if (attr == 0)
     attr = lookup_attribute (G_FILE_ATTRIBUTE_STANDARD_IS_SYMLINK);
-  
+
   value = g_file_info_create_value (info, attr);
   if (value)
     _g_file_attribute_value_set_boolean (value, is_symlink);
@@ -1852,8 +1854,8 @@ g_file_info_set_is_symlink (GFileInfo *info,
  * g_file_info_set_name:
  * @info: a #GFileInfo.
  * @name: a string containing a name.
- * 
- * Sets the name attribute for the current #GFileInfo. 
+ *
+ * Sets the name attribute for the current #GFileInfo.
  * See %G_FILE_ATTRIBUTE_STANDARD_NAME.
  **/
 void
@@ -1862,13 +1864,13 @@ g_file_info_set_name (GFileInfo  *info,
 {
   static guint32 attr = 0;
   GFileAttributeValue *value;
-  
+
   g_return_if_fail (G_IS_FILE_INFO (info));
   g_return_if_fail (name != NULL);
-  
+
   if (attr == 0)
     attr = lookup_attribute (G_FILE_ATTRIBUTE_STANDARD_NAME);
-  
+
   value = g_file_info_create_value (info, attr);
   if (value)
     _g_file_attribute_value_set_byte_string (value, name);
@@ -1878,7 +1880,7 @@ g_file_info_set_name (GFileInfo  *info,
  * g_file_info_set_display_name:
  * @info: a #GFileInfo.
  * @display_name: a string containing a display name.
- * 
+ *
  * Sets the display name for the current #GFileInfo.
  * See %G_FILE_ATTRIBUTE_STANDARD_DISPLAY_NAME.
  **/
@@ -1888,13 +1890,13 @@ g_file_info_set_display_name (GFileInfo  *info,
 {
   static guint32 attr = 0;
   GFileAttributeValue *value;
-  
+
   g_return_if_fail (G_IS_FILE_INFO (info));
   g_return_if_fail (display_name != NULL);
-  
+
   if (attr == 0)
     attr = lookup_attribute (G_FILE_ATTRIBUTE_STANDARD_DISPLAY_NAME);
-  
+
   value = g_file_info_create_value (info, attr);
   if (value)
     _g_file_attribute_value_set_string (value, display_name);
@@ -1904,7 +1906,7 @@ g_file_info_set_display_name (GFileInfo  *info,
  * g_file_info_set_edit_name:
  * @info: a #GFileInfo.
  * @edit_name: a string containing an edit name.
- * 
+ *
  * Sets the edit name for the current file.
  * See %G_FILE_ATTRIBUTE_STANDARD_EDIT_NAME.
  **/
@@ -1914,13 +1916,13 @@ g_file_info_set_edit_name (GFileInfo  *info,
 {
   static guint32 attr = 0;
   GFileAttributeValue *value;
-  
+
   g_return_if_fail (G_IS_FILE_INFO (info));
   g_return_if_fail (edit_name != NULL);
-  
+
   if (attr == 0)
     attr = lookup_attribute (G_FILE_ATTRIBUTE_STANDARD_EDIT_NAME);
-  
+
   value = g_file_info_create_value (info, attr);
   if (value)
     _g_file_attribute_value_set_string (value, edit_name);
@@ -1930,8 +1932,8 @@ g_file_info_set_edit_name (GFileInfo  *info,
  * g_file_info_set_icon:
  * @info: a #GFileInfo.
  * @icon: a #GIcon.
- * 
- * Sets the icon for a given #GFileInfo. 
+ *
+ * Sets the icon for a given #GFileInfo.
  * See %G_FILE_ATTRIBUTE_STANDARD_ICON.
  **/
 void
@@ -1940,13 +1942,13 @@ g_file_info_set_icon (GFileInfo *info,
 {
   static guint32 attr = 0;
   GFileAttributeValue *value;
-  
+
   g_return_if_fail (G_IS_FILE_INFO (info));
   g_return_if_fail (G_IS_ICON (icon));
-  
+
   if (attr == 0)
     attr = lookup_attribute (G_FILE_ATTRIBUTE_STANDARD_ICON);
-  
+
   value = g_file_info_create_value (info, attr);
   if (value)
     _g_file_attribute_value_set_object (value, G_OBJECT (icon));
@@ -1955,8 +1957,8 @@ g_file_info_set_icon (GFileInfo *info,
 /**
  * g_file_info_set_content_type:
  * @info: a #GFileInfo.
- * @content_type: a content type. See #GContentType.
- * 
+ * @content_type: a content type. See <link linkend="gio-GContentType">GContentType</link>.
+ *
  * Sets the content type attribute for a given #GFileInfo.
  * See %G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE.
  **/
@@ -1966,13 +1968,13 @@ g_file_info_set_content_type (GFileInfo  *info,
 {
   static guint32 attr = 0;
   GFileAttributeValue *value;
-  
+
   g_return_if_fail (G_IS_FILE_INFO (info));
   g_return_if_fail (content_type != NULL);
-  
+
   if (attr == 0)
     attr = lookup_attribute (G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE);
-  
+
   value = g_file_info_create_value (info, attr);
   if (value)
     _g_file_attribute_value_set_string (value, content_type);
@@ -1982,8 +1984,8 @@ g_file_info_set_content_type (GFileInfo  *info,
  * g_file_info_set_size:
  * @info: a #GFileInfo.
  * @size: a #goffset containing the file's size.
- * 
- * Sets the %G_FILE_ATTRIBUTE_STANDARD_SIZE attribute in the file info 
+ *
+ * Sets the %G_FILE_ATTRIBUTE_STANDARD_SIZE attribute in the file info
  * to the given size.
  **/
 void
@@ -1992,22 +1994,22 @@ g_file_info_set_size (GFileInfo *info,
 {
   static guint32 attr = 0;
   GFileAttributeValue *value;
-  
+
   g_return_if_fail (G_IS_FILE_INFO (info));
-  
+
   if (attr == 0)
     attr = lookup_attribute (G_FILE_ATTRIBUTE_STANDARD_SIZE);
-  
+
   value = g_file_info_create_value (info, attr);
   if (value)
     _g_file_attribute_value_set_uint64 (value, size);
 }
 
 /**
- * g_file_info_set_modification_time
+ * g_file_info_set_modification_time:
  * @info: a #GFileInfo.
  * @mtime: a #GTimeVal.
- * 
+ *
  * Sets the %G_FILE_ATTRIBUTE_TIME_MODIFIED attribute in the file
  * info to the given time value.
  **/
@@ -2017,16 +2019,16 @@ g_file_info_set_modification_time (GFileInfo *info,
 {
   static guint32 attr_mtime = 0, attr_mtime_usec;
   GFileAttributeValue *value;
-  
+
   g_return_if_fail (G_IS_FILE_INFO (info));
   g_return_if_fail (mtime != NULL);
-  
+
   if (attr_mtime == 0)
     {
       attr_mtime = lookup_attribute (G_FILE_ATTRIBUTE_TIME_MODIFIED);
       attr_mtime_usec = lookup_attribute (G_FILE_ATTRIBUTE_TIME_MODIFIED_USEC);
     }
-  
+
   value = g_file_info_create_value (info, attr_mtime);
   if (value)
     _g_file_attribute_value_set_uint64 (value, mtime->tv_sec);
@@ -2039,8 +2041,8 @@ g_file_info_set_modification_time (GFileInfo *info,
  * g_file_info_set_symlink_target:
  * @info: a #GFileInfo.
  * @symlink_target: a static string containing a path to a symlink target.
- * 
- * Sets the %G_FILE_ATTRIBUTE_STANDARD_SYMLINK_TARGET attribute in the file info 
+ *
+ * Sets the %G_FILE_ATTRIBUTE_STANDARD_SYMLINK_TARGET attribute in the file info
  * to the given symlink target.
  **/
 void
@@ -2049,13 +2051,13 @@ g_file_info_set_symlink_target (GFileInfo  *info,
 {
   static guint32 attr = 0;
   GFileAttributeValue *value;
-  
+
   g_return_if_fail (G_IS_FILE_INFO (info));
   g_return_if_fail (symlink_target != NULL);
-  
+
   if (attr == 0)
     attr = lookup_attribute (G_FILE_ATTRIBUTE_STANDARD_SYMLINK_TARGET);
-  
+
   value = g_file_info_create_value (info, attr);
   if (value)
     _g_file_attribute_value_set_byte_string (value, symlink_target);
@@ -2065,8 +2067,8 @@ g_file_info_set_symlink_target (GFileInfo  *info,
  * g_file_info_set_sort_order:
  * @info: a #GFileInfo.
  * @sort_order: a sort order integer.
- * 
- * Sets the sort order attribute in the file info structure. See 
+ *
+ * Sets the sort order attribute in the file info structure. See
  * %G_FILE_ATTRIBUTE_STANDARD_SORT_ORDER.
  **/
 void
@@ -2075,20 +2077,18 @@ g_file_info_set_sort_order (GFileInfo *info,
 {
   static guint32 attr = 0;
   GFileAttributeValue *value;
-  
+
   g_return_if_fail (G_IS_FILE_INFO (info));
-  
+
   if (attr == 0)
     attr = lookup_attribute (G_FILE_ATTRIBUTE_STANDARD_SORT_ORDER);
-  
+
   value = g_file_info_create_value (info, attr);
   if (value)
     _g_file_attribute_value_set_int32 (value, sort_order);
 }
 
 
-#define ON_STACK_MATCHERS 5
-
 typedef struct {
   guint32 id;
   guint32 mask;
@@ -2096,74 +2096,113 @@ typedef struct {
 
 struct _GFileAttributeMatcher {
   gboolean all;
-  SubMatcher sub_matchers[ON_STACK_MATCHERS];
-  GArray *more_sub_matchers;
+  gint ref;
+
+  GArray *sub_matchers;
 
   /* Interator */
   guint32 iterator_ns;
-  int iterator_pos;
-  int ref;
+  gint iterator_pos;
 };
 
-static void
-matcher_add (GFileAttributeMatcher *matcher,
-            guint                  id,
-             guint                  mask)
+G_DEFINE_BOXED_TYPE (GFileAttributeMatcher, g_file_attribute_matcher,
+                     g_file_attribute_matcher_ref,
+                     g_file_attribute_matcher_unref)
+
+static gint
+compare_sub_matchers (gconstpointer a,
+                      gconstpointer b)
 {
-  SubMatcher *sub_matchers;
-  int i;
-  SubMatcher s;
+  const SubMatcher *suba = a;
+  const SubMatcher *subb = b;
+  int diff;
+
+  diff = suba->id - subb->id;
+
+  if (diff)
+    return diff;
+
+  return suba->mask - subb->mask;
+}
 
-  for (i = 0; i < ON_STACK_MATCHERS; i++)
+static gboolean
+sub_matcher_matches (SubMatcher *matcher,
+                     SubMatcher *submatcher)
+{
+  if ((matcher->mask & submatcher->mask) != matcher->mask)
+    return FALSE;
+  
+  return matcher->id == (submatcher->id & matcher->mask);
+}
+
+/* Call this function after modifying a matcher.
+ * It will ensure all the invariants other functions rely on.
+ */
+static GFileAttributeMatcher *
+matcher_optimize (GFileAttributeMatcher *matcher)
+{
+  SubMatcher *submatcher, *compare;
+  guint i, j;
+
+  /* remove sub_matchers if we match everything anyway */
+  if (matcher->all)
     {
-      /* First empty spot, not found, use this */
-      if (matcher->sub_matchers[i].id == 0)
-       {
-         matcher->sub_matchers[i].id = id;
-         matcher->sub_matchers[i].mask = mask;
-         return;
-       }
-      
-      /* Already added */
-      if (matcher->sub_matchers[i].id == id &&
-         matcher->sub_matchers[i].mask == mask)
-       return;
+      if (matcher->sub_matchers)
+        {
+          g_array_free (matcher->sub_matchers, TRUE);
+          matcher->sub_matchers = NULL;
+        }
+      return matcher;
     }
 
-  if (matcher->more_sub_matchers == NULL)
-    matcher->more_sub_matchers = g_array_new (FALSE, FALSE, sizeof (SubMatcher));
-      
-  sub_matchers = (SubMatcher *)matcher->more_sub_matchers->data;
-  for (i = 0; i < matcher->more_sub_matchers->len; i++)
+  if (matcher->sub_matchers->len == 0)
     {
-      /* Already added */
-      if (sub_matchers[i].id == id &&
-         sub_matchers[i].mask == mask)
-       return;
+      g_file_attribute_matcher_unref (matcher);
+      return NULL;
     }
 
-  s.id = id;
-  s.mask = mask;
-  
-  g_array_append_val (matcher->more_sub_matchers, s);
+  /* sort sub_matchers by id (and then mask), so we can bsearch
+   * and compare matchers in O(N) instead of O(N²) */
+  g_array_sort (matcher->sub_matchers, compare_sub_matchers);
+
+  /* remove duplicates and specific matches when we match the whole namespace */
+  j = 0;
+  compare = &g_array_index (matcher->sub_matchers, SubMatcher, j);
+
+  for (i = 1; i < matcher->sub_matchers->len; i++)
+    {
+      submatcher = &g_array_index (matcher->sub_matchers, SubMatcher, i);
+      if (sub_matcher_matches (compare, submatcher))
+        continue;
+
+      j++;
+      compare++;
+
+      if (j < i)
+        *compare = *submatcher;
+    }
+
+  g_array_set_size (matcher->sub_matchers, j + 1);
+
+  return matcher;
 }
 
 /**
  * g_file_attribute_matcher_new:
  * @attributes: an attribute string to match.
- * 
- * Creates a new file attribute matcher, which matches attributes 
- * against a given string. #GFileAttributeMatcher<!-- -->s are reference 
- * counted structures, and are created with a reference count of 1. If 
- * the number of references falls to 0, the #GFileAttributeMatcher is 
+ *
+ * Creates a new file attribute matcher, which matches attributes
+ * against a given string. #GFileAttributeMatcher<!-- -->s are reference
+ * counted structures, and are created with a reference count of 1. If
+ * the number of references falls to 0, the #GFileAttributeMatcher is
  * automatically destroyed.
- * 
+ *
  * The @attribute string should be formatted with specific keys separated
- * from namespaces with a double colon. Several "namespace::key" strings may be 
- * concatenated with a single comma (e.g. "standard::type,standard::is-hidden"). 
- * The wildcard "*" may be used to match all keys and namespaces, or 
- * "namespace::*" will match all keys in a given namespace. 
- * 
+ * from namespaces with a double colon. Several "namespace::key" strings may be
+ * concatenated with a single comma (e.g. "standard::type,standard::is-hidden").
+ * The wildcard "*" may be used to match all keys and namespaces, or
+ * "namespace::*" will match all keys in a given namespace.
+ *
  * Examples of strings to use:
  * <table>
  * <title>File Attribute Matcher strings and results</title>
@@ -2176,7 +2215,7 @@ matcher_add (GFileAttributeMatcher *matcher,
  * all keys in the unix namespace.</entry></row>
  * </tbody></tgroup>
  * </table>
- * 
+ *
  * Returns: a #GFileAttributeMatcher.
  **/
 GFileAttributeMatcher *
@@ -2192,6 +2231,7 @@ g_file_attribute_matcher_new (const char *attributes)
 
   matcher = g_malloc0 (sizeof (GFileAttributeMatcher));
   matcher->ref = 1;
+  matcher->sub_matchers = g_array_new (FALSE, FALSE, sizeof (SubMatcher));
 
   split = g_strsplit (attributes, ",", -1);
 
@@ -2201,41 +2241,114 @@ g_file_attribute_matcher_new (const char *attributes)
        matcher->all = TRUE;
       else
        {
-         guint32 id, mask;
-  
+          SubMatcher s;
+
          colon = strstr (split[i], "::");
          if (colon != NULL &&
              !(colon[2] == 0 ||
                (colon[2] == '*' &&
                 colon[3] == 0)))
            {
-             id = lookup_attribute (split[i]);
-             mask = 0xffffffff;
+             s.id = lookup_attribute (split[i]);
+             s.mask = 0xffffffff;
            }
          else
            {
              if (colon)
                *colon = 0;
 
-             id = lookup_namespace (split[i]) << NS_POS;
-             mask = NS_MASK << NS_POS;
+             s.id = lookup_namespace (split[i]) << NS_POS;
+             s.mask = NS_MASK << NS_POS;
            }
-         
-         matcher_add (matcher, id, mask);
+
+          g_array_append_val (matcher->sub_matchers, s);
        }
     }
 
   g_strfreev (split);
 
+  matcher = matcher_optimize (matcher);
+
   return matcher;
 }
 
 /**
+ * g_file_attribute_matcher_subtract:
+ * @matcher: Matcher to subtract from 
+ * @subtract: The matcher to subtract
+ *
+ * Subtracts all attributes of @subtract from @matcher and returns
+ * a matcher that supports those attributes.
+ *
+ * Note that currently it is not possible to remove a single
+ * attribute when the @matcher matches the whole namespace - or remove
+ * a namespace or attribute when the matcher matches everything. This
+ * is a limitation of the current implementation, but may be fixed
+ * in the future.
+ *
+ * Returns: A file attribute matcher matching all attributes of
+ *     @matcher that are not matched by @subtract
+ **/
+GFileAttributeMatcher *
+g_file_attribute_matcher_subtract (GFileAttributeMatcher *matcher,
+                                   GFileAttributeMatcher *subtract)
+{
+  GFileAttributeMatcher *result;
+  guint mi, si;
+  SubMatcher *msub, *ssub;
+
+  if (matcher == NULL)
+    return NULL;
+  if (subtract == NULL)
+    return g_file_attribute_matcher_ref (matcher);
+  if (subtract->all)
+    return NULL;
+  if (matcher->all)
+    return g_file_attribute_matcher_ref (matcher);
+
+  result = g_malloc0 (sizeof (GFileAttributeMatcher));
+  result->ref = 1;
+  result->sub_matchers = g_array_new (FALSE, FALSE, sizeof (SubMatcher));
+
+  si = 0;
+  g_assert (subtract->sub_matchers->len > 0);
+  ssub = &g_array_index (subtract->sub_matchers, SubMatcher, si);
+
+  for (mi = 0; mi < matcher->sub_matchers->len; mi++)
+    {
+      msub = &g_array_index (matcher->sub_matchers, SubMatcher, mi);
+
+retry:
+      if (sub_matcher_matches (ssub, msub))
+        continue;
+
+      si++;
+      if (si >= subtract->sub_matchers->len)
+        break;
+
+      ssub = &g_array_index (subtract->sub_matchers, SubMatcher, si);
+      if (ssub->id <= msub->id)
+        goto retry;
+
+      g_array_append_val (result->sub_matchers, *msub);
+    }
+
+  if (mi < matcher->sub_matchers->len)
+    g_array_append_vals (result->sub_matchers,
+                         &g_array_index (matcher->sub_matchers, SubMatcher, mi),
+                         matcher->sub_matchers->len - mi);
+
+  result = matcher_optimize (result);
+
+  return result;
+}
+
+/**
  * g_file_attribute_matcher_ref:
  * @matcher: a #GFileAttributeMatcher.
- * 
+ *
  * References a file attribute matcher.
- * 
+ *
  * Returns: a #GFileAttributeMatcher.
  **/
 GFileAttributeMatcher *
@@ -2252,10 +2365,10 @@ g_file_attribute_matcher_ref (GFileAttributeMatcher *matcher)
 /**
  * g_file_attribute_matcher_unref:
  * @matcher: a #GFileAttributeMatcher.
- * 
- * Unreferences @matcher. If the reference count falls below 1, 
+ *
+ * Unreferences @matcher. If the reference count falls below 1,
  * the @matcher is automatically freed.
- * 
+ *
  **/
 void
 g_file_attribute_matcher_unref (GFileAttributeMatcher *matcher)
@@ -2263,12 +2376,12 @@ g_file_attribute_matcher_unref (GFileAttributeMatcher *matcher)
   if (matcher)
     {
       g_return_if_fail (matcher->ref > 0);
-      
+
       if (g_atomic_int_dec_and_test (&matcher->ref))
        {
-         if (matcher->more_sub_matchers)
-           g_array_free (matcher->more_sub_matchers, TRUE);
-         
+         if (matcher->sub_matchers)
+           g_array_free (matcher->sub_matchers, TRUE);
+
          g_free (matcher);
        }
     }
@@ -2278,16 +2391,17 @@ g_file_attribute_matcher_unref (GFileAttributeMatcher *matcher)
  * g_file_attribute_matcher_matches_only:
  * @matcher: a #GFileAttributeMatcher.
  * @attribute: a file attribute key.
- * 
+ *
  * Checks if a attribute matcher only matches a given attribute. Always
  * returns %FALSE if "*" was used when creating the matcher.
- * 
+ *
  * Returns: %TRUE if the matcher only matches @attribute. %FALSE otherwise.
  **/
 gboolean
 g_file_attribute_matcher_matches_only (GFileAttributeMatcher *matcher,
                                       const char            *attribute)
 {
+  SubMatcher *sub_matcher;
   guint32 id;
 
   g_return_val_if_fail (attribute != NULL && *attribute != '\0', FALSE);
@@ -2295,16 +2409,16 @@ g_file_attribute_matcher_matches_only (GFileAttributeMatcher *matcher,
   if (matcher == NULL ||
       matcher->all)
     return FALSE;
+
+  if (matcher->sub_matchers->len != 1)
+    return FALSE;
   
   id = lookup_attribute (attribute);
-
-  if (matcher->sub_matchers[0].id != 0 &&
-      matcher->sub_matchers[1].id == 0 &&
-      matcher->sub_matchers[0].mask == 0xffffffff &&
-      matcher->sub_matchers[0].id == id)
-    return TRUE;
   
-  return FALSE;
+  sub_matcher = &g_array_index (matcher->sub_matchers, SubMatcher, 0);
+  
+  return sub_matcher->id == id &&
+         sub_matcher->mask == 0xffffffff;
 }
 
 static gboolean
@@ -2313,26 +2427,17 @@ matcher_matches_id (GFileAttributeMatcher *matcher,
 {
   SubMatcher *sub_matchers;
   int i;
-  
-  for (i = 0; i < ON_STACK_MATCHERS; i++)
-    {
-      if (matcher->sub_matchers[i].id == 0)
-       return FALSE;
-      
-      if (matcher->sub_matchers[i].id == (id & matcher->sub_matchers[i].mask))
-       return TRUE;
-    }
 
-  if (matcher->more_sub_matchers)
+  if (matcher->sub_matchers)
     {
-      sub_matchers = (SubMatcher *)matcher->more_sub_matchers->data;
-      for (i = 0; i < matcher->more_sub_matchers->len; i++)
+      sub_matchers = (SubMatcher *)matcher->sub_matchers->data;
+      for (i = 0; i < matcher->sub_matchers->len; i++)
        {
          if (sub_matchers[i].id == (id & sub_matchers[i].mask))
            return TRUE;
        }
     }
-  
+
   return FALSE;
 }
 
@@ -2343,10 +2448,10 @@ _g_file_attribute_matcher_matches_id (GFileAttributeMatcher *matcher,
   /* We return a NULL matcher for an empty match string, so handle this */
   if (matcher == NULL)
     return FALSE;
-  
+
   if (matcher->all)
     return TRUE;
-  
+
   return matcher_matches_id (matcher, id);
 }
 
@@ -2355,10 +2460,10 @@ _g_file_attribute_matcher_matches_id (GFileAttributeMatcher *matcher,
  * @matcher: a #GFileAttributeMatcher.
  * @attribute: a file attribute key.
  *
- * Checks if an attribute will be matched by an attribute matcher. If 
+ * Checks if an attribute will be matched by an attribute matcher. If
  * the matcher was created with the "*" matching string, this function
  * will always return %TRUE.
- * 
+ *
  * Returns: %TRUE if @attribute matches @matcher. %FALSE otherwise.
  **/
 gboolean
@@ -2370,10 +2475,10 @@ g_file_attribute_matcher_matches (GFileAttributeMatcher *matcher,
   /* We return a NULL matcher for an empty match string, so handle this */
   if (matcher == NULL)
     return FALSE;
-  
+
   if (matcher->all)
     return TRUE;
-  
+
   return matcher_matches_id (matcher, lookup_attribute (attribute));
 }
 
@@ -2382,14 +2487,14 @@ g_file_attribute_matcher_matches (GFileAttributeMatcher *matcher,
  * g_file_attribute_matcher_enumerate_namespace:
  * @matcher: a #GFileAttributeMatcher.
  * @ns: a string containing a file attribute namespace.
- * 
+ *
  * Checks if the matcher will match all of the keys in a given namespace.
- * This will always return %TRUE if a wildcard character is in use (e.g. if 
+ * This will always return %TRUE if a wildcard character is in use (e.g. if
  * matcher was created with "standard::*" and @ns is "standard", or if matcher was created
- * using "*" and namespace is anything.) 
- * 
+ * using "*" and namespace is anything.)
+ *
  * TODO: this is awkwardly worded.
- * 
+ *
  * Returns: %TRUE if the matcher matches all of the entries
  * in the given @ns, %FALSE otherwise.
  **/
@@ -2400,28 +2505,22 @@ g_file_attribute_matcher_enumerate_namespace (GFileAttributeMatcher *matcher,
   SubMatcher *sub_matchers;
   int ns_id;
   int i;
-  
+
   g_return_val_if_fail (ns != NULL && *ns != '\0', FALSE);
 
   /* We return a NULL matcher for an empty match string, so handle this */
   if (matcher == NULL)
     return FALSE;
-  
+
   if (matcher->all)
     return TRUE;
 
   ns_id = lookup_namespace (ns) << NS_POS;
 
-  for (i = 0; i < ON_STACK_MATCHERS; i++)
+  if (matcher->sub_matchers)
     {
-      if (matcher->sub_matchers[i].id == ns_id)
-       return TRUE;
-    }
-
-  if (matcher->more_sub_matchers)
-    {
-      sub_matchers = (SubMatcher *)matcher->more_sub_matchers->data;
-      for (i = 0; i < matcher->more_sub_matchers->len; i++)
+      sub_matchers = (SubMatcher *)matcher->sub_matchers->data;
+      for (i = 0; i < matcher->sub_matchers->len; i++)
        {
          if (sub_matchers[i].id == ns_id)
            return TRUE;
@@ -2430,17 +2529,17 @@ g_file_attribute_matcher_enumerate_namespace (GFileAttributeMatcher *matcher,
 
   matcher->iterator_ns = ns_id;
   matcher->iterator_pos = 0;
-  
+
   return FALSE;
 }
 
 /**
  * g_file_attribute_matcher_enumerate_next:
  * @matcher: a #GFileAttributeMatcher.
- * 
+ *
  * Gets the next matched attribute from a #GFileAttributeMatcher.
- * 
- * Returns: a string containing the next attribute or %NULL if 
+ *
+ * Returns: a string containing the next attribute or %NULL if
  * no more attribute exist.
  **/
 const char *
@@ -2457,24 +2556,13 @@ g_file_attribute_matcher_enumerate_next (GFileAttributeMatcher *matcher)
     {
       i = matcher->iterator_pos++;
 
-      if (i < ON_STACK_MATCHERS)
-       {
-         if (matcher->sub_matchers[i].id == 0)
-           return NULL;
+      if (matcher->sub_matchers == NULL)
+        return NULL;
 
-         sub_matcher = &matcher->sub_matchers[i];
-       }
+      if (i < matcher->sub_matchers->len)
+        sub_matcher = &g_array_index (matcher->sub_matchers, SubMatcher, i);
       else
-       {
-         if (matcher->more_sub_matchers == NULL)
-           return NULL;
-      
-         i -= ON_STACK_MATCHERS;
-         if (i < matcher->more_sub_matchers->len)
-           sub_matcher = &g_array_index (matcher->more_sub_matchers, SubMatcher, i);
-         else
-           return NULL;
-       }
+        return NULL;
 
       if (sub_matcher->mask == 0xffffffff &&
          (sub_matcher->id & (NS_MASK << NS_POS)) == matcher->iterator_ns)
@@ -2482,5 +2570,42 @@ g_file_attribute_matcher_enumerate_next (GFileAttributeMatcher *matcher)
     }
 }
 
-#define __G_FILE_INFO_C__
-#include "gioaliasdef.c"
+/**
+ * g_file_attribute_matcher_to_string:
+ * @matcher: (allow-none): a #GFileAttributeMatcher.
+ *
+ * Prints what the matcher is matching against. The format will be 
+ * equal to the format passed to g_file_attribute_matcher_new().
+ * The output however, might not be identical, as the matcher may
+ * decide to use a different order or omit needless parts.
+ *
+ * Returns: a string describing the attributes the matcher matches
+ *   against or %NULL if @matcher was %NULL.
+ *
+ * Since: 2.32
+ **/
+char *
+g_file_attribute_matcher_to_string (GFileAttributeMatcher *matcher)
+{
+  GString *string;
+  guint i;
+
+  if (matcher == NULL)
+    return NULL;
+
+  if (matcher->all)
+    return g_strdup ("*");
+
+  string = g_string_new ("");
+  for (i = 0; i < matcher->sub_matchers->len; i++)
+    {
+      SubMatcher *submatcher = &g_array_index (matcher->sub_matchers, SubMatcher, i);
+
+      if (i > 0)
+        g_string_append_c (string, ',');
+
+      g_string_append (string, get_attribute_for_id (submatcher->id));
+    }
+
+  return g_string_free (string, FALSE);
+}