1 /* GIO - GLib Input, Output and Streaming Library
3 * Copyright (C) 2006-2007 Red Hat, Inc.
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General
16 * Public License along with this library; if not, write to the
17 * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
18 * Boston, MA 02111-1307, USA.
20 * Author: Alexander Larsson <alexl@redhat.com>
25 * @short_description: File Information and Attributes
29 * Functionality for manipulating basic metadata for files. #GFileInfo
30 * implements methods for getting information that all files should
31 * contain, and allows for manipulation of extended attributes.
32 * #GFileAttributeMatcher allows for searching through a #GFileInfo for
40 #include "gfileinfo.h"
41 #include "gfileattribute-priv.h"
46 /* We use this nasty thing, because NULL is a valid attribute matcher (matches nothing) */
47 #define NO_ATTRIBUTE_MASK ((GFileAttributeMatcher *)1)
51 GFileAttributeValue value;
56 GObject parent_instance;
59 GFileAttributeMatcher *mask;
62 struct _GFileInfoClass
64 GObjectClass parent_class;
68 static gboolean g_file_attribute_matcher_matches_id (GFileAttributeMatcher *matcher,
71 G_DEFINE_TYPE (GFileInfo, g_file_info, G_TYPE_OBJECT);
75 guint32 attribute_id_counter;
78 G_LOCK_DEFINE_STATIC (attribute_hash);
79 static int namespace_id_counter = 0;
80 static GHashTable *ns_hash = NULL;
81 static GHashTable *attribute_hash = NULL;
82 static char ***attributes = NULL;
84 /* Attribute ids are 32bit, we split it up like this:
85 * |------------|--------------------|
87 * namespace attribute id
89 * This way the attributes gets sorted in namespace order
93 #define NS_MASK ((guint32)((1<<12) - 1))
95 #define ID_MASK ((guint32)((1<<20) - 1))
97 #define GET_NS(_attr_id) \
98 (((guint32) (_attr_id) >> NS_POS) & NS_MASK)
99 #define GET_ID(_attr_id) \
100 (((guint32)(_attr_id) >> ID_POS) & ID_MASK)
102 #define MAKE_ATTR_ID(_ns, _id) \
103 ( ((((guint32) _ns) & NS_MASK) << NS_POS) | \
104 ((((guint32) _id) & ID_MASK) << ID_POS) )
107 _lookup_namespace (const char *namespace)
111 ns_info = g_hash_table_lookup (ns_hash, namespace);
114 ns_info = g_new0 (NSInfo, 1);
115 ns_info->id = ++namespace_id_counter;
116 g_hash_table_insert (ns_hash, g_strdup (namespace), ns_info);
117 attributes = g_realloc (attributes, (ns_info->id + 1) * sizeof (char **));
118 attributes[ns_info->id] = NULL;
124 lookup_namespace (const char *namespace)
129 G_LOCK (attribute_hash);
131 if (attribute_hash == NULL)
133 ns_hash = g_hash_table_new (g_str_hash, g_str_equal);
134 attribute_hash = g_hash_table_new (g_str_hash, g_str_equal);
137 ns_info = _lookup_namespace (namespace);
142 G_UNLOCK (attribute_hash);
148 get_attribute_for_id (int attribute)
151 G_LOCK (attribute_hash);
152 s = attributes[GET_NS(attribute)][GET_ID(attribute)];
153 G_UNLOCK (attribute_hash);
158 lookup_attribute (const char *attribute)
165 G_LOCK (attribute_hash);
166 if (attribute_hash == NULL)
168 ns_hash = g_hash_table_new (g_str_hash, g_str_equal);
169 attribute_hash = g_hash_table_new (g_str_hash, g_str_equal);
172 attr_id = GPOINTER_TO_UINT (g_hash_table_lookup (attribute_hash, attribute));
176 G_UNLOCK (attribute_hash);
180 colon = strstr (attribute, "::");
182 ns = g_strndup (attribute, colon - attribute);
186 ns_info = _lookup_namespace (ns);
189 id = ++ns_info->attribute_id_counter;
190 attributes[ns_info->id] = g_realloc (attributes[ns_info->id], (id + 1) * sizeof (char *));
191 attributes[ns_info->id][id] = g_strdup (attribute);
193 attr_id = MAKE_ATTR_ID (ns_info->id, id);
195 g_hash_table_insert (attribute_hash, attributes[ns_info->id][id], GUINT_TO_POINTER (attr_id));
197 G_UNLOCK (attribute_hash);
203 g_file_info_finalize (GObject *object)
207 GFileAttribute *attrs;
209 info = G_FILE_INFO (object);
211 attrs = (GFileAttribute *)info->attributes->data;
212 for (i = 0; i < info->attributes->len; i++)
213 _g_file_attribute_value_clear (&attrs[i].value);
214 g_array_free (info->attributes, TRUE);
216 if (info->mask != NO_ATTRIBUTE_MASK)
217 g_file_attribute_matcher_unref (info->mask);
219 if (G_OBJECT_CLASS (g_file_info_parent_class)->finalize)
220 (*G_OBJECT_CLASS (g_file_info_parent_class)->finalize) (object);
224 g_file_info_class_init (GFileInfoClass *klass)
226 GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
228 gobject_class->finalize = g_file_info_finalize;
232 g_file_info_init (GFileInfo *info)
234 info->mask = NO_ATTRIBUTE_MASK;
235 info->attributes = g_array_new (FALSE, FALSE,
236 sizeof (GFileAttribute));
242 * Creates a new file info structure.
244 * Returns: a #GFileInfo.
247 g_file_info_new (void)
249 return g_object_new (G_TYPE_FILE_INFO, NULL);
253 * g_file_info_copy_into:
254 * @src_info: source to copy attributes from.
255 * @dest_info: destination to copy attributes to.
257 * Copies all of the #GFileAttribute<!-- -->s from @src_info to @dest_info.
260 g_file_info_copy_into (GFileInfo *src_info,
261 GFileInfo *dest_info)
263 GFileAttribute *source, *dest;
266 g_return_if_fail (G_IS_FILE_INFO (src_info));
267 g_return_if_fail (G_IS_FILE_INFO (dest_info));
269 dest = (GFileAttribute *)dest_info->attributes->data;
270 for (i = 0; i < dest_info->attributes->len; i++)
271 _g_file_attribute_value_clear (&dest[i].value);
273 g_array_set_size (dest_info->attributes,
274 src_info->attributes->len);
276 source = (GFileAttribute *)src_info->attributes->data;
277 dest = (GFileAttribute *)dest_info->attributes->data;
279 for (i = 0; i < src_info->attributes->len; i++)
281 dest[i].attribute = source[i].attribute;
282 dest[i].value.type = G_FILE_ATTRIBUTE_TYPE_INVALID;
283 _g_file_attribute_value_set (&dest[i].value, &source[i].value);
286 if (src_info->mask == NO_ATTRIBUTE_MASK)
287 dest_info->mask = NO_ATTRIBUTE_MASK;
289 dest_info->mask = g_file_attribute_matcher_ref (src_info->mask);
294 * @other: a #GFileInfo.
296 * Duplicates a file info structure.
298 * Returns: a duplicate #GFileInfo of @other.
301 g_file_info_dup (GFileInfo *other)
305 g_return_val_if_fail (G_IS_FILE_INFO (other), NULL);
307 new = g_file_info_new ();
308 g_file_info_copy_into (other, new);
313 * g_file_info_set_attribute_mask:
314 * @info: a #GFileInfo.
315 * @mask: a #GFileAttributeMatcher.
317 * Sets @mask on @info to match specific attribute types.
320 g_file_info_set_attribute_mask (GFileInfo *info,
321 GFileAttributeMatcher *mask)
323 GFileAttribute *attr;
326 g_return_if_fail (G_IS_FILE_INFO (info));
327 g_return_if_fail (mask != NULL);
329 if (mask != info->mask)
331 if (info->mask != NO_ATTRIBUTE_MASK)
332 g_file_attribute_matcher_unref (info->mask);
333 info->mask = g_file_attribute_matcher_ref (mask);
335 /* Remove non-matching attributes */
336 for (i = 0; i < info->attributes->len; i++)
338 attr = &g_array_index (info->attributes, GFileAttribute, i);
339 if (!g_file_attribute_matcher_matches_id (mask,
342 _g_file_attribute_value_clear (&attr->value);
343 g_array_remove_index (info->attributes, i);
351 * g_file_info_unset_attribute_mask:
354 * Unsets a mask set by g_file_info_set_attribute_mask(), if one
358 g_file_info_unset_attribute_mask (GFileInfo *info)
360 g_return_if_fail (G_IS_FILE_INFO (info));
362 if (info->mask != NO_ATTRIBUTE_MASK)
363 g_file_attribute_matcher_unref (info->mask);
364 info->mask = NO_ATTRIBUTE_MASK;
368 * g_file_info_clear_status:
369 * @info: a #GFileInfo.
371 * Clears the status information from @info.
374 g_file_info_clear_status (GFileInfo *info)
376 GFileAttribute *attrs;
379 g_return_if_fail (G_IS_FILE_INFO (info));
381 attrs = (GFileAttribute *)info->attributes->data;
382 for (i = 0; i < info->attributes->len; i++)
383 attrs[i].value.status = G_FILE_ATTRIBUTE_STATUS_UNSET;
387 g_file_info_find_place (GFileInfo *info,
391 GFileAttribute *attrs;
392 /* Binary search for the place where attribute would be, if its
396 max = info->attributes->len;
398 attrs = (GFileAttribute *)info->attributes->data;
402 med = min + (max - min) / 2;
403 if (attrs[med].attribute == attribute)
408 else if (attrs[med].attribute < attribute)
410 else /* attrs[med].attribute > attribute */
417 static GFileAttributeValue *
418 g_file_info_find_value (GFileInfo *info,
421 GFileAttribute *attrs;
424 i = g_file_info_find_place (info, attr_id);
425 attrs = (GFileAttribute *)info->attributes->data;
426 if (i < info->attributes->len &&
427 attrs[i].attribute == attr_id)
428 return &attrs[i].value;
433 static GFileAttributeValue *
434 g_file_info_find_value_by_name (GFileInfo *info,
435 const char *attribute)
439 attr_id = lookup_attribute (attribute);
440 return g_file_info_find_value (info, attr_id);
444 * g_file_info_has_attribute:
445 * @info: a #GFileInfo.
446 * @attribute: a file attribute key.
448 * Checks if a file info structure has an attribute named @attribute.
450 * Returns: %TRUE if @GFileInfo has an attribute named @attribute,
454 g_file_info_has_attribute (GFileInfo *info,
455 const char *attribute)
457 GFileAttributeValue *value;
459 g_return_val_if_fail (G_IS_FILE_INFO (info), FALSE);
460 g_return_val_if_fail (attribute != NULL && *attribute != '\0', FALSE);
462 value = g_file_info_find_value_by_name (info, attribute);
463 return value != NULL;
467 * g_file_info_list_attributes:
468 * @info: a #GFileInfo.
469 * @name_space: a file attribute key's namespace.
471 * Lists the file info structure's attributes.
473 * Returns: a null-terminated array of strings of all of the
474 * possible attribute types for the given @name_space, or
478 g_file_info_list_attributes (GFileInfo *info,
479 const char *name_space)
482 GFileAttribute *attrs;
484 guint32 ns_id = (name_space) ? lookup_namespace (name_space) : 0;
487 g_return_val_if_fail (G_IS_FILE_INFO (info), NULL);
489 names = g_ptr_array_new ();
490 attrs = (GFileAttribute *)info->attributes->data;
491 for (i = 0; i < info->attributes->len; i++)
493 attribute = attrs[i].attribute;
494 if (ns_id == 0 || GET_NS (attribute) == ns_id)
495 g_ptr_array_add (names, g_strdup (get_attribute_for_id (attribute)));
499 g_ptr_array_add (names, NULL);
501 return (char **)g_ptr_array_free (names, FALSE);
505 * g_file_info_get_attribute_type:
506 * @info: a #GFileInfo.
507 * @attribute: a file attribute key.
509 * Gets the attribute type for an attribute key.
511 * Returns: a #GFileAttributeType for the given @attribute, or
512 * %G_FILE_ATTRIBUTE_TYPE_INVALID if the key is invalid.
515 g_file_info_get_attribute_type (GFileInfo *info,
516 const char *attribute)
518 GFileAttributeValue *value;
520 g_return_val_if_fail (G_IS_FILE_INFO (info), G_FILE_ATTRIBUTE_TYPE_INVALID);
521 g_return_val_if_fail (attribute != NULL && *attribute != '\0', G_FILE_ATTRIBUTE_TYPE_INVALID);
523 value = g_file_info_find_value_by_name (info, attribute);
527 return G_FILE_ATTRIBUTE_TYPE_INVALID;
531 * g_file_info_remove_attribute:
532 * @info: a #GFileInfo.
533 * @attribute: a file attribute key.
535 * Removes all cases of @attribute from @info if it exists.
539 g_file_info_remove_attribute (GFileInfo *info,
540 const char *attribute)
543 GFileAttribute *attrs;
546 g_return_if_fail (G_IS_FILE_INFO (info));
547 g_return_if_fail (attribute != NULL && *attribute != '\0');
549 attr_id = lookup_attribute (attribute);
551 i = g_file_info_find_place (info, attr_id);
552 attrs = (GFileAttribute *)info->attributes->data;
553 if (i < info->attributes->len &&
554 attrs[i].attribute == attr_id)
556 _g_file_attribute_value_clear (&attrs[i].value);
557 g_array_remove_index (info->attributes, i);
562 g_file_info_get_attribute_data (GFileInfo *info,
563 const char *attribute,
564 GFileAttributeType *type,
566 GFileAttributeStatus *status)
568 GFileAttributeValue *value;
570 value = g_file_info_find_value_by_name (info, attribute);
575 *status = value->status;
581 *value_pp = _g_file_attribute_value_peek_as_pointer (value);
587 g_file_info_get_attribute_status (GFileInfo *info,
588 const char *attribute)
590 GFileAttributeValue *val;
592 g_return_val_if_fail (G_IS_FILE_INFO (info), 0);
593 g_return_val_if_fail (attribute != NULL && *attribute != '\0', 0);
595 val = g_file_info_find_value_by_name (info, attribute);
603 GFileAttributeValue *
604 _g_file_info_get_attribute_value (GFileInfo *info,
605 const char *attribute)
608 g_return_val_if_fail (G_IS_FILE_INFO (info), NULL);
609 g_return_val_if_fail (attribute != NULL && *attribute != '\0', NULL);
611 return g_file_info_find_value_by_name (info, attribute);
615 * g_file_info_get_attribute_as_string:
616 * @info: a #GFileInfo.
617 * @attribute: a file attribute key.
619 * Gets the value of a attribute, formated as a string.
620 * This escapes things as needed to make the string valid
623 * Returns: a utf8 string associated with the given @attribute.
624 * When you're done with the string it must be freed.
627 g_file_info_get_attribute_as_string (GFileInfo *info,
628 const char *attribute)
630 GFileAttributeValue *val;
631 val = _g_file_info_get_attribute_value (info, attribute);
633 return _g_file_attribute_value_as_string (val);
639 * g_file_info_get_attribute_object:
640 * @info: a #GFileInfo.
641 * @attribute: a file attribute key.
643 * Gets the value of a #GObject attribute. If the attribute does
644 * not contain a #GObject, %NULL will be returned.
646 * Returns: a #GObject associated with the given @attribute, or
650 g_file_info_get_attribute_object (GFileInfo *info,
651 const char *attribute)
653 GFileAttributeValue *value;
655 g_return_val_if_fail (G_IS_FILE_INFO (info), NULL);
656 g_return_val_if_fail (attribute != NULL && *attribute != '\0', NULL);
658 value = g_file_info_find_value_by_name (info, attribute);
659 return _g_file_attribute_value_get_object (value);
663 * g_file_info_get_attribute_string:
664 * @info: a #GFileInfo.
665 * @attribute: a file attribute key.
667 * Gets the value of a string attribute. If the attribute does
668 * not contain a string, %NULL will be returned.
670 * Returns: the contents of the @attribute value as a string, or
674 g_file_info_get_attribute_string (GFileInfo *info,
675 const char *attribute)
677 GFileAttributeValue *value;
679 g_return_val_if_fail (G_IS_FILE_INFO (info), NULL);
680 g_return_val_if_fail (attribute != NULL && *attribute != '\0', NULL);
682 value = g_file_info_find_value_by_name (info, attribute);
683 return _g_file_attribute_value_get_string (value);
687 * g_file_info_get_attribute_byte_string:
688 * @info: a #GFileInfo.
689 * @attribute: a file attribute key.
691 * Gets the value of a byte string attribute. If the attribute does
692 * not contain a byte string, %NULL will be returned.
694 * Returns: the contents of the @attribute value as a byte string, or
698 g_file_info_get_attribute_byte_string (GFileInfo *info,
699 const char *attribute)
701 GFileAttributeValue *value;
703 g_return_val_if_fail (G_IS_FILE_INFO (info), NULL);
704 g_return_val_if_fail (attribute != NULL && *attribute != '\0', NULL);
706 value = g_file_info_find_value_by_name (info, attribute);
707 return _g_file_attribute_value_get_byte_string (value);
711 * g_file_info_get_attribute_boolean:
712 * @info: a #GFileInfo.
713 * @attribute: a file attribute key.
715 * Gets the value of a boolean attribute. If the attribute does not
716 * contain a boolean value, %FALSE will be returned.
718 * Returns: the boolean value contained within the attribute.
721 g_file_info_get_attribute_boolean (GFileInfo *info,
722 const char *attribute)
724 GFileAttributeValue *value;
726 g_return_val_if_fail (G_IS_FILE_INFO (info), FALSE);
727 g_return_val_if_fail (attribute != NULL && *attribute != '\0', FALSE);
729 value = g_file_info_find_value_by_name (info, attribute);
730 return _g_file_attribute_value_get_boolean (value);
734 * g_file_info_get_attribute_uint32:
735 * @info: a #GFileInfo.
736 * @attribute: a file attribute key.
738 * Gets an unsigned 32-bit integer contained within the attribute. If the
739 * attribute does not contain an unsigned 32-bit integer, or is invalid,
740 * 0 will be returned.
742 * Returns: an unsigned 32-bit integer from the attribute.
745 g_file_info_get_attribute_uint32 (GFileInfo *info,
746 const char *attribute)
748 GFileAttributeValue *value;
750 g_return_val_if_fail (G_IS_FILE_INFO (info), 0);
751 g_return_val_if_fail (attribute != NULL && *attribute != '\0', 0);
753 value = g_file_info_find_value_by_name (info, attribute);
754 return _g_file_attribute_value_get_uint32 (value);
758 * g_file_info_get_attribute_int32:
759 * @info: a #GFileInfo.
760 * @attribute: a file attribute key.
762 * Gets a signed 32-bit integer contained within the attribute. If the
763 * attribute does not contain a signed 32-bit integer, or is invalid,
764 * 0 will be returned.
766 * Returns: a signed 32-bit integer from the attribute.
769 g_file_info_get_attribute_int32 (GFileInfo *info,
770 const char *attribute)
772 GFileAttributeValue *value;
774 g_return_val_if_fail (G_IS_FILE_INFO (info), 0);
775 g_return_val_if_fail (attribute != NULL && *attribute != '\0', 0);
777 value = g_file_info_find_value_by_name (info, attribute);
778 return _g_file_attribute_value_get_int32 (value);
782 * g_file_info_get_attribute_uint64:
783 * @info: a #GFileInfo.
784 * @attribute: a file attribute key.
786 * Gets a unsigned 64-bit integer contained within the attribute. If the
787 * attribute does not contain an unsigned 64-bit integer, or is invalid,
788 * 0 will be returned.
790 * Returns: a unsigned 64-bit integer from the attribute.
793 g_file_info_get_attribute_uint64 (GFileInfo *info,
794 const char *attribute)
796 GFileAttributeValue *value;
798 g_return_val_if_fail (G_IS_FILE_INFO (info), 0);
799 g_return_val_if_fail (attribute != NULL && *attribute != '\0', 0);
801 value = g_file_info_find_value_by_name (info, attribute);
802 return _g_file_attribute_value_get_uint64 (value);
806 * g_file_info_get_attribute_int64:
807 * @info: a #GFileInfo.
808 * @attribute: a file attribute key.
810 * Gets a signed 64-bit integer contained within the attribute. If the
811 * attribute does not contain an signed 64-bit integer, or is invalid,
812 * 0 will be returned.
814 * Returns: a signed 64-bit integer from the attribute.
817 g_file_info_get_attribute_int64 (GFileInfo *info,
818 const char *attribute)
820 GFileAttributeValue *value;
822 g_return_val_if_fail (G_IS_FILE_INFO (info), 0);
823 g_return_val_if_fail (attribute != NULL && *attribute != '\0', 0);
825 value = g_file_info_find_value_by_name (info, attribute);
826 return _g_file_attribute_value_get_int64 (value);
829 static GFileAttributeValue *
830 g_file_info_create_value (GFileInfo *info,
833 GFileAttribute *attrs;
836 if (info->mask != NO_ATTRIBUTE_MASK &&
837 !g_file_attribute_matcher_matches_id (info->mask, attr_id))
840 i = g_file_info_find_place (info, attr_id);
842 attrs = (GFileAttribute *)info->attributes->data;
843 if (i < info->attributes->len &&
844 attrs[i].attribute == attr_id)
845 return &attrs[i].value;
848 GFileAttribute attr = { 0 };
849 attr.attribute = attr_id;
850 g_array_insert_val (info->attributes, i, attr);
852 attrs = (GFileAttribute *)info->attributes->data;
853 return &attrs[i].value;
857 static GFileAttributeValue *
858 g_file_info_create_value_by_name (GFileInfo *info,
859 const char *attribute)
863 attr_id = lookup_attribute (attribute);
865 return g_file_info_create_value (info, attr_id);
869 * g_file_info_set_attribute:
870 * @info: a #GFileInfo.
871 * @attribute: a file attribute key.
872 * @type: a #GFileAttributeType
873 * @value_p: pointer to the value
875 * Sets the @attribute to contain the given value, if possible.
878 g_file_info_set_attribute (GFileInfo *info,
879 const char *attribute,
880 GFileAttributeType type,
883 GFileAttributeValue *value;
885 g_return_if_fail (G_IS_FILE_INFO (info));
886 g_return_if_fail (attribute != NULL && *attribute != '\0');
888 value = g_file_info_create_value_by_name (info, attribute);
891 _g_file_attribute_value_set_from_pointer (value, type, value_p, TRUE);
895 * g_file_info_set_attribute_object:
896 * @info: a #GFileInfo.
897 * @attribute: a file attribute key.
898 * @attr_value: a #GObject.
900 * Sets the @attribute to contain the given @attr_value,
904 g_file_info_set_attribute_object (GFileInfo *info,
905 const char *attribute,
908 GFileAttributeValue *value;
910 g_return_if_fail (G_IS_FILE_INFO (info));
911 g_return_if_fail (attribute != NULL && *attribute != '\0');
912 g_return_if_fail (G_IS_OBJECT (attr_value));
914 value = g_file_info_create_value_by_name (info, attribute);
916 _g_file_attribute_value_set_object (value, attr_value);
920 * g_file_info_set_attribute_string:
921 * @info: a #GFileInfo.
922 * @attribute: a file attribute key.
923 * @attr_value: a string.
925 * Sets the @attribute to contain the given @attr_value,
929 g_file_info_set_attribute_string (GFileInfo *info,
930 const char *attribute,
931 const char *attr_value)
933 GFileAttributeValue *value;
935 g_return_if_fail (G_IS_FILE_INFO (info));
936 g_return_if_fail (attribute != NULL && *attribute != '\0');
937 g_return_if_fail (attr_value != NULL);
939 value = g_file_info_create_value_by_name (info, attribute);
941 _g_file_attribute_value_set_string (value, attr_value);
945 * g_file_info_set_attribute_byte_string:
946 * @info: a #GFileInfo.
947 * @attribute: a file attribute key.
948 * @attr_value: a byte string.
950 * Sets the @attribute to contain the given @attr_value,
954 g_file_info_set_attribute_byte_string (GFileInfo *info,
955 const char *attribute,
956 const char *attr_value)
958 GFileAttributeValue *value;
960 g_return_if_fail (G_IS_FILE_INFO (info));
961 g_return_if_fail (attribute != NULL && *attribute != '\0');
962 g_return_if_fail (attr_value != NULL);
964 value = g_file_info_create_value_by_name (info, attribute);
966 _g_file_attribute_value_set_byte_string (value, attr_value);
970 * g_file_info_set_attribute_boolean:
971 * @info: a #GFileInfo.
972 * @attribute: a file attribute key.
973 * @attr_value: a boolean value.
975 * Sets the @attribute to contain the given @attr_value,
979 g_file_info_set_attribute_boolean (GFileInfo *info,
980 const char *attribute,
983 GFileAttributeValue *value;
985 g_return_if_fail (G_IS_FILE_INFO (info));
986 g_return_if_fail (attribute != NULL && *attribute != '\0');
988 value = g_file_info_create_value_by_name (info, attribute);
990 _g_file_attribute_value_set_boolean (value, attr_value);
994 * g_file_info_set_attribute_uint32:
995 * @info: a #GFileInfo.
996 * @attribute: a file attribute key.
997 * @attr_value: an unsigned 32-bit integer.
999 * Sets the @attribute to contain the given @attr_value,
1003 g_file_info_set_attribute_uint32 (GFileInfo *info,
1004 const char *attribute,
1007 GFileAttributeValue *value;
1009 g_return_if_fail (G_IS_FILE_INFO (info));
1010 g_return_if_fail (attribute != NULL && *attribute != '\0');
1012 value = g_file_info_create_value_by_name (info, attribute);
1014 _g_file_attribute_value_set_uint32 (value, attr_value);
1019 * g_file_info_set_attribute_int32:
1020 * @info: a #GFileInfo.
1021 * @attribute: a file attribute key.
1022 * @attr_value: a signed 32-bit integer
1024 * Sets the @attribute to contain the given @attr_value,
1028 g_file_info_set_attribute_int32 (GFileInfo *info,
1029 const char *attribute,
1032 GFileAttributeValue *value;
1034 g_return_if_fail (G_IS_FILE_INFO (info));
1035 g_return_if_fail (attribute != NULL && *attribute != '\0');
1037 value = g_file_info_create_value_by_name (info, attribute);
1039 _g_file_attribute_value_set_int32 (value, attr_value);
1043 * g_file_info_set_attribute_uint64:
1044 * @info: a #GFileInfo.
1045 * @attribute: a file attribute key.
1046 * @attr_value: an unsigned 64-bit integer.
1048 * Sets the @attribute to contain the given @attr_value,
1052 g_file_info_set_attribute_uint64 (GFileInfo *info,
1053 const char *attribute,
1056 GFileAttributeValue *value;
1058 g_return_if_fail (G_IS_FILE_INFO (info));
1059 g_return_if_fail (attribute != NULL && *attribute != '\0');
1061 value = g_file_info_create_value_by_name (info, attribute);
1063 _g_file_attribute_value_set_uint64 (value, attr_value);
1067 * g_file_info_set_attribute_int64:
1068 * @info: a #GFileInfo.
1069 * @attribute: attribute name to set.
1070 * @attr_value: int64 value to set attribute to.
1072 * Sets the @attribute to contain the given @attr_value,
1077 g_file_info_set_attribute_int64 (GFileInfo *info,
1078 const char *attribute,
1081 GFileAttributeValue *value;
1083 g_return_if_fail (G_IS_FILE_INFO (info));
1084 g_return_if_fail (attribute != NULL && *attribute != '\0');
1086 value = g_file_info_create_value_by_name (info, attribute);
1088 _g_file_attribute_value_set_int64 (value, attr_value);
1091 /* Helper getters */
1093 * g_file_info_get_file_type:
1094 * @info: a #GFileInfo.
1096 * Gets a file's type (whether it is a regular file, symlink, etc).
1097 * This is different from the file's content type, see g_file_info_get_content_type().
1099 * Returns: a #GFileType for the given file.
1102 g_file_info_get_file_type (GFileInfo *info)
1104 static guint32 attr = 0;
1105 GFileAttributeValue *value;
1107 g_return_val_if_fail (G_IS_FILE_INFO (info), G_FILE_TYPE_UNKNOWN);
1110 attr = lookup_attribute (G_FILE_ATTRIBUTE_STANDARD_TYPE);
1112 value = g_file_info_find_value (info, attr);
1113 return (GFileType)_g_file_attribute_value_get_uint32 (value);
1117 * g_file_info_get_is_hidden:
1118 * @info: a #GFileInfo.
1120 * Checks if a file is hidden.
1122 * Returns: %TRUE if the file is a hidden file, %FALSE otherwise.
1125 g_file_info_get_is_hidden (GFileInfo *info)
1127 static guint32 attr = 0;
1128 GFileAttributeValue *value;
1130 g_return_val_if_fail (G_IS_FILE_INFO (info), FALSE);
1133 attr = lookup_attribute (G_FILE_ATTRIBUTE_STANDARD_IS_HIDDEN);
1135 value = g_file_info_find_value (info, attr);
1136 return (GFileType)_g_file_attribute_value_get_boolean (value);
1140 * g_file_info_get_is_backup:
1141 * @info: a #GFileInfo.
1143 * Checks if a file is a backup file.
1145 * Returns: %TRUE if file is a backup file, %FALSE otherwise.
1148 g_file_info_get_is_backup (GFileInfo *info)
1150 static guint32 attr = 0;
1151 GFileAttributeValue *value;
1153 g_return_val_if_fail (G_IS_FILE_INFO (info), FALSE);
1156 attr = lookup_attribute (G_FILE_ATTRIBUTE_STANDARD_IS_BACKUP);
1158 value = g_file_info_find_value (info, attr);
1159 return (GFileType)_g_file_attribute_value_get_boolean (value);
1163 * g_file_info_get_is_symlink:
1164 * @info: a #GFileInfo.
1166 * Checks if a file is a symlink.
1168 * Returns: %TRUE if the given @info is a symlink.
1171 g_file_info_get_is_symlink (GFileInfo *info)
1173 static guint32 attr = 0;
1174 GFileAttributeValue *value;
1176 g_return_val_if_fail (G_IS_FILE_INFO (info), FALSE);
1179 attr = lookup_attribute (G_FILE_ATTRIBUTE_STANDARD_IS_SYMLINK);
1181 value = g_file_info_find_value (info, attr);
1182 return (GFileType)_g_file_attribute_value_get_boolean (value);
1186 * g_file_info_get_name:
1187 * @info: a #GFileInfo.
1189 * Gets the name for a file.
1191 * Returns: a string containing the file name.
1194 g_file_info_get_name (GFileInfo *info)
1196 static guint32 attr = 0;
1197 GFileAttributeValue *value;
1199 g_return_val_if_fail (G_IS_FILE_INFO (info), NULL);
1202 attr = lookup_attribute (G_FILE_ATTRIBUTE_STANDARD_NAME);
1204 value = g_file_info_find_value (info, attr);
1205 return _g_file_attribute_value_get_byte_string (value);
1209 * g_file_info_get_display_name:
1210 * @info: a #GFileInfo.
1212 * Gets a display name for a file.
1214 * Returns: a string containing the display name.
1217 g_file_info_get_display_name (GFileInfo *info)
1219 static guint32 attr = 0;
1220 GFileAttributeValue *value;
1222 g_return_val_if_fail (G_IS_FILE_INFO (info), NULL);
1225 attr = lookup_attribute (G_FILE_ATTRIBUTE_STANDARD_DISPLAY_NAME);
1227 value = g_file_info_find_value (info, attr);
1228 return _g_file_attribute_value_get_string (value);
1232 * g_file_info_get_edit_name:
1233 * @info: a #GFileInfo.
1235 * Gets the edit name for a file.
1237 * Returns: a string containing the edit name.
1240 g_file_info_get_edit_name (GFileInfo *info)
1242 static guint32 attr = 0;
1243 GFileAttributeValue *value;
1245 g_return_val_if_fail (G_IS_FILE_INFO (info), NULL);
1248 attr = lookup_attribute (G_FILE_ATTRIBUTE_STANDARD_EDIT_NAME);
1250 value = g_file_info_find_value (info, attr);
1251 return _g_file_attribute_value_get_string (value);
1255 * g_file_info_get_icon:
1256 * @info: a #GFileInfo.
1258 * Gets the icon for a file.
1260 * Returns: #GIcon for the given @info.
1263 g_file_info_get_icon (GFileInfo *info)
1265 static guint32 attr = 0;
1266 GFileAttributeValue *value;
1269 g_return_val_if_fail (G_IS_FILE_INFO (info), NULL);
1272 attr = lookup_attribute (G_FILE_ATTRIBUTE_STANDARD_ICON);
1274 value = g_file_info_find_value (info, attr);
1275 obj = _g_file_attribute_value_get_object (value);
1276 if (obj != NULL && G_IS_ICON (obj))
1277 return G_ICON (obj);
1282 * g_file_info_get_content_type:
1283 * @info: a #GFileInfo.
1285 * Gets the file's content type.
1287 * Returns: a string containing the file's content type.s
1290 g_file_info_get_content_type (GFileInfo *info)
1292 static guint32 attr = 0;
1293 GFileAttributeValue *value;
1295 g_return_val_if_fail (G_IS_FILE_INFO (info), NULL);
1298 attr = lookup_attribute (G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE);
1300 value = g_file_info_find_value (info, attr);
1301 return _g_file_attribute_value_get_string (value);
1305 * g_file_info_get_size:
1306 * @info: a #GFileInfo.
1308 * Gets the file's size.
1310 * Returns: a #goffset containing the file's size.
1313 g_file_info_get_size (GFileInfo *info)
1315 static guint32 attr = 0;
1316 GFileAttributeValue *value;
1318 g_return_val_if_fail (G_IS_FILE_INFO (info), (goffset) 0);
1321 attr = lookup_attribute (G_FILE_ATTRIBUTE_STANDARD_SIZE);
1323 value = g_file_info_find_value (info, attr);
1324 return (goffset) _g_file_attribute_value_get_uint64 (value);
1328 * g_file_info_get_modification_time:
1329 * @info: a #GFileInfo.
1330 * @result: a #GTimeVal.
1332 * Gets the modification time of the current @info and sets it
1336 g_file_info_get_modification_time (GFileInfo *info,
1339 static guint32 attr_mtime = 0, attr_mtime_usec;
1340 GFileAttributeValue *value;
1342 g_return_if_fail (G_IS_FILE_INFO (info));
1343 g_return_if_fail (result != NULL);
1345 if (attr_mtime == 0)
1347 attr_mtime = lookup_attribute (G_FILE_ATTRIBUTE_TIME_MODIFIED);
1348 attr_mtime_usec = lookup_attribute (G_FILE_ATTRIBUTE_TIME_MODIFIED_USEC);
1351 value = g_file_info_find_value (info, attr_mtime);
1352 result->tv_sec = _g_file_attribute_value_get_uint64 (value);
1353 value = g_file_info_find_value (info, attr_mtime_usec);
1354 result->tv_usec = _g_file_attribute_value_get_uint32 (value);
1358 * g_file_info_get_symlink_target:
1359 * @info: a #GFileInfo.
1361 * Gets the symlink target for a given #GFileInfo.
1363 * Returns: a string containing the symlink target.
1366 g_file_info_get_symlink_target (GFileInfo *info)
1368 static guint32 attr = 0;
1369 GFileAttributeValue *value;
1371 g_return_val_if_fail (G_IS_FILE_INFO (info), NULL);
1374 attr = lookup_attribute (G_FILE_ATTRIBUTE_STANDARD_SYMLINK_TARGET);
1376 value = g_file_info_find_value (info, attr);
1377 return _g_file_attribute_value_get_byte_string (value);
1381 * g_file_info_get_etag:
1382 * @info: a #GFileInfo.
1384 * Gets the <link linkend="gfile-etag">entity tag</link> for a given
1385 * #GFileInfo. See %G_FILE_ATTRIBUTE_ETAG_VALUE.
1387 * Returns: a string containing the value of the "etag:value" attribute.
1390 g_file_info_get_etag (GFileInfo *info)
1392 static guint32 attr = 0;
1393 GFileAttributeValue *value;
1395 g_return_val_if_fail (G_IS_FILE_INFO (info), NULL);
1398 attr = lookup_attribute (G_FILE_ATTRIBUTE_ETAG_VALUE);
1400 value = g_file_info_find_value (info, attr);
1401 return _g_file_attribute_value_get_string (value);
1405 * g_file_info_get_sort_order:
1406 * @info: a #GFileInfo.
1408 * Gets the value of the sort_order attribute from the #GFileInfo.
1409 * See %G_FILE_ATTRIBUTE_STANDARD_SORT_ORDER.
1411 * Returns: a #gint32 containing the value of the "standard::sort_order" attribute.
1414 g_file_info_get_sort_order (GFileInfo *info)
1416 static guint32 attr = 0;
1417 GFileAttributeValue *value;
1419 g_return_val_if_fail (G_IS_FILE_INFO (info), 0);
1422 attr = lookup_attribute (G_FILE_ATTRIBUTE_STANDARD_SORT_ORDER);
1424 value = g_file_info_find_value (info, attr);
1425 return _g_file_attribute_value_get_int32 (value);
1428 /* Helper setters: */
1430 * g_file_info_set_file_type:
1431 * @info: a #GFileInfo.
1432 * @type: a #GFileType.
1434 * Sets the file type in a #GFileInfo to @type.
1435 * See %G_FILE_ATTRIBUTE_STANDARD_TYPE.
1438 g_file_info_set_file_type (GFileInfo *info,
1441 static guint32 attr = 0;
1442 GFileAttributeValue *value;
1444 g_return_if_fail (G_IS_FILE_INFO (info));
1447 attr = lookup_attribute (G_FILE_ATTRIBUTE_STANDARD_TYPE);
1449 value = g_file_info_create_value (info, attr);
1451 _g_file_attribute_value_set_uint32 (value, type);
1455 * g_file_info_set_is_hidden:
1456 * @info: a #GFileInfo.
1457 * @is_hidden: a #gboolean.
1459 * Sets the "is_hidden" attribute in a #GFileInfo according to @is_symlink.
1460 * See %G_FILE_ATTRIBUTE_STANDARD_IS_HIDDEN.
1463 g_file_info_set_is_hidden (GFileInfo *info,
1466 static guint32 attr = 0;
1467 GFileAttributeValue *value;
1469 g_return_if_fail (G_IS_FILE_INFO (info));
1472 attr = lookup_attribute (G_FILE_ATTRIBUTE_STANDARD_IS_HIDDEN);
1474 value = g_file_info_create_value (info, attr);
1476 _g_file_attribute_value_set_boolean (value, is_hidden);
1480 * g_file_info_set_is_symlink:
1481 * @info: a #GFileInfo.
1482 * @is_symlink: a #gboolean.
1484 * Sets the "is_symlink" attribute in a #GFileInfo according to @is_symlink.
1485 * See %G_FILE_ATTRIBUTE_STANDARD_IS_SYMLINK.
1488 g_file_info_set_is_symlink (GFileInfo *info,
1489 gboolean is_symlink)
1491 static guint32 attr = 0;
1492 GFileAttributeValue *value;
1494 g_return_if_fail (G_IS_FILE_INFO (info));
1497 attr = lookup_attribute (G_FILE_ATTRIBUTE_STANDARD_IS_SYMLINK);
1499 value = g_file_info_create_value (info, attr);
1501 _g_file_attribute_value_set_boolean (value, is_symlink);
1505 * g_file_info_set_name:
1506 * @info: a #GFileInfo.
1507 * @name: a string containing a name.
1509 * Sets the name attribute for the current #GFileInfo.
1510 * See %G_FILE_ATTRIBUTE_STANDARD_NAME.
1513 g_file_info_set_name (GFileInfo *info,
1516 static guint32 attr = 0;
1517 GFileAttributeValue *value;
1519 g_return_if_fail (G_IS_FILE_INFO (info));
1520 g_return_if_fail (name != NULL);
1523 attr = lookup_attribute (G_FILE_ATTRIBUTE_STANDARD_NAME);
1525 value = g_file_info_create_value (info, attr);
1527 _g_file_attribute_value_set_byte_string (value, name);
1531 * g_file_info_set_display_name:
1532 * @info: a #GFileInfo.
1533 * @display_name: a string containing a display name.
1535 * Sets the display name for the current #GFileInfo.
1536 * See %G_FILE_ATTRIBUTE_STANDARD_DISPLAY_NAME.
1539 g_file_info_set_display_name (GFileInfo *info,
1540 const char *display_name)
1542 static guint32 attr = 0;
1543 GFileAttributeValue *value;
1545 g_return_if_fail (G_IS_FILE_INFO (info));
1546 g_return_if_fail (display_name != NULL);
1549 attr = lookup_attribute (G_FILE_ATTRIBUTE_STANDARD_DISPLAY_NAME);
1551 value = g_file_info_create_value (info, attr);
1553 _g_file_attribute_value_set_string (value, display_name);
1557 * g_file_info_set_edit_name:
1558 * @info: a #GFileInfo.
1559 * @edit_name: a string containing an edit name.
1561 * Sets the edit name for the current file.
1562 * See %G_FILE_ATTRIBUTE_STANDARD_EDIT_NAME.
1565 g_file_info_set_edit_name (GFileInfo *info,
1566 const char *edit_name)
1568 static guint32 attr = 0;
1569 GFileAttributeValue *value;
1571 g_return_if_fail (G_IS_FILE_INFO (info));
1572 g_return_if_fail (edit_name != NULL);
1575 attr = lookup_attribute (G_FILE_ATTRIBUTE_STANDARD_EDIT_NAME);
1577 value = g_file_info_create_value (info, attr);
1579 _g_file_attribute_value_set_string (value, edit_name);
1583 * g_file_info_set_icon:
1584 * @info: a #GFileInfo.
1587 * Sets the icon for a given #GFileInfo.
1588 * See %G_FILE_ATTRIBUTE_STANDARD_ICON.
1591 g_file_info_set_icon (GFileInfo *info,
1594 static guint32 attr = 0;
1595 GFileAttributeValue *value;
1597 g_return_if_fail (G_IS_FILE_INFO (info));
1598 g_return_if_fail (G_IS_ICON (icon));
1601 attr = lookup_attribute (G_FILE_ATTRIBUTE_STANDARD_ICON);
1603 value = g_file_info_create_value (info, attr);
1605 _g_file_attribute_value_set_object (value, G_OBJECT (icon));
1609 * g_file_info_set_content_type:
1610 * @info: a #GFileInfo.
1611 * @content_type: a content type. See #GContentType.
1613 * Sets the content type attribute for a given #GFileInfo.
1614 * See %G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE.
1617 g_file_info_set_content_type (GFileInfo *info,
1618 const char *content_type)
1620 static guint32 attr = 0;
1621 GFileAttributeValue *value;
1623 g_return_if_fail (G_IS_FILE_INFO (info));
1624 g_return_if_fail (content_type != NULL);
1627 attr = lookup_attribute (G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE);
1629 value = g_file_info_create_value (info, attr);
1631 _g_file_attribute_value_set_string (value, content_type);
1635 * g_file_info_set_size:
1636 * @info: a #GFileInfo.
1637 * @size: a #goffset containing the file's size.
1639 * Sets the %G_FILE_ATTRIBUTE_STANDARD_SIZE attribute in the file info
1640 * to the given size.
1643 g_file_info_set_size (GFileInfo *info,
1646 static guint32 attr = 0;
1647 GFileAttributeValue *value;
1649 g_return_if_fail (G_IS_FILE_INFO (info));
1652 attr = lookup_attribute (G_FILE_ATTRIBUTE_STANDARD_SIZE);
1654 value = g_file_info_create_value (info, attr);
1656 _g_file_attribute_value_set_uint64 (value, size);
1660 * g_file_info_set_modification_time
1661 * @info: a #GFileInfo.
1662 * @mtime: a #GTimeVal.
1664 * Sets the %G_FILE_ATTRIBUTE_TIME_MODIFIED attribute in the file
1665 * info to the given time value.
1668 g_file_info_set_modification_time (GFileInfo *info,
1671 static guint32 attr_mtime = 0, attr_mtime_usec;
1672 GFileAttributeValue *value;
1674 g_return_if_fail (G_IS_FILE_INFO (info));
1675 g_return_if_fail (mtime != NULL);
1677 if (attr_mtime == 0)
1679 attr_mtime = lookup_attribute (G_FILE_ATTRIBUTE_TIME_MODIFIED);
1680 attr_mtime_usec = lookup_attribute (G_FILE_ATTRIBUTE_TIME_MODIFIED_USEC);
1683 value = g_file_info_create_value (info, attr_mtime);
1685 _g_file_attribute_value_set_uint64 (value, mtime->tv_sec);
1686 value = g_file_info_create_value (info, attr_mtime_usec);
1688 _g_file_attribute_value_set_uint32 (value, mtime->tv_usec);
1692 * g_file_info_set_symlink_target:
1693 * @info: a #GFileInfo.
1694 * @symlink_target: a static string containing a path to a symlink target.
1696 * Sets the %G_FILE_ATTRIBUTE_STANDARD_SYMLINK_TARGET attribute in the file info
1697 * to the given symlink target.
1700 g_file_info_set_symlink_target (GFileInfo *info,
1701 const char *symlink_target)
1703 static guint32 attr = 0;
1704 GFileAttributeValue *value;
1706 g_return_if_fail (G_IS_FILE_INFO (info));
1707 g_return_if_fail (symlink_target != NULL);
1710 attr = lookup_attribute (G_FILE_ATTRIBUTE_STANDARD_SYMLINK_TARGET);
1712 value = g_file_info_create_value (info, attr);
1714 _g_file_attribute_value_set_byte_string (value, symlink_target);
1718 * g_file_info_set_sort_order:
1719 * @info: a #GFileInfo.
1720 * @sort_order: a sort order integer.
1722 * Sets the sort order attribute in the file info structure. See
1723 * %G_FILE_ATTRIBUTE_STANDARD_SORT_ORDER.
1726 g_file_info_set_sort_order (GFileInfo *info,
1729 static guint32 attr = 0;
1730 GFileAttributeValue *value;
1732 g_return_if_fail (G_IS_FILE_INFO (info));
1735 attr = lookup_attribute (G_FILE_ATTRIBUTE_STANDARD_SORT_ORDER);
1737 value = g_file_info_create_value (info, attr);
1739 _g_file_attribute_value_set_int32 (value, sort_order);
1743 #define ON_STACK_MATCHERS 5
1750 struct _GFileAttributeMatcher {
1752 SubMatcher sub_matchers[ON_STACK_MATCHERS];
1753 GArray *more_sub_matchers;
1756 guint32 iterator_ns;
1762 matcher_add (GFileAttributeMatcher *matcher,
1766 SubMatcher *sub_matchers;
1770 for (i = 0; i < ON_STACK_MATCHERS; i++)
1772 /* First empty spot, not found, use this */
1773 if (matcher->sub_matchers[i].id == 0)
1775 matcher->sub_matchers[i].id = id;
1776 matcher->sub_matchers[i].mask = mask;
1781 if (matcher->sub_matchers[i].id == id &&
1782 matcher->sub_matchers[i].mask == mask)
1786 if (matcher->more_sub_matchers == NULL)
1787 matcher->more_sub_matchers = g_array_new (FALSE, FALSE, sizeof (SubMatcher));
1789 sub_matchers = (SubMatcher *)matcher->more_sub_matchers->data;
1790 for (i = 0; i < matcher->more_sub_matchers->len; i++)
1793 if (sub_matchers[i].id == id &&
1794 sub_matchers[i].mask == mask)
1801 g_array_append_val (matcher->more_sub_matchers, s);
1805 * g_file_attribute_matcher_new:
1806 * @attributes: an attribute string to match.
1808 * Creates a new file attribute matcher, which matches attributes
1809 * against a given string. #GFileAttributeMatcher<!-- -->s are reference
1810 * counted structures, and are created with a reference count of 1. If
1811 * the number of references falls to 0, the #GFileAttributeMatcher is
1812 * automatically destroyed.
1814 * The @attribute string should be formatted with specific keys separated
1815 * from namespaces with a double colon. Several "namespace::key" strings may be
1816 * concatenated with a single comma (e.g. "standard::type,standard::is-hidden").
1817 * The wildcard "*" may be used to match all keys and namespaces, or
1818 * "namespace::*" will match all keys in a given namespace.
1820 * Examples of strings to use:
1822 * <title>File Attribute Matcher strings and results</title>
1823 * <tgroup cols='2' align='left'><thead>
1824 * <row><entry> Matcher String </entry><entry> Matches </entry></row></thead>
1826 * <row><entry>"*"</entry><entry>matches all attributes.</entry></row>
1827 * <row><entry>"standard::is-hidden"</entry><entry>matches only the key is-hidden in the standard namespace.</entry></row>
1828 * <row><entry>"standard::type,unix::*"</entry><entry>matches the type key in the standard namespace and
1829 * all keys in the unix namespace.</entry></row>
1833 * Returns: a #GFileAttributeMatcher.
1835 GFileAttributeMatcher *
1836 g_file_attribute_matcher_new (const char *attributes)
1841 GFileAttributeMatcher *matcher;
1843 if (attributes == NULL || *attributes == '\0')
1846 matcher = g_malloc0 (sizeof (GFileAttributeMatcher));
1849 split = g_strsplit (attributes, ",", -1);
1851 for (i = 0; split[i] != NULL; i++)
1853 if (strcmp (split[i], "*") == 0)
1854 matcher->all = TRUE;
1859 colon = strstr (split[i], "::");
1860 if (colon != NULL &&
1865 id = lookup_attribute (split[i]);
1873 id = lookup_namespace (split[i]) << NS_POS;
1874 mask = NS_MASK << NS_POS;
1877 matcher_add (matcher, id, mask);
1887 * g_file_attribute_matcher_ref:
1888 * @matcher: a #GFileAttributeMatcher.
1890 * References a file attribute matcher.
1892 * Returns: a #GFileAttributeMatcher.
1894 GFileAttributeMatcher *
1895 g_file_attribute_matcher_ref (GFileAttributeMatcher *matcher)
1897 g_return_val_if_fail (matcher != NULL, NULL);
1898 g_return_val_if_fail (matcher->ref > 0, NULL);
1900 g_atomic_int_inc (&matcher->ref);
1906 * g_file_attribute_matcher_unref:
1907 * @matcher: a #GFileAttributeMatcher.
1909 * Unreferences @matcher. If the reference count falls below 1,
1910 * the @matcher is automatically freed.
1914 g_file_attribute_matcher_unref (GFileAttributeMatcher *matcher)
1916 g_return_if_fail (matcher != NULL);
1917 g_return_if_fail (matcher->ref > 0);
1919 if (g_atomic_int_dec_and_test (&matcher->ref))
1921 if (matcher->more_sub_matchers)
1922 g_array_free (matcher->more_sub_matchers, TRUE);
1929 * g_file_attribute_matcher_matches_only:
1930 * @matcher: a #GFileAttributeMatcher.
1931 * @attribute: a file attribute key.
1933 * Checks if a attribute matcher only matches a given attribute. Always
1934 * returns %FALSE if "*" was used when creating the matcher.
1936 * Returns: %TRUE if the matcher only matches @attribute. %FALSE otherwise.
1939 g_file_attribute_matcher_matches_only (GFileAttributeMatcher *matcher,
1940 const char *attribute)
1944 g_return_val_if_fail (matcher != NULL, FALSE);
1945 g_return_val_if_fail (attribute != NULL && *attribute != '\0', FALSE);
1950 id = lookup_attribute (attribute);
1952 if (matcher->sub_matchers[0].id != 0 &&
1953 matcher->sub_matchers[1].id == 0 &&
1954 matcher->sub_matchers[0].mask == 0xffffffff &&
1955 matcher->sub_matchers[0].id == id)
1962 matcher_matches_id (GFileAttributeMatcher *matcher,
1965 SubMatcher *sub_matchers;
1968 for (i = 0; i < ON_STACK_MATCHERS; i++)
1970 if (matcher->sub_matchers[i].id == 0)
1973 if (matcher->sub_matchers[i].id == (id & matcher->sub_matchers[i].mask))
1977 if (matcher->more_sub_matchers)
1979 sub_matchers = (SubMatcher *)matcher->more_sub_matchers->data;
1980 for (i = 0; i < matcher->more_sub_matchers->len; i++)
1982 if (sub_matchers[i].id == (id & sub_matchers[i].mask))
1991 g_file_attribute_matcher_matches_id (GFileAttributeMatcher *matcher,
1994 g_return_val_if_fail (matcher != NULL, FALSE);
1999 return matcher_matches_id (matcher, id);
2003 * g_file_attribute_matcher_matches:
2004 * @matcher: a #GFileAttributeMatcher.
2005 * @attribute: a file attribute key.
2007 * Checks if an attribute will be matched by an attribute matcher. If
2008 * the matcher was created with the "*" matching string, this function
2009 * will always return %TRUE.
2011 * Returns: %TRUE if @attribute matches @matcher. %FALSE otherwise.
2014 g_file_attribute_matcher_matches (GFileAttributeMatcher *matcher,
2015 const char *attribute)
2017 g_return_val_if_fail (matcher != NULL, FALSE);
2018 g_return_val_if_fail (attribute != NULL && *attribute != '\0', FALSE);
2023 return matcher_matches_id (matcher, lookup_attribute (attribute));
2026 /* return TRUE -> all */
2028 * g_file_attribute_matcher_enumerate_namespace:
2029 * @matcher: a #GFileAttributeMatcher.
2030 * @ns: a string containing a file attribute namespace.
2032 * Checks if the matcher will match all of the keys in a given namespace.
2033 * This will always return %TRUE if a wildcard character is in use (e.g. if
2034 * matcher was created with "standard::*" and @ns is "standard", or if matcher was created
2035 * using "*" and namespace is anything.)
2037 * TODO: this is awkwardly worded.
2039 * Returns: %TRUE if the matcher matches all of the entries
2040 * in the given @ns, %FALSE otherwise.
2043 g_file_attribute_matcher_enumerate_namespace (GFileAttributeMatcher *matcher,
2046 SubMatcher *sub_matchers;
2050 g_return_val_if_fail (matcher != NULL, FALSE);
2051 g_return_val_if_fail (ns != NULL && *ns != '\0', FALSE);
2056 ns_id = lookup_namespace (ns) << NS_POS;
2058 for (i = 0; i < ON_STACK_MATCHERS; i++)
2060 if (matcher->sub_matchers[i].id == ns_id)
2064 if (matcher->more_sub_matchers)
2066 sub_matchers = (SubMatcher *)matcher->more_sub_matchers->data;
2067 for (i = 0; i < matcher->more_sub_matchers->len; i++)
2069 if (sub_matchers[i].id == ns_id)
2074 matcher->iterator_ns = ns_id;
2075 matcher->iterator_pos = 0;
2081 * g_file_attribute_matcher_enumerate_next:
2082 * @matcher: a #GFileAttributeMatcher.
2084 * Gets the next matched attribute from a #GFileAttributeMatcher.
2086 * Returns: a string containing the next attribute or %NULL if
2087 * no more attribute exist.
2090 g_file_attribute_matcher_enumerate_next (GFileAttributeMatcher *matcher)
2093 SubMatcher *sub_matcher;
2095 g_return_val_if_fail (matcher != NULL, NULL);
2099 i = matcher->iterator_pos++;
2101 if (i < ON_STACK_MATCHERS)
2103 if (matcher->sub_matchers[i].id == 0)
2106 sub_matcher = &matcher->sub_matchers[i];
2110 if (matcher->more_sub_matchers == NULL)
2113 i -= ON_STACK_MATCHERS;
2114 if (i < matcher->more_sub_matchers->len)
2115 sub_matcher = &g_array_index (matcher->more_sub_matchers, SubMatcher, i);
2120 if (sub_matcher->mask == 0xffffffff &&
2121 (sub_matcher->id & (NS_MASK << NS_POS)) == matcher->iterator_ns)
2122 return get_attribute_for_id (sub_matcher->id);
2126 #define __G_FILE_INFO_C__
2127 #include "gioaliasdef.c"