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
28 * Functionality for manipulating basic metadata for files. #GFileInfo
29 * implements methods for getting information that all files should
30 * contain, and allows for manipulation of extended attributes.
31 * #GFileAttributeMatcher allows for searching through a #GFileInfo for
42 #include "gfileinfo.h"
47 /* We use this nasty thing, because NULL is a valid attribute matcher (matches nothing) */
48 #define NO_ATTRIBUTE_MASK ((GFileAttributeMatcher *)1)
52 GFileAttributeValue value;
57 GObject parent_instance;
60 GFileAttributeMatcher *mask;
63 struct _GFileInfoClass
65 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 = strchr (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:
563 * @info: a #GFileInfo.
564 * @attribute: a file attribute key.
566 * Gets an attribute value from a file info structure.
568 * Returns: a #GFileAttributeValue for the given @attribute, or
571 GFileAttributeValue *
572 g_file_info_get_attribute (GFileInfo *info,
573 const char *attribute)
576 g_return_val_if_fail (G_IS_FILE_INFO (info), NULL);
577 g_return_val_if_fail (attribute != NULL && *attribute != '\0', NULL);
579 return g_file_info_find_value_by_name (info, attribute);
583 * g_file_info_get_attribute_object:
584 * @info: a #GFileInfo.
585 * @attribute: a file attribute key.
587 * Gets the value of a #GObject attribute. If the attribute does
588 * not contain a #GObject, %NULL will be returned.
590 * Returns: a #GObject associated with the given @attribute, or
594 g_file_info_get_attribute_object (GFileInfo *info,
595 const char *attribute)
597 GFileAttributeValue *value;
599 g_return_val_if_fail (G_IS_FILE_INFO (info), NULL);
600 g_return_val_if_fail (attribute != NULL && *attribute != '\0', NULL);
602 value = g_file_info_find_value_by_name (info, attribute);
603 return g_file_attribute_value_get_object (value);
607 * g_file_info_get_attribute_string:
608 * @info: a #GFileInfo.
609 * @attribute: a file attribute key.
611 * Gets the value of a string attribute. If the attribute does
612 * not contain a string, %NULL will be returned.
614 * Returns: the contents of the @attribute value as a string, or
618 g_file_info_get_attribute_string (GFileInfo *info,
619 const char *attribute)
621 GFileAttributeValue *value;
623 g_return_val_if_fail (G_IS_FILE_INFO (info), NULL);
624 g_return_val_if_fail (attribute != NULL && *attribute != '\0', NULL);
626 value = g_file_info_find_value_by_name (info, attribute);
627 return g_file_attribute_value_get_string (value);
631 * g_file_info_get_attribute_byte_string:
632 * @info: a #GFileInfo.
633 * @attribute: a file attribute key.
635 * Gets the value of a byte string attribute. If the attribute does
636 * not contain a byte string, %NULL will be returned.
638 * Returns: the contents of the @attribute value as a byte string, or
642 g_file_info_get_attribute_byte_string (GFileInfo *info,
643 const char *attribute)
645 GFileAttributeValue *value;
647 g_return_val_if_fail (G_IS_FILE_INFO (info), NULL);
648 g_return_val_if_fail (attribute != NULL && *attribute != '\0', NULL);
650 value = g_file_info_find_value_by_name (info, attribute);
651 return g_file_attribute_value_get_byte_string (value);
655 * g_file_info_get_attribute_boolean:
656 * @info: a #GFileInfo.
657 * @attribute: a file attribute key.
659 * Gets the value of a boolean attribute. If the attribute does not
660 * contain a boolean value, %FALSE will be returned.
662 * Returns: the boolean value contained within the attribute.
665 g_file_info_get_attribute_boolean (GFileInfo *info,
666 const char *attribute)
668 GFileAttributeValue *value;
670 g_return_val_if_fail (G_IS_FILE_INFO (info), FALSE);
671 g_return_val_if_fail (attribute != NULL && *attribute != '\0', FALSE);
673 value = g_file_info_find_value_by_name (info, attribute);
674 return g_file_attribute_value_get_boolean (value);
678 * g_file_info_get_attribute_uint32:
679 * @info: a #GFileInfo.
680 * @attribute: a file attribute key.
682 * Gets an unsigned 32-bit integer contained within the attribute. If the
683 * attribute does not contain an unsigned 32-bit integer, or is invalid,
684 * 0 will be returned.
686 * Returns: an unsigned 32-bit integer from the attribute.
689 g_file_info_get_attribute_uint32 (GFileInfo *info,
690 const char *attribute)
692 GFileAttributeValue *value;
694 g_return_val_if_fail (G_IS_FILE_INFO (info), 0);
695 g_return_val_if_fail (attribute != NULL && *attribute != '\0', 0);
697 value = g_file_info_find_value_by_name (info, attribute);
698 return g_file_attribute_value_get_uint32 (value);
702 * g_file_info_get_attribute_int32:
703 * @info: a #GFileInfo.
704 * @attribute: a file attribute key.
706 * Gets a signed 32-bit integer contained within the attribute. If the
707 * attribute does not contain a signed 32-bit integer, or is invalid,
708 * 0 will be returned.
710 * Returns: a signed 32-bit integer from the attribute.
713 g_file_info_get_attribute_int32 (GFileInfo *info,
714 const char *attribute)
716 GFileAttributeValue *value;
718 g_return_val_if_fail (G_IS_FILE_INFO (info), 0);
719 g_return_val_if_fail (attribute != NULL && *attribute != '\0', 0);
721 value = g_file_info_find_value_by_name (info, attribute);
722 return g_file_attribute_value_get_int32 (value);
726 * g_file_info_get_attribute_uint64:
727 * @info: a #GFileInfo.
728 * @attribute: a file attribute key.
730 * Gets a unsigned 64-bit integer contained within the attribute. If the
731 * attribute does not contain an unsigned 64-bit integer, or is invalid,
732 * 0 will be returned.
734 * Returns: a unsigned 64-bit integer from the attribute.
737 g_file_info_get_attribute_uint64 (GFileInfo *info,
738 const char *attribute)
740 GFileAttributeValue *value;
742 g_return_val_if_fail (G_IS_FILE_INFO (info), 0);
743 g_return_val_if_fail (attribute != NULL && *attribute != '\0', 0);
745 value = g_file_info_find_value_by_name (info, attribute);
746 return g_file_attribute_value_get_uint64 (value);
750 * g_file_info_get_attribute_int64:
751 * @info: a #GFileInfo.
752 * @attribute: a file attribute key.
754 * Gets a signed 64-bit integer contained within the attribute. If the
755 * attribute does not contain an signed 64-bit integer, or is invalid,
756 * 0 will be returned.
758 * Returns: a signed 64-bit integer from the attribute.
761 g_file_info_get_attribute_int64 (GFileInfo *info,
762 const char *attribute)
764 GFileAttributeValue *value;
766 g_return_val_if_fail (G_IS_FILE_INFO (info), 0);
767 g_return_val_if_fail (attribute != NULL && *attribute != '\0', 0);
769 value = g_file_info_find_value_by_name (info, attribute);
770 return g_file_attribute_value_get_int64 (value);
773 static GFileAttributeValue *
774 g_file_info_create_value (GFileInfo *info,
777 GFileAttribute *attrs;
781 if (info->mask != NO_ATTRIBUTE_MASK &&
782 !g_file_attribute_matcher_matches_id (info->mask, attr_id))
785 i = g_file_info_find_place (info, attr_id);
787 attrs = (GFileAttribute *)info->attributes->data;
788 if (i < info->attributes->len &&
789 attrs[i].attribute == attr_id)
790 return &attrs[i].value;
793 attr.attribute = attr_id;
794 attr.value.type = G_FILE_ATTRIBUTE_TYPE_INVALID;
795 g_array_insert_val (info->attributes, i, attr);
797 attrs = (GFileAttribute *)info->attributes->data;
798 return &attrs[i].value;
802 static GFileAttributeValue *
803 g_file_info_create_value_by_name (GFileInfo *info,
804 const char *attribute)
808 attr_id = lookup_attribute (attribute);
810 return g_file_info_create_value (info, attr_id);
814 * g_file_info_set_attribute:
815 * @info: a #GFileInfo.
816 * @attribute: a file attribute key.
817 * @attr_value: a #GFileAttributeValue.
819 * Sets the @attribute to contain the given @attr_value,
823 g_file_info_set_attribute (GFileInfo *info,
824 const char *attribute,
825 const GFileAttributeValue *attr_value)
827 GFileAttributeValue *value;
829 g_return_if_fail (G_IS_FILE_INFO (info));
830 g_return_if_fail (attribute != NULL && *attribute != '\0');
831 g_return_if_fail (attr_value != NULL);
833 value = g_file_info_create_value_by_name (info, attribute);
835 g_file_attribute_value_set (value, attr_value);
839 * g_file_info_set_attribute_object:
840 * @info: a #GFileInfo.
841 * @attribute: a file attribute key.
842 * @attr_value: a #GObject.
844 * Sets the @attribute to contain the given @attr_value,
848 g_file_info_set_attribute_object (GFileInfo *info,
849 const char *attribute,
852 GFileAttributeValue *value;
854 g_return_if_fail (G_IS_FILE_INFO (info));
855 g_return_if_fail (attribute != NULL && *attribute != '\0');
856 g_return_if_fail (G_IS_OBJECT (attr_value));
858 value = g_file_info_create_value_by_name (info, attribute);
860 g_file_attribute_value_set_object (value, attr_value);
864 * g_file_info_set_attribute_string:
865 * @info: a #GFileInfo.
866 * @attribute: a file attribute key.
867 * @attr_value: a string.
869 * Sets the @attribute to contain the given @attr_value,
873 g_file_info_set_attribute_string (GFileInfo *info,
874 const char *attribute,
875 const char *attr_value)
877 GFileAttributeValue *value;
879 g_return_if_fail (G_IS_FILE_INFO (info));
880 g_return_if_fail (attribute != NULL && *attribute != '\0');
881 g_return_if_fail (attr_value != NULL);
883 value = g_file_info_create_value_by_name (info, attribute);
885 g_file_attribute_value_set_string (value, attr_value);
889 * g_file_info_set_attribute_byte_string:
890 * @info: a #GFileInfo.
891 * @attribute: a file attribute key.
892 * @attr_value: a byte string.
894 * Sets the @attribute to contain the given @attr_value,
898 g_file_info_set_attribute_byte_string (GFileInfo *info,
899 const char *attribute,
900 const char *attr_value)
902 GFileAttributeValue *value;
904 g_return_if_fail (G_IS_FILE_INFO (info));
905 g_return_if_fail (attribute != NULL && *attribute != '\0');
906 g_return_if_fail (attr_value != NULL);
908 value = g_file_info_create_value_by_name (info, attribute);
910 g_file_attribute_value_set_byte_string (value, attr_value);
914 * g_file_info_set_attribute_boolean:
915 * @info: a #GFileInfo.
916 * @attribute: a file attribute key.
917 * @attr_value: a boolean value.
919 * Sets the @attribute to contain the given @attr_value,
923 g_file_info_set_attribute_boolean (GFileInfo *info,
924 const char *attribute,
927 GFileAttributeValue *value;
929 g_return_if_fail (G_IS_FILE_INFO (info));
930 g_return_if_fail (attribute != NULL && *attribute != '\0');
932 value = g_file_info_create_value_by_name (info, attribute);
934 g_file_attribute_value_set_boolean (value, attr_value);
938 * g_file_info_set_attribute_uint32:
939 * @info: a #GFileInfo.
940 * @attribute: a file attribute key.
941 * @attr_value: an unsigned 32-bit integer.
943 * Sets the @attribute to contain the given @attr_value,
947 g_file_info_set_attribute_uint32 (GFileInfo *info,
948 const char *attribute,
951 GFileAttributeValue *value;
953 g_return_if_fail (G_IS_FILE_INFO (info));
954 g_return_if_fail (attribute != NULL && *attribute != '\0');
956 value = g_file_info_create_value_by_name (info, attribute);
958 g_file_attribute_value_set_uint32 (value, attr_value);
963 * g_file_info_set_attribute_int32:
964 * @info: a #GFileInfo.
965 * @attribute: a file attribute key.
966 * @attr_value: a signed 32-bit integer
968 * Sets the @attribute to contain the given @attr_value,
972 g_file_info_set_attribute_int32 (GFileInfo *info,
973 const char *attribute,
976 GFileAttributeValue *value;
978 g_return_if_fail (G_IS_FILE_INFO (info));
979 g_return_if_fail (attribute != NULL && *attribute != '\0');
981 value = g_file_info_create_value_by_name (info, attribute);
983 g_file_attribute_value_set_int32 (value, attr_value);
987 * g_file_info_set_attribute_uint64:
988 * @info: a #GFileInfo.
989 * @attribute: a file attribute key.
990 * @attr_value: an unsigned 64-bit integer.
992 * Sets the @attribute to contain the given @attr_value,
996 g_file_info_set_attribute_uint64 (GFileInfo *info,
997 const char *attribute,
1000 GFileAttributeValue *value;
1002 g_return_if_fail (G_IS_FILE_INFO (info));
1003 g_return_if_fail (attribute != NULL && *attribute != '\0');
1005 value = g_file_info_create_value_by_name (info, attribute);
1007 g_file_attribute_value_set_uint64 (value, attr_value);
1011 * g_file_info_set_attribute_int64:
1012 * @info: a #GFileInfo.
1013 * @attribute: attribute name to set.
1014 * @attr_value: int64 value to set attribute to.
1016 * Sets the @attribute to contain the given @attr_value,
1021 g_file_info_set_attribute_int64 (GFileInfo *info,
1022 const char *attribute,
1025 GFileAttributeValue *value;
1027 g_return_if_fail (G_IS_FILE_INFO (info));
1028 g_return_if_fail (attribute != NULL && *attribute != '\0');
1030 value = g_file_info_create_value_by_name (info, attribute);
1032 g_file_attribute_value_set_int64 (value, attr_value);
1035 /* Helper getters */
1037 * g_file_info_get_file_type:
1038 * @info: a #GFileInfo.
1040 * Gets a file's type (whether it is a regular file, symlink, etc).
1041 * This is different from the file's content type, see g_file_info_get_content_type().
1043 * Returns: a #GFileType for the given file.
1046 g_file_info_get_file_type (GFileInfo *info)
1048 static guint32 attr = 0;
1049 GFileAttributeValue *value;
1051 g_return_val_if_fail (G_IS_FILE_INFO (info), G_FILE_TYPE_UNKNOWN);
1054 attr = lookup_attribute (G_FILE_ATTRIBUTE_STD_TYPE);
1056 value = g_file_info_find_value (info, attr);
1057 return (GFileType)g_file_attribute_value_get_uint32 (value);
1061 * g_file_info_get_is_hidden:
1062 * @info: a #GFileInfo.
1064 * Checks if a file is hidden.
1066 * Returns: %TRUE if the file is a hidden file, %FALSE otherwise.
1069 g_file_info_get_is_hidden (GFileInfo *info)
1071 static guint32 attr = 0;
1072 GFileAttributeValue *value;
1074 g_return_val_if_fail (G_IS_FILE_INFO (info), FALSE);
1077 attr = lookup_attribute (G_FILE_ATTRIBUTE_STD_IS_HIDDEN);
1079 value = g_file_info_find_value (info, attr);
1080 return (GFileType)g_file_attribute_value_get_boolean (value);
1084 * g_file_info_get_is_backup:
1085 * @info: a #GFileInfo.
1087 * Checks if a file is a backup file.
1089 * Returns: %TRUE if file is a backup file, %FALSE otherwise.
1092 g_file_info_get_is_backup (GFileInfo *info)
1094 static guint32 attr = 0;
1095 GFileAttributeValue *value;
1097 g_return_val_if_fail (G_IS_FILE_INFO (info), FALSE);
1100 attr = lookup_attribute (G_FILE_ATTRIBUTE_STD_IS_BACKUP);
1102 value = g_file_info_find_value (info, attr);
1103 return (GFileType)g_file_attribute_value_get_boolean (value);
1107 * g_file_info_get_is_symlink:
1108 * @info: a #GFileInfo.
1110 * Checks if a file is a symlink.
1112 * Returns: %TRUE if the given @info is a symlink.
1115 g_file_info_get_is_symlink (GFileInfo *info)
1117 static guint32 attr = 0;
1118 GFileAttributeValue *value;
1120 g_return_val_if_fail (G_IS_FILE_INFO (info), FALSE);
1123 attr = lookup_attribute (G_FILE_ATTRIBUTE_STD_IS_SYMLINK);
1125 value = g_file_info_find_value (info, attr);
1126 return (GFileType)g_file_attribute_value_get_boolean (value);
1130 * g_file_info_get_name:
1131 * @info: a #GFileInfo.
1133 * Gets the name for a file.
1135 * Returns: a string containing the file name.
1138 g_file_info_get_name (GFileInfo *info)
1140 static guint32 attr = 0;
1141 GFileAttributeValue *value;
1143 g_return_val_if_fail (G_IS_FILE_INFO (info), NULL);
1146 attr = lookup_attribute (G_FILE_ATTRIBUTE_STD_NAME);
1148 value = g_file_info_find_value (info, attr);
1149 return g_file_attribute_value_get_byte_string (value);
1153 * g_file_info_get_display_name:
1154 * @info: a #GFileInfo.
1156 * Gets a display name for a file.
1158 * Returns: a string containing the display name.
1161 g_file_info_get_display_name (GFileInfo *info)
1163 static guint32 attr = 0;
1164 GFileAttributeValue *value;
1166 g_return_val_if_fail (G_IS_FILE_INFO (info), NULL);
1169 attr = lookup_attribute (G_FILE_ATTRIBUTE_STD_DISPLAY_NAME);
1171 value = g_file_info_find_value (info, attr);
1172 return g_file_attribute_value_get_string (value);
1176 * g_file_info_get_edit_name:
1177 * @info: a #GFileInfo.
1179 * Gets the edit name for a file.
1181 * Returns: a string containing the edit name.
1184 g_file_info_get_edit_name (GFileInfo *info)
1186 static guint32 attr = 0;
1187 GFileAttributeValue *value;
1189 g_return_val_if_fail (G_IS_FILE_INFO (info), NULL);
1192 attr = lookup_attribute (G_FILE_ATTRIBUTE_STD_EDIT_NAME);
1194 value = g_file_info_find_value (info, attr);
1195 return g_file_attribute_value_get_string (value);
1199 * g_file_info_get_icon:
1200 * @info: a #GFileInfo.
1202 * Gets the icon for a file.
1204 * Returns: #GIcon for the given @info.
1207 g_file_info_get_icon (GFileInfo *info)
1209 static guint32 attr = 0;
1210 GFileAttributeValue *value;
1213 g_return_val_if_fail (G_IS_FILE_INFO (info), NULL);
1216 attr = lookup_attribute (G_FILE_ATTRIBUTE_STD_ICON);
1218 value = g_file_info_find_value (info, attr);
1219 obj = g_file_attribute_value_get_object (value);
1220 if (obj != NULL && G_IS_ICON (obj))
1221 return G_ICON (obj);
1226 * g_file_info_get_content_type:
1227 * @info: a #GFileInfo.
1229 * Gets the file's content type.
1231 * Returns: a string containing the file's content type.s
1234 g_file_info_get_content_type (GFileInfo *info)
1236 static guint32 attr = 0;
1237 GFileAttributeValue *value;
1239 g_return_val_if_fail (G_IS_FILE_INFO (info), NULL);
1242 attr = lookup_attribute (G_FILE_ATTRIBUTE_STD_CONTENT_TYPE);
1244 value = g_file_info_find_value (info, attr);
1245 return g_file_attribute_value_get_string (value);
1249 * g_file_info_get_size:
1250 * @info: a #GFileInfo.
1252 * Gets the file's size.
1254 * Returns: a #goffset containing the file's size.
1257 g_file_info_get_size (GFileInfo *info)
1259 static guint32 attr = 0;
1260 GFileAttributeValue *value;
1262 g_return_val_if_fail (G_IS_FILE_INFO (info), (goffset) 0);
1265 attr = lookup_attribute (G_FILE_ATTRIBUTE_STD_SIZE);
1267 value = g_file_info_find_value (info, attr);
1268 return (goffset) g_file_attribute_value_get_uint64 (value);
1272 * g_file_info_get_modification_time:
1273 * @info: a #GFileInfo.
1274 * @result: a #GTimeVal.
1276 * Gets the modification time of the current @info and sets it
1280 g_file_info_get_modification_time (GFileInfo *info,
1283 static guint32 attr_mtime = 0, attr_mtime_usec;
1284 GFileAttributeValue *value;
1286 g_return_if_fail (G_IS_FILE_INFO (info));
1287 g_return_if_fail (result != NULL);
1289 if (attr_mtime == 0)
1291 attr_mtime = lookup_attribute (G_FILE_ATTRIBUTE_TIME_MODIFIED);
1292 attr_mtime_usec = lookup_attribute (G_FILE_ATTRIBUTE_TIME_MODIFIED_USEC);
1295 value = g_file_info_find_value (info, attr_mtime);
1296 result->tv_sec = g_file_attribute_value_get_uint64 (value);
1297 value = g_file_info_find_value (info, attr_mtime_usec);
1298 result->tv_usec = g_file_attribute_value_get_uint32 (value);
1302 * g_file_info_get_symlink_target:
1303 * @info: a #GFileInfo.
1305 * Gets the symlink target for a given #GFileInfo.
1307 * Returns: a string containing the symlink target.
1310 g_file_info_get_symlink_target (GFileInfo *info)
1312 static guint32 attr = 0;
1313 GFileAttributeValue *value;
1315 g_return_val_if_fail (G_IS_FILE_INFO (info), NULL);
1318 attr = lookup_attribute (G_FILE_ATTRIBUTE_STD_SYMLINK_TARGET);
1320 value = g_file_info_find_value (info, attr);
1321 return g_file_attribute_value_get_byte_string (value);
1325 * g_file_info_get_etag:
1326 * @info: a #GFileInfo.
1328 * Gets the <link linkend="gfile-etag">entity tag</link> for a given
1329 * #GFileInfo. See %G_FILE_ATTRIBUTE_ETAG_VALUE.
1331 * Returns: a string containing the value of the "etag:value" attribute.
1334 g_file_info_get_etag (GFileInfo *info)
1336 static guint32 attr = 0;
1337 GFileAttributeValue *value;
1339 g_return_val_if_fail (G_IS_FILE_INFO (info), NULL);
1342 attr = lookup_attribute (G_FILE_ATTRIBUTE_ETAG_VALUE);
1344 value = g_file_info_find_value (info, attr);
1345 return g_file_attribute_value_get_string (value);
1349 * g_file_info_get_sort_order:
1350 * @info: a #GFileInfo.
1352 * Gets the value of the sort_order attribute from the #GFileInfo.
1353 * See %G_FILE_ATTRIBUTE_STD_SORT_ORDER.
1355 * Returns: a #gint32 containing the value of the "std:sort_order" attribute.
1358 g_file_info_get_sort_order (GFileInfo *info)
1360 static guint32 attr = 0;
1361 GFileAttributeValue *value;
1363 g_return_val_if_fail (G_IS_FILE_INFO (info), 0);
1366 attr = lookup_attribute (G_FILE_ATTRIBUTE_STD_SORT_ORDER);
1368 value = g_file_info_find_value (info, attr);
1369 return g_file_attribute_value_get_int32 (value);
1372 /* Helper setters: */
1374 * g_file_info_set_file_type:
1375 * @info: a #GFileInfo.
1376 * @type: a #GFileType.
1378 * Sets the file type in a #GFileInfo to @type.
1379 * See %G_FILE_ATTRIBUTE_STD_TYPE.
1382 g_file_info_set_file_type (GFileInfo *info,
1385 static guint32 attr = 0;
1386 GFileAttributeValue *value;
1388 g_return_if_fail (G_IS_FILE_INFO (info));
1391 attr = lookup_attribute (G_FILE_ATTRIBUTE_STD_TYPE);
1393 value = g_file_info_create_value (info, attr);
1395 g_file_attribute_value_set_uint32 (value, type);
1399 * g_file_info_set_is_hidden:
1400 * @info: a #GFileInfo.
1401 * @is_hidden: a #gboolean.
1403 * Sets the "is_hidden" attribute in a #GFileInfo according to @is_symlink.
1404 * See %G_FILE_ATTRIBUTE_STD_IS_HIDDEN.
1407 g_file_info_set_is_hidden (GFileInfo *info,
1410 static guint32 attr = 0;
1411 GFileAttributeValue *value;
1413 g_return_if_fail (G_IS_FILE_INFO (info));
1416 attr = lookup_attribute (G_FILE_ATTRIBUTE_STD_IS_HIDDEN);
1418 value = g_file_info_create_value (info, attr);
1420 g_file_attribute_value_set_boolean (value, is_hidden);
1424 * g_file_info_set_is_symlink:
1425 * @info: a #GFileInfo.
1426 * @is_symlink: a #gboolean.
1428 * Sets the "is_symlink" attribute in a #GFileInfo according to @is_symlink.
1429 * See %G_FILE_ATTRIBUTE_STD_IS_SYMLINK.
1432 g_file_info_set_is_symlink (GFileInfo *info,
1433 gboolean is_symlink)
1435 static guint32 attr = 0;
1436 GFileAttributeValue *value;
1438 g_return_if_fail (G_IS_FILE_INFO (info));
1441 attr = lookup_attribute (G_FILE_ATTRIBUTE_STD_IS_SYMLINK);
1443 value = g_file_info_create_value (info, attr);
1445 g_file_attribute_value_set_boolean (value, is_symlink);
1449 * g_file_info_set_name:
1450 * @info: a #GFileInfo.
1451 * @name: a string containing a name.
1453 * Sets the name attribute for the current #GFileInfo.
1454 * See %G_FILE_ATTRIBUTE_STD_NAME.
1457 g_file_info_set_name (GFileInfo *info,
1460 static guint32 attr = 0;
1461 GFileAttributeValue *value;
1463 g_return_if_fail (G_IS_FILE_INFO (info));
1464 g_return_if_fail (name != NULL);
1467 attr = lookup_attribute (G_FILE_ATTRIBUTE_STD_NAME);
1469 value = g_file_info_create_value (info, attr);
1471 g_file_attribute_value_set_byte_string (value, name);
1475 * g_file_info_set_display_name:
1476 * @info: a #GFileInfo.
1477 * @display_name: a string containing a display name.
1479 * Sets the display name for the current #GFileInfo.
1480 * See %G_FILE_ATTRIBUTE_STD_DISPLAY_NAME.
1483 g_file_info_set_display_name (GFileInfo *info,
1484 const char *display_name)
1486 static guint32 attr = 0;
1487 GFileAttributeValue *value;
1489 g_return_if_fail (G_IS_FILE_INFO (info));
1490 g_return_if_fail (display_name != NULL);
1493 attr = lookup_attribute (G_FILE_ATTRIBUTE_STD_DISPLAY_NAME);
1495 value = g_file_info_create_value (info, attr);
1497 g_file_attribute_value_set_string (value, display_name);
1501 * g_file_info_set_edit_name:
1502 * @info: a #GFileInfo.
1503 * @edit_name: a string containing an edit name.
1505 * Sets the edit name for the current file.
1506 * See %G_FILE_ATTRIBUTE_STD_EDIT_NAME.
1509 g_file_info_set_edit_name (GFileInfo *info,
1510 const char *edit_name)
1512 static guint32 attr = 0;
1513 GFileAttributeValue *value;
1515 g_return_if_fail (G_IS_FILE_INFO (info));
1516 g_return_if_fail (edit_name != NULL);
1519 attr = lookup_attribute (G_FILE_ATTRIBUTE_STD_EDIT_NAME);
1521 value = g_file_info_create_value (info, attr);
1523 g_file_attribute_value_set_string (value, edit_name);
1527 * g_file_info_set_icon:
1528 * @info: a #GFileInfo.
1531 * Sets the icon for a given #GFileInfo.
1532 * See %G_FILE_ATTRIBUTE_STD_ICON.
1535 g_file_info_set_icon (GFileInfo *info,
1538 static guint32 attr = 0;
1539 GFileAttributeValue *value;
1541 g_return_if_fail (G_IS_FILE_INFO (info));
1542 g_return_if_fail (G_IS_ICON (icon));
1545 attr = lookup_attribute (G_FILE_ATTRIBUTE_STD_ICON);
1547 value = g_file_info_create_value (info, attr);
1549 g_file_attribute_value_set_object (value, G_OBJECT (icon));
1553 * g_file_info_set_content_type:
1554 * @info: a #GFileInfo.
1555 * @content_type: a content type. See #GContentType.
1557 * Sets the content type attribute for a given #GFileInfo.
1558 * See %G_FILE_ATTRIBUTE_STD_CONTENT_TYPE.
1561 g_file_info_set_content_type (GFileInfo *info,
1562 const char *content_type)
1564 static guint32 attr = 0;
1565 GFileAttributeValue *value;
1567 g_return_if_fail (G_IS_FILE_INFO (info));
1568 g_return_if_fail (content_type != NULL);
1571 attr = lookup_attribute (G_FILE_ATTRIBUTE_STD_CONTENT_TYPE);
1573 value = g_file_info_create_value (info, attr);
1575 g_file_attribute_value_set_string (value, content_type);
1579 * g_file_info_set_size:
1580 * @info: a #GFileInfo.
1581 * @size: a #goffset containing the file's size.
1583 * Sets the %G_FILE_ATTRIBUTE_STD_SIZE attribute in the file info
1584 * to the given size.
1587 g_file_info_set_size (GFileInfo *info,
1590 static guint32 attr = 0;
1591 GFileAttributeValue *value;
1593 g_return_if_fail (G_IS_FILE_INFO (info));
1596 attr = lookup_attribute (G_FILE_ATTRIBUTE_STD_SIZE);
1598 value = g_file_info_create_value (info, attr);
1600 g_file_attribute_value_set_uint64 (value, size);
1604 * g_file_info_set_modification_time
1605 * @info: a #GFileInfo.
1606 * @mtime: a #GTimeVal.
1608 * Sets the %G_FILE_ATTRIBUTE_TIME_MODIFIED attribute in the file
1609 * info to the given time value.
1612 g_file_info_set_modification_time (GFileInfo *info,
1615 static guint32 attr_mtime = 0, attr_mtime_usec;
1616 GFileAttributeValue *value;
1618 g_return_if_fail (G_IS_FILE_INFO (info));
1619 g_return_if_fail (mtime != NULL);
1621 if (attr_mtime == 0)
1623 attr_mtime = lookup_attribute (G_FILE_ATTRIBUTE_TIME_MODIFIED);
1624 attr_mtime_usec = lookup_attribute (G_FILE_ATTRIBUTE_TIME_MODIFIED_USEC);
1627 value = g_file_info_create_value (info, attr_mtime);
1629 g_file_attribute_value_set_uint64 (value, mtime->tv_sec);
1630 value = g_file_info_create_value (info, attr_mtime_usec);
1632 g_file_attribute_value_set_uint32 (value, mtime->tv_usec);
1636 * g_file_info_set_symlink_target:
1637 * @info: a #GFileInfo.
1638 * @symlink_target: a static string containing a path to a symlink target.
1640 * Sets the %G_FILE_ATTRIBUTE_STD_SYMLINK_TARGET attribute in the file info
1641 * to the given symlink target.
1644 g_file_info_set_symlink_target (GFileInfo *info,
1645 const char *symlink_target)
1647 static guint32 attr = 0;
1648 GFileAttributeValue *value;
1650 g_return_if_fail (G_IS_FILE_INFO (info));
1651 g_return_if_fail (symlink_target != NULL);
1654 attr = lookup_attribute (G_FILE_ATTRIBUTE_STD_SYMLINK_TARGET);
1656 value = g_file_info_create_value (info, attr);
1658 g_file_attribute_value_set_byte_string (value, symlink_target);
1662 * g_file_info_set_sort_order:
1663 * @info: a #GFileInfo.
1664 * @sort_order: a sort order integer.
1666 * Sets the sort order attribute in the file info structure. See
1667 * %G_FILE_ATTRIBUTE_STD_SORT_ORDER.
1670 g_file_info_set_sort_order (GFileInfo *info,
1673 static guint32 attr = 0;
1674 GFileAttributeValue *value;
1676 g_return_if_fail (G_IS_FILE_INFO (info));
1679 attr = lookup_attribute (G_FILE_ATTRIBUTE_STD_SORT_ORDER);
1681 value = g_file_info_create_value (info, attr);
1683 g_file_attribute_value_set_int32 (value, sort_order);
1687 #define ON_STACK_MATCHERS 5
1694 struct _GFileAttributeMatcher {
1696 SubMatcher sub_matchers[ON_STACK_MATCHERS];
1697 GArray *more_sub_matchers;
1700 guint32 iterator_ns;
1706 matcher_add (GFileAttributeMatcher *matcher,
1710 SubMatcher *sub_matchers;
1714 for (i = 0; i < ON_STACK_MATCHERS; i++)
1716 /* First empty spot, not found, use this */
1717 if (matcher->sub_matchers[i].id == 0)
1719 matcher->sub_matchers[i].id = id;
1720 matcher->sub_matchers[i].mask = mask;
1725 if (matcher->sub_matchers[i].id == id &&
1726 matcher->sub_matchers[i].mask == mask)
1730 if (matcher->more_sub_matchers == NULL)
1731 matcher->more_sub_matchers = g_array_new (FALSE, FALSE, sizeof (SubMatcher));
1733 sub_matchers = (SubMatcher *)matcher->more_sub_matchers->data;
1734 for (i = 0; i < matcher->more_sub_matchers->len; i++)
1737 if (sub_matchers[i].id == id &&
1738 sub_matchers[i].mask == mask)
1745 g_array_append_val (matcher->more_sub_matchers, s);
1749 * g_file_attribute_matcher_new:
1750 * @attributes: an attribute string to match.
1752 * Creates a new file attribute matcher, which matches attributes
1753 * against a given string. #GFileAttributeMatcher<!-- -->s are reference
1754 * counted structures, and are created with a reference count of 1. If
1755 * the number of references falls to 0, the #GFileAttributeMatcher is
1756 * automatically destroyed.
1758 * The @attribute string should be formatted with specific keys separated
1759 * from namespaces with a colon. Several "namespace:key" strings may be
1760 * concatenated with a single comma (e.g. "std:type,std:is_hidden").
1761 * The wildcard "*" may be used to match all keys and namespaces, or
1762 * "namespace:*" will match all keys in a given namespace.
1764 * Examples of strings to use:
1766 * <title>File Attribute Matcher strings and results</title>
1767 * <tgroup cols='2' align='left'><thead>
1768 * <row><entry> Matcher String </entry><entry> Matches </entry></row></thead>
1770 * <row><entry>"*"</entry><entry>matches all attributes.</entry></row>
1771 * <row><entry>"std:is_hidden"</entry><entry>matches only the key is_hidden in the std namespace.</entry></row>
1772 * <row><entry>"std:type,unix:*"</entry><entry>matches the type key in the std namespace and all keys in the unix
1773 * namespace.</entry></row>
1777 * Returns: a #GFileAttributeMatcher.
1779 GFileAttributeMatcher *
1780 g_file_attribute_matcher_new (const char *attributes)
1785 GFileAttributeMatcher *matcher;
1787 if (attributes == NULL || *attributes == '\0')
1790 matcher = g_malloc0 (sizeof (GFileAttributeMatcher));
1793 split = g_strsplit (attributes, ",", -1);
1795 for (i = 0; split[i] != NULL; i++)
1797 if (strcmp (split[i], "*") == 0)
1798 matcher->all = TRUE;
1803 colon = strchr (split[i], ':');
1804 if (colon != NULL &&
1809 id = lookup_attribute (split[i]);
1817 id = lookup_namespace (split[i]) << NS_POS;
1818 mask = NS_MASK << NS_POS;
1821 matcher_add (matcher, id, mask);
1831 * g_file_attribute_matcher_ref:
1832 * @matcher: a #GFileAttributeMatcher.
1834 * References a file attribute matcher.
1836 * Returns: a #GFileAttributeMatcher.
1838 GFileAttributeMatcher *
1839 g_file_attribute_matcher_ref (GFileAttributeMatcher *matcher)
1841 g_return_val_if_fail (matcher != NULL, NULL);
1842 g_return_val_if_fail (matcher->ref > 0, NULL);
1844 g_atomic_int_inc (&matcher->ref);
1850 * g_file_attribute_matcher_unref:
1851 * @matcher: a #GFileAttributeMatcher.
1853 * Unreferences @matcher. If the reference count falls below 1,
1854 * the @matcher is automatically freed.
1858 g_file_attribute_matcher_unref (GFileAttributeMatcher *matcher)
1860 g_return_if_fail (matcher != NULL);
1861 g_return_if_fail (matcher->ref > 0);
1863 if (g_atomic_int_dec_and_test (&matcher->ref))
1865 if (matcher->more_sub_matchers)
1866 g_array_free (matcher->more_sub_matchers, TRUE);
1873 * g_file_attribute_matcher_matches_only:
1874 * @matcher: a #GFileAttributeMatcher.
1875 * @attribute: a file attribute key.
1877 * Checks if a attribute matcher only matches a given attribute. Always
1878 * returns %FALSE if "*" was used when creating the matcher.
1880 * Returns: %TRUE if the matcher only matches @attribute. %FALSE otherwise.
1883 g_file_attribute_matcher_matches_only (GFileAttributeMatcher *matcher,
1884 const char *attribute)
1888 g_return_val_if_fail (matcher != NULL, FALSE);
1889 g_return_val_if_fail (attribute != NULL && *attribute != '\0', FALSE);
1894 id = lookup_attribute (attribute);
1896 if (matcher->sub_matchers[0].id != 0 &&
1897 matcher->sub_matchers[1].id == 0 &&
1898 matcher->sub_matchers[0].mask == 0xffffffff &&
1899 matcher->sub_matchers[0].id == id)
1906 matcher_matches_id (GFileAttributeMatcher *matcher,
1909 SubMatcher *sub_matchers;
1912 for (i = 0; i < ON_STACK_MATCHERS; i++)
1914 if (matcher->sub_matchers[i].id == 0)
1917 if (matcher->sub_matchers[i].id == (id & matcher->sub_matchers[i].mask))
1921 if (matcher->more_sub_matchers)
1923 sub_matchers = (SubMatcher *)matcher->more_sub_matchers->data;
1924 for (i = 0; i < matcher->more_sub_matchers->len; i++)
1926 if (sub_matchers[i].id == (id & sub_matchers[i].mask))
1935 g_file_attribute_matcher_matches_id (GFileAttributeMatcher *matcher,
1938 g_return_val_if_fail (matcher != NULL, FALSE);
1943 return matcher_matches_id (matcher, id);
1947 * g_file_attribute_matcher_matches:
1948 * @matcher: a #GFileAttributeMatcher.
1949 * @attribute: a file attribute key.
1951 * Checks if an attribute will be matched by an attribute matcher. If
1952 * the matcher was created with the "*" matching string, this function
1953 * will always return %TRUE.
1955 * Returns: %TRUE if @attribute matches @matcher. %FALSE otherwise.
1958 g_file_attribute_matcher_matches (GFileAttributeMatcher *matcher,
1959 const char *attribute)
1961 g_return_val_if_fail (matcher != NULL, FALSE);
1962 g_return_val_if_fail (attribute != NULL && *attribute != '\0', FALSE);
1967 return matcher_matches_id (matcher, lookup_attribute (attribute));
1970 /* return TRUE -> all */
1972 * g_file_attribute_matcher_enumerate_namespace:
1973 * @matcher: a #GFileAttributeMatcher.
1974 * @ns: a string containing a file attribute namespace.
1976 * Checks if the matcher will match all of the keys in a given namespace.
1977 * This will always return %TRUE if a wildcard character is in use (e.g. if
1978 * matcher was created with "std:*" and @ns is "std", or if matcher was created
1979 * using "*" and namespace is anything.)
1981 * TODO: this is awkwardly worded.
1983 * Returns: %TRUE if the matcher matches all of the entries
1984 * in the given @ns, %FALSE otherwise.
1987 g_file_attribute_matcher_enumerate_namespace (GFileAttributeMatcher *matcher,
1990 SubMatcher *sub_matchers;
1994 g_return_val_if_fail (matcher != NULL, FALSE);
1995 g_return_val_if_fail (ns != NULL && *ns != '\0', FALSE);
2000 ns_id = lookup_namespace (ns) << NS_POS;
2002 for (i = 0; i < ON_STACK_MATCHERS; i++)
2004 if (matcher->sub_matchers[i].id == ns_id)
2008 if (matcher->more_sub_matchers)
2010 sub_matchers = (SubMatcher *)matcher->more_sub_matchers->data;
2011 for (i = 0; i < matcher->more_sub_matchers->len; i++)
2013 if (sub_matchers[i].id == ns_id)
2018 matcher->iterator_ns = ns_id;
2019 matcher->iterator_pos = 0;
2025 * g_file_attribute_matcher_enumerate_next:
2026 * @matcher: a #GFileAttributeMatcher.
2028 * Gets the next matched attribute from a #GFileAttributeMatcher.
2030 * Returns: a string containing the next attribute or %NULL if
2031 * no more attribute exist.
2034 g_file_attribute_matcher_enumerate_next (GFileAttributeMatcher *matcher)
2037 SubMatcher *sub_matcher;
2039 g_return_val_if_fail (matcher != NULL, NULL);
2043 i = matcher->iterator_pos++;
2045 if (i < ON_STACK_MATCHERS)
2047 if (matcher->sub_matchers[i].id == 0)
2050 sub_matcher = &matcher->sub_matchers[i];
2054 if (matcher->more_sub_matchers == NULL)
2057 i -= ON_STACK_MATCHERS;
2058 if (i < matcher->more_sub_matchers->len)
2059 sub_matcher = &g_array_index (matcher->more_sub_matchers, SubMatcher, i);
2064 if (sub_matcher->mask == 0xffffffff &&
2065 (sub_matcher->id & (NS_MASK << NS_POS)) == matcher->iterator_ns)
2066 return get_attribute_for_id (sub_matcher->id);
2070 #define __G_FILE_INFO_C__
2071 #include "gioaliasdef.c"