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, GFileInfo *dest_info)
262 GFileAttribute *source, *dest;
265 g_return_if_fail (G_IS_FILE_INFO (src_info));
266 g_return_if_fail (G_IS_FILE_INFO (dest_info));
268 dest = (GFileAttribute *)dest_info->attributes->data;
269 for (i = 0; i < dest_info->attributes->len; i++)
270 g_file_attribute_value_clear (&dest[i].value);
272 g_array_set_size (dest_info->attributes,
273 src_info->attributes->len);
275 source = (GFileAttribute *)src_info->attributes->data;
276 dest = (GFileAttribute *)dest_info->attributes->data;
278 for (i = 0; i < src_info->attributes->len; i++)
280 dest[i].attribute = source[i].attribute;
281 dest[i].value.type = G_FILE_ATTRIBUTE_TYPE_INVALID;
282 g_file_attribute_value_set (&dest[i].value, &source[i].value);
285 if (src_info->mask == NO_ATTRIBUTE_MASK)
286 dest_info->mask = NO_ATTRIBUTE_MASK;
288 dest_info->mask = g_file_attribute_matcher_ref (src_info->mask);
293 * @other: a #GFileInfo.
295 * Duplicates a file info structure.
297 * Returns: a duplicate #GFileInfo of @other.
300 g_file_info_dup (GFileInfo *other)
304 g_return_val_if_fail (G_IS_FILE_INFO (other), NULL);
306 new = g_file_info_new ();
307 g_file_info_copy_into (other, new);
312 * g_file_info_set_attribute_mask:
313 * @info: a #GFileInfo.
314 * @mask: a #GFileAttributeMatcher.
316 * Sets @mask on @info to match specific attribute types.
319 g_file_info_set_attribute_mask (GFileInfo *info,
320 GFileAttributeMatcher *mask)
322 GFileAttribute *attr;
325 g_return_if_fail (G_IS_FILE_INFO (info));
326 g_return_if_fail (mask != NULL);
328 if (mask != info->mask)
330 if (info->mask != NO_ATTRIBUTE_MASK)
331 g_file_attribute_matcher_unref (info->mask);
332 info->mask = g_file_attribute_matcher_ref (mask);
334 /* Remove non-matching attributes */
335 for (i = 0; i < info->attributes->len; i++)
337 attr = &g_array_index (info->attributes, GFileAttribute, i);
338 if (!g_file_attribute_matcher_matches_id (mask,
341 g_file_attribute_value_clear (&attr->value);
342 g_array_remove_index (info->attributes, i);
350 * g_file_info_unset_attribute_mask:
353 * Unsets a mask set by g_file_info_set_attribute_mask(), if one
357 g_file_info_unset_attribute_mask (GFileInfo *info)
359 g_return_if_fail (G_IS_FILE_INFO (info));
361 if (info->mask != NO_ATTRIBUTE_MASK)
362 g_file_attribute_matcher_unref (info->mask);
363 info->mask = NO_ATTRIBUTE_MASK;
367 * g_file_info_clear_status:
368 * @info: a #GFileInfo.
370 * Clears the status information from @info.
373 g_file_info_clear_status (GFileInfo *info)
375 GFileAttribute *attrs;
378 g_return_if_fail (G_IS_FILE_INFO (info));
380 attrs = (GFileAttribute *)info->attributes->data;
381 for (i = 0; i < info->attributes->len; i++)
382 attrs[i].value.status = G_FILE_ATTRIBUTE_STATUS_UNSET;
386 g_file_info_find_place (GFileInfo *info,
390 GFileAttribute *attrs;
391 /* Binary search for the place where attribute would be, if its
395 max = info->attributes->len;
397 attrs = (GFileAttribute *)info->attributes->data;
401 med = min + (max - min) / 2;
402 if (attrs[med].attribute == attribute)
407 else if (attrs[med].attribute < attribute)
409 else /* attrs[med].attribute > attribute */
416 static GFileAttributeValue *
417 g_file_info_find_value (GFileInfo *info,
420 GFileAttribute *attrs;
423 i = g_file_info_find_place (info, attr_id);
424 attrs = (GFileAttribute *)info->attributes->data;
425 if (i < info->attributes->len &&
426 attrs[i].attribute == attr_id)
427 return &attrs[i].value;
432 static GFileAttributeValue *
433 g_file_info_find_value_by_name (GFileInfo *info,
434 const char *attribute)
438 attr_id = lookup_attribute (attribute);
439 return g_file_info_find_value (info, attr_id);
443 * g_file_info_has_attribute:
444 * @info: a #GFileInfo.
445 * @attribute: a file attribute key.
447 * Checks if a file info structure has an attribute named @attribute.
449 * Returns: %TRUE if @GFileInfo has an attribute named @attribute,
453 g_file_info_has_attribute (GFileInfo *info,
454 const char *attribute)
456 GFileAttributeValue *value;
458 g_return_val_if_fail (G_IS_FILE_INFO (info), FALSE);
459 g_return_val_if_fail (attribute != NULL && *attribute != '\0', FALSE);
461 value = g_file_info_find_value_by_name (info, attribute);
462 return value != NULL;
466 * g_file_info_list_attributes:
467 * @info: a #GFileInfo.
468 * @name_space: a file attribute key's namespace.
470 * Lists the file info structure's attributes.
472 * Returns: a null-terminated array of strings of all of the
473 * possible attribute types for the given @name_space, or
477 g_file_info_list_attributes (GFileInfo *info,
478 const char *name_space)
481 GFileAttribute *attrs;
483 guint32 ns_id = (name_space) ? lookup_namespace (name_space) : 0;
486 g_return_val_if_fail (G_IS_FILE_INFO (info), NULL);
488 names = g_ptr_array_new ();
489 attrs = (GFileAttribute *)info->attributes->data;
490 for (i = 0; i < info->attributes->len; i++)
492 attribute = attrs[i].attribute;
493 if (ns_id == 0 || GET_NS (attribute) == ns_id)
494 g_ptr_array_add (names, g_strdup (get_attribute_for_id (attribute)));
498 g_ptr_array_add (names, NULL);
500 return (char **)g_ptr_array_free (names, FALSE);
504 * g_file_info_get_attribute_type:
505 * @info: a #GFileInfo.
506 * @attribute: a file attribute key.
508 * Gets the attribute type for an attribute key.
510 * Returns: a #GFileAttributeType for the given @attribute, or
511 * %G_FILE_ATTRIBUTE_TYPE_INVALID if the key is invalid.
514 g_file_info_get_attribute_type (GFileInfo *info,
515 const char *attribute)
517 GFileAttributeValue *value;
519 g_return_val_if_fail (G_IS_FILE_INFO (info), G_FILE_ATTRIBUTE_TYPE_INVALID);
520 g_return_val_if_fail (attribute != NULL && *attribute != '\0', G_FILE_ATTRIBUTE_TYPE_INVALID);
522 value = g_file_info_find_value_by_name (info, attribute);
526 return G_FILE_ATTRIBUTE_TYPE_INVALID;
530 * g_file_info_remove_attribute:
531 * @info: a #GFileInfo.
532 * @attribute: a file attribute key.
534 * Removes all cases of @attribute from @info if it exists.
538 g_file_info_remove_attribute (GFileInfo *info,
539 const char *attribute)
542 GFileAttribute *attrs;
545 g_return_if_fail (G_IS_FILE_INFO (info));
546 g_return_if_fail (attribute != NULL && *attribute != '\0');
548 attr_id = lookup_attribute (attribute);
550 i = g_file_info_find_place (info, attr_id);
551 attrs = (GFileAttribute *)info->attributes->data;
552 if (i < info->attributes->len &&
553 attrs[i].attribute == attr_id)
555 g_file_attribute_value_clear (&attrs[i].value);
556 g_array_remove_index (info->attributes, i);
561 * g_file_info_get_attribute:
562 * @info: a #GFileInfo.
563 * @attribute: a file attribute key.
565 * Gets an attribute value from a file info structure.
567 * Returns: a #GFileAttributeValue for the given @attribute, or
570 GFileAttributeValue *
571 g_file_info_get_attribute (GFileInfo *info,
572 const char *attribute)
575 g_return_val_if_fail (G_IS_FILE_INFO (info), NULL);
576 g_return_val_if_fail (attribute != NULL && *attribute != '\0', NULL);
578 return g_file_info_find_value_by_name (info, attribute);
582 * g_file_info_get_attribute_object:
583 * @info: a #GFileInfo.
584 * @attribute: a file attribute key.
586 * Gets the value of a #GObject attribute. If the attribute does
587 * not contain a #GObject, %NULL will be returned.
589 * Returns: a #GObject associated with the given @attribute, or
593 g_file_info_get_attribute_object (GFileInfo *info,
594 const char *attribute)
596 GFileAttributeValue *value;
598 g_return_val_if_fail (G_IS_FILE_INFO (info), NULL);
599 g_return_val_if_fail (attribute != NULL && *attribute != '\0', NULL);
601 value = g_file_info_find_value_by_name (info, attribute);
602 return g_file_attribute_value_get_object (value);
606 * g_file_info_get_attribute_string:
607 * @info: a #GFileInfo.
608 * @attribute: a file attribute key.
610 * Gets the value of a string attribute. If the attribute does
611 * not contain a string, %NULL will be returned.
613 * Returns: the contents of the @attribute value as a string, or
617 g_file_info_get_attribute_string (GFileInfo *info,
618 const char *attribute)
620 GFileAttributeValue *value;
622 g_return_val_if_fail (G_IS_FILE_INFO (info), NULL);
623 g_return_val_if_fail (attribute != NULL && *attribute != '\0', NULL);
625 value = g_file_info_find_value_by_name (info, attribute);
626 return g_file_attribute_value_get_string (value);
630 * g_file_info_get_attribute_byte_string:
631 * @info: a #GFileInfo.
632 * @attribute: a file attribute key.
634 * Gets the value of a byte string attribute. If the attribute does
635 * not contain a byte string, %NULL will be returned.
637 * Returns: the contents of the @attribute value as a byte string, or
641 g_file_info_get_attribute_byte_string (GFileInfo *info,
642 const char *attribute)
644 GFileAttributeValue *value;
646 g_return_val_if_fail (G_IS_FILE_INFO (info), NULL);
647 g_return_val_if_fail (attribute != NULL && *attribute != '\0', NULL);
649 value = g_file_info_find_value_by_name (info, attribute);
650 return g_file_attribute_value_get_byte_string (value);
654 * g_file_info_get_attribute_boolean:
655 * @info: a #GFileInfo.
656 * @attribute: a file attribute key.
658 * Gets the value of a boolean attribute. If the attribute does not
659 * contain a boolean value, %FALSE will be returned.
661 * Returns: the boolean value contained within the attribute.
664 g_file_info_get_attribute_boolean (GFileInfo *info,
665 const char *attribute)
667 GFileAttributeValue *value;
669 g_return_val_if_fail (G_IS_FILE_INFO (info), FALSE);
670 g_return_val_if_fail (attribute != NULL && *attribute != '\0', FALSE);
672 value = g_file_info_find_value_by_name (info, attribute);
673 return g_file_attribute_value_get_boolean (value);
677 * g_file_info_get_attribute_uint32:
678 * @info: a #GFileInfo.
679 * @attribute: a file attribute key.
681 * Gets an unsigned 32-bit integer contained within the attribute. If the
682 * attribute does not contain an unsigned 32-bit integer, or is invalid,
683 * %0 will be returned.
685 * Returns: an unsigned 32-bit integer from the attribute.
688 g_file_info_get_attribute_uint32 (GFileInfo *info,
689 const char *attribute)
691 GFileAttributeValue *value;
693 g_return_val_if_fail (G_IS_FILE_INFO (info), 0);
694 g_return_val_if_fail (attribute != NULL && *attribute != '\0', 0);
696 value = g_file_info_find_value_by_name (info, attribute);
697 return g_file_attribute_value_get_uint32 (value);
701 * g_file_info_get_attribute_int32:
702 * @info: a #GFileInfo.
703 * @attribute: a file attribute key.
705 * Gets a signed 32-bit integer contained within the attribute. If the
706 * attribute does not contain a signed 32-bit integer, or is invalid,
707 * %0 will be returned.
709 * Returns: a signed 32-bit integer from the attribute.
712 g_file_info_get_attribute_int32 (GFileInfo *info,
713 const char *attribute)
715 GFileAttributeValue *value;
717 g_return_val_if_fail (G_IS_FILE_INFO (info), 0);
718 g_return_val_if_fail (attribute != NULL && *attribute != '\0', 0);
720 value = g_file_info_find_value_by_name (info, attribute);
721 return g_file_attribute_value_get_int32 (value);
725 * g_file_info_get_attribute_uint64:
726 * @info: a #GFileInfo.
727 * @attribute: a file attribute key.
729 * Gets a unsigned 64-bit integer contained within the attribute. If the
730 * attribute does not contain an unsigned 64-bit integer, or is invalid,
731 * %0 will be returned.
733 * Returns: a unsigned 64-bit integer from the attribute.
736 g_file_info_get_attribute_uint64 (GFileInfo *info,
737 const char *attribute)
739 GFileAttributeValue *value;
741 g_return_val_if_fail (G_IS_FILE_INFO (info), 0);
742 g_return_val_if_fail (attribute != NULL && *attribute != '\0', 0);
744 value = g_file_info_find_value_by_name (info, attribute);
745 return g_file_attribute_value_get_uint64 (value);
749 * g_file_info_get_attribute_int64:
750 * @info: a #GFileInfo.
751 * @attribute: a file attribute key.
753 * Gets a signed 64-bit integer contained within the attribute. If the
754 * attribute does not contain an signed 64-bit integer, or is invalid,
755 * %0 will be returned.
757 * Returns: a signed 64-bit integer from the attribute.
760 g_file_info_get_attribute_int64 (GFileInfo *info,
761 const char *attribute)
763 GFileAttributeValue *value;
765 g_return_val_if_fail (G_IS_FILE_INFO (info), 0);
766 g_return_val_if_fail (attribute != NULL && *attribute != '\0', 0);
768 value = g_file_info_find_value_by_name (info, attribute);
769 return g_file_attribute_value_get_int64 (value);
772 static GFileAttributeValue *
773 g_file_info_create_value (GFileInfo *info,
776 GFileAttribute *attrs;
780 if (info->mask != NO_ATTRIBUTE_MASK &&
781 !g_file_attribute_matcher_matches_id (info->mask, attr_id))
784 i = g_file_info_find_place (info, attr_id);
786 attrs = (GFileAttribute *)info->attributes->data;
787 if (i < info->attributes->len &&
788 attrs[i].attribute == attr_id)
789 return &attrs[i].value;
792 attr.attribute = attr_id;
793 attr.value.type = G_FILE_ATTRIBUTE_TYPE_INVALID;
794 g_array_insert_val (info->attributes, i, attr);
796 attrs = (GFileAttribute *)info->attributes->data;
797 return &attrs[i].value;
801 static GFileAttributeValue *
802 g_file_info_create_value_by_name (GFileInfo *info,
803 const char *attribute)
807 attr_id = lookup_attribute (attribute);
809 return g_file_info_create_value (info, attr_id);
813 * g_file_info_set_attribute:
814 * @info: a #GFileInfo.
815 * @attribute: a file attribute key.
816 * @attr_value: a #GFileAttributeValue.
818 * 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,
849 g_file_info_set_attribute_object (GFileInfo *info,
850 const char *attribute,
853 GFileAttributeValue *value;
855 g_return_if_fail (G_IS_FILE_INFO (info));
856 g_return_if_fail (attribute != NULL && *attribute != '\0');
857 g_return_if_fail (G_IS_OBJECT (attr_value));
859 value = g_file_info_create_value_by_name (info, attribute);
861 g_file_attribute_value_set_object (value, attr_value);
865 * g_file_info_set_attribute_string:
866 * @info: a #GFileInfo.
867 * @attribute: a file attribute key.
868 * @attr_value: a string.
870 * Sets the @attribute to contain the given @attr_value,
875 g_file_info_set_attribute_string (GFileInfo *info,
876 const char *attribute,
877 const char *attr_value)
879 GFileAttributeValue *value;
881 g_return_if_fail (G_IS_FILE_INFO (info));
882 g_return_if_fail (attribute != NULL && *attribute != '\0');
883 g_return_if_fail (attr_value != NULL);
885 value = g_file_info_create_value_by_name (info, attribute);
887 g_file_attribute_value_set_string (value, attr_value);
891 * g_file_info_set_attribute_byte_string:
892 * @info: a #GFileInfo.
893 * @attribute: a file attribute key.
894 * @attr_value: a byte string.
896 * Sets the @attribute to contain the given @attr_value,
901 g_file_info_set_attribute_byte_string (GFileInfo *info,
902 const char *attribute,
903 const char *attr_value)
905 GFileAttributeValue *value;
907 g_return_if_fail (G_IS_FILE_INFO (info));
908 g_return_if_fail (attribute != NULL && *attribute != '\0');
909 g_return_if_fail (attr_value != NULL);
911 value = g_file_info_create_value_by_name (info, attribute);
913 g_file_attribute_value_set_byte_string (value, attr_value);
917 * g_file_info_set_attribute_boolean:
918 * @info: a #GFileInfo.
919 * @attribute: a file attribute key.
920 * @attr_value: a boolean value.
922 * Sets the @attribute to contain the given @attr_value,
927 g_file_info_set_attribute_boolean (GFileInfo *info,
928 const char *attribute,
931 GFileAttributeValue *value;
933 g_return_if_fail (G_IS_FILE_INFO (info));
934 g_return_if_fail (attribute != NULL && *attribute != '\0');
936 value = g_file_info_create_value_by_name (info, attribute);
938 g_file_attribute_value_set_boolean (value, attr_value);
942 * g_file_info_set_attribute_uint32:
943 * @info: a #GFileInfo.
944 * @attribute: a file attribute key.
945 * @attr_value: an unsigned 32-bit integer.
947 * Sets the @attribute to contain the given @attr_value,
953 g_file_info_set_attribute_uint32 (GFileInfo *info,
954 const char *attribute,
957 GFileAttributeValue *value;
959 g_return_if_fail (G_IS_FILE_INFO (info));
960 g_return_if_fail (attribute != NULL && *attribute != '\0');
962 value = g_file_info_create_value_by_name (info, attribute);
964 g_file_attribute_value_set_uint32 (value, attr_value);
969 * g_file_info_set_attribute_int32:
970 * @info: a #GFileInfo.
971 * @attribute: a file attribute key.
972 * @attr_value: a signed 32-bit integer
974 * Sets the @attribute to contain the given @attr_value,
979 g_file_info_set_attribute_int32 (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_int32 (value, attr_value);
994 * g_file_info_set_attribute_uint64:
995 * @info: a #GFileInfo.
996 * @attribute: a file attribute key.
997 * @attr_value: an unsigned 64-bit integer.
999 * Sets the @attribute to contain the given @attr_value,
1004 g_file_info_set_attribute_uint64 (GFileInfo *info,
1005 const char *attribute,
1008 GFileAttributeValue *value;
1010 g_return_if_fail (G_IS_FILE_INFO (info));
1011 g_return_if_fail (attribute != NULL && *attribute != '\0');
1013 value = g_file_info_create_value_by_name (info, attribute);
1015 g_file_attribute_value_set_uint64 (value, attr_value);
1019 * g_file_info_set_attribute_int64:
1020 * @info: a #GFileInfo.
1021 * @attribute: attribute name to set.
1022 * @attr_value: int64 value to set attribute to.
1024 * Sets the @attribute to contain the given @attr_value,
1029 g_file_info_set_attribute_int64 (GFileInfo *info,
1030 const char *attribute,
1033 GFileAttributeValue *value;
1035 g_return_if_fail (G_IS_FILE_INFO (info));
1036 g_return_if_fail (attribute != NULL && *attribute != '\0');
1038 value = g_file_info_create_value_by_name (info, attribute);
1040 g_file_attribute_value_set_int64 (value, attr_value);
1043 /* Helper getters */
1045 * g_file_info_get_file_type:
1046 * @info: a #GFileInfo.
1048 * Gets a file's type (whether it is a regular file, symlink, etc).
1049 * This is different from the file's content type, see g_file_info_get_content_type().
1051 * Returns: a #GFileType for the given file.
1054 g_file_info_get_file_type (GFileInfo *info)
1056 static guint32 attr = 0;
1057 GFileAttributeValue *value;
1059 g_return_val_if_fail (G_IS_FILE_INFO (info), G_FILE_TYPE_UNKNOWN);
1062 attr = lookup_attribute (G_FILE_ATTRIBUTE_STD_TYPE);
1064 value = g_file_info_find_value (info, attr);
1065 return (GFileType)g_file_attribute_value_get_uint32 (value);
1069 * g_file_info_get_is_hidden:
1070 * @info: a #GFileInfo.
1072 * Checks if a file is hidden.
1074 * Returns: %TRUE if the file is a hidden file, %FALSE otherwise.
1077 g_file_info_get_is_hidden (GFileInfo *info)
1079 static guint32 attr = 0;
1080 GFileAttributeValue *value;
1082 g_return_val_if_fail (G_IS_FILE_INFO (info), FALSE);
1085 attr = lookup_attribute (G_FILE_ATTRIBUTE_STD_IS_HIDDEN);
1087 value = g_file_info_find_value (info, attr);
1088 return (GFileType)g_file_attribute_value_get_boolean (value);
1092 * g_file_info_get_is_backup:
1093 * @info: a #GFileInfo.
1095 * Checks if a file is a backup file.
1097 * Returns: %TRUE if file is a backup file, %FALSE otherwise.
1100 g_file_info_get_is_backup (GFileInfo *info)
1102 static guint32 attr = 0;
1103 GFileAttributeValue *value;
1105 g_return_val_if_fail (G_IS_FILE_INFO (info), FALSE);
1108 attr = lookup_attribute (G_FILE_ATTRIBUTE_STD_IS_BACKUP);
1110 value = g_file_info_find_value (info, attr);
1111 return (GFileType)g_file_attribute_value_get_boolean (value);
1115 * g_file_info_get_is_symlink:
1116 * @info: a #GFileInfo.
1118 * Checks if a file is a symlink.
1120 * Returns: %TRUE if the given @info is a symlink.
1123 g_file_info_get_is_symlink (GFileInfo *info)
1125 static guint32 attr = 0;
1126 GFileAttributeValue *value;
1128 g_return_val_if_fail (G_IS_FILE_INFO (info), FALSE);
1131 attr = lookup_attribute (G_FILE_ATTRIBUTE_STD_IS_SYMLINK);
1133 value = g_file_info_find_value (info, attr);
1134 return (GFileType)g_file_attribute_value_get_boolean (value);
1138 * g_file_info_get_name:
1139 * @info: a #GFileInfo.
1141 * Gets the name for a file.
1143 * Returns: a string containing the file name.
1146 g_file_info_get_name (GFileInfo *info)
1148 static guint32 attr = 0;
1149 GFileAttributeValue *value;
1151 g_return_val_if_fail (G_IS_FILE_INFO (info), NULL);
1154 attr = lookup_attribute (G_FILE_ATTRIBUTE_STD_NAME);
1156 value = g_file_info_find_value (info, attr);
1157 return g_file_attribute_value_get_byte_string (value);
1161 * g_file_info_get_display_name:
1162 * @info: a #GFileInfo.
1164 * Gets a display name for a file.
1166 * Returns: a string containing the display name.
1169 g_file_info_get_display_name (GFileInfo *info)
1171 static guint32 attr = 0;
1172 GFileAttributeValue *value;
1174 g_return_val_if_fail (G_IS_FILE_INFO (info), NULL);
1177 attr = lookup_attribute (G_FILE_ATTRIBUTE_STD_DISPLAY_NAME);
1179 value = g_file_info_find_value (info, attr);
1180 return g_file_attribute_value_get_string (value);
1184 * g_file_info_get_edit_name:
1185 * @info: a #GFileInfo.
1187 * Gets the edit name for a file.
1189 * Returns: a string containing the edit name.
1192 g_file_info_get_edit_name (GFileInfo *info)
1194 static guint32 attr = 0;
1195 GFileAttributeValue *value;
1197 g_return_val_if_fail (G_IS_FILE_INFO (info), NULL);
1200 attr = lookup_attribute (G_FILE_ATTRIBUTE_STD_EDIT_NAME);
1202 value = g_file_info_find_value (info, attr);
1203 return g_file_attribute_value_get_string (value);
1207 * g_file_info_get_icon:
1208 * @info: a #GFileInfo.
1210 * Gets the icon for a file.
1212 * Returns: #GIcon for the given @info.
1215 g_file_info_get_icon (GFileInfo *info)
1217 static guint32 attr = 0;
1218 GFileAttributeValue *value;
1221 g_return_val_if_fail (G_IS_FILE_INFO (info), NULL);
1224 attr = lookup_attribute (G_FILE_ATTRIBUTE_STD_ICON);
1226 value = g_file_info_find_value (info, attr);
1227 obj = g_file_attribute_value_get_object (value);
1228 if (obj != NULL && G_IS_ICON (obj))
1229 return G_ICON (obj);
1234 * g_file_info_get_content_type:
1235 * @info: a #GFileInfo.
1237 * Gets the file's content type.
1239 * Returns: a string containing the file's content type.s
1242 g_file_info_get_content_type (GFileInfo *info)
1244 static guint32 attr = 0;
1245 GFileAttributeValue *value;
1247 g_return_val_if_fail (G_IS_FILE_INFO (info), NULL);
1250 attr = lookup_attribute (G_FILE_ATTRIBUTE_STD_CONTENT_TYPE);
1252 value = g_file_info_find_value (info, attr);
1253 return g_file_attribute_value_get_string (value);
1257 * g_file_info_get_size:
1258 * @info: a #GFileInfo.
1260 * Gets the file's size.
1262 * Returns: a #goffset containing the file's size.
1265 g_file_info_get_size (GFileInfo *info)
1267 static guint32 attr = 0;
1268 GFileAttributeValue *value;
1270 g_return_val_if_fail (G_IS_FILE_INFO (info), (goffset) 0);
1273 attr = lookup_attribute (G_FILE_ATTRIBUTE_STD_SIZE);
1275 value = g_file_info_find_value (info, attr);
1276 return (goffset) g_file_attribute_value_get_uint64 (value);
1280 * g_file_info_get_modification_time:
1281 * @info: a #GFileInfo.
1282 * @result: a #GTimeVal.
1284 * Gets the modification time of the current @info and sets it
1290 g_file_info_get_modification_time (GFileInfo *info,
1293 static guint32 attr_mtime = 0, attr_mtime_usec;
1294 GFileAttributeValue *value;
1296 g_return_if_fail (G_IS_FILE_INFO (info));
1297 g_return_if_fail (result != NULL);
1299 if (attr_mtime == 0)
1301 attr_mtime = lookup_attribute (G_FILE_ATTRIBUTE_TIME_MODIFIED);
1302 attr_mtime_usec = lookup_attribute (G_FILE_ATTRIBUTE_TIME_MODIFIED_USEC);
1305 value = g_file_info_find_value (info, attr_mtime);
1306 result->tv_sec = g_file_attribute_value_get_uint64 (value);
1307 value = g_file_info_find_value (info, attr_mtime_usec);
1308 result->tv_usec = g_file_attribute_value_get_uint32 (value);
1312 * g_file_info_get_symlink_target:
1313 * @info: a #GFileInfo.
1315 * Gets the symlink target for a given #GFileInfo.
1317 * Returns: a string containing the symlink target.
1320 g_file_info_get_symlink_target (GFileInfo *info)
1322 static guint32 attr = 0;
1323 GFileAttributeValue *value;
1325 g_return_val_if_fail (G_IS_FILE_INFO (info), NULL);
1328 attr = lookup_attribute (G_FILE_ATTRIBUTE_STD_SYMLINK_TARGET);
1330 value = g_file_info_find_value (info, attr);
1331 return g_file_attribute_value_get_byte_string (value);
1335 * g_file_info_get_etag:
1336 * @info: a #GFileInfo.
1338 * Gets the entity tag for a given #GFileInfo.
1339 * See %G_FILE_ATTRIBUTE_ETAG_VALUE.
1341 * Returns: a string containing the value of the "etag:value" attribute.
1344 g_file_info_get_etag (GFileInfo *info)
1346 static guint32 attr = 0;
1347 GFileAttributeValue *value;
1349 g_return_val_if_fail (G_IS_FILE_INFO (info), NULL);
1352 attr = lookup_attribute (G_FILE_ATTRIBUTE_ETAG_VALUE);
1354 value = g_file_info_find_value (info, attr);
1355 return g_file_attribute_value_get_string (value);
1359 * g_file_info_get_sort_order:
1360 * @info: a #GFileInfo.
1362 * Gets the value of the sort_order attribute from the #GFileInfo.
1363 * See %G_FILE_ATTRIBUTE_STD_SORT_ORDER.
1365 * Returns: a #gint32 containing the value of the "std:sort_order" attribute.
1368 g_file_info_get_sort_order (GFileInfo *info)
1370 static guint32 attr = 0;
1371 GFileAttributeValue *value;
1373 g_return_val_if_fail (G_IS_FILE_INFO (info), 0);
1376 attr = lookup_attribute (G_FILE_ATTRIBUTE_STD_SORT_ORDER);
1378 value = g_file_info_find_value (info, attr);
1379 return g_file_attribute_value_get_int32 (value);
1382 /* Helper setters: */
1384 * g_file_info_set_file_type:
1385 * @info: a #GFileInfo.
1386 * @type: a #GFileType.
1388 * Sets the file type in a #GFileInfo to @type.
1389 * See %G_FILE_ATTRIBUTE_STD_TYPE.
1392 g_file_info_set_file_type (GFileInfo *info,
1395 static guint32 attr = 0;
1396 GFileAttributeValue *value;
1398 g_return_if_fail (G_IS_FILE_INFO (info));
1401 attr = lookup_attribute (G_FILE_ATTRIBUTE_STD_TYPE);
1403 value = g_file_info_create_value (info, attr);
1405 g_file_attribute_value_set_uint32 (value, type);
1409 * g_file_info_set_is_hidden:
1410 * @info: a #GFileInfo.
1411 * @is_hidden: a #gboolean.
1413 * Sets the "is_hidden" attribute in a #GFileInfo according to @is_symlink.
1414 * See %G_FILE_ATTRIBUTE_STD_IS_HIDDEN.
1417 g_file_info_set_is_hidden (GFileInfo *info,
1420 static guint32 attr = 0;
1421 GFileAttributeValue *value;
1423 g_return_if_fail (G_IS_FILE_INFO (info));
1426 attr = lookup_attribute (G_FILE_ATTRIBUTE_STD_IS_HIDDEN);
1428 value = g_file_info_create_value (info, attr);
1430 g_file_attribute_value_set_boolean (value, is_hidden);
1434 * g_file_info_set_is_symlink:
1435 * @info: a #GFileInfo.
1436 * @is_symlink: a #gboolean.
1438 * Sets the "is_symlink" attribute in a #GFileInfo according to @is_symlink.
1439 * See %G_FILE_ATTRIBUTE_STD_IS_SYMLINK.
1443 g_file_info_set_is_symlink (GFileInfo *info,
1444 gboolean is_symlink)
1446 static guint32 attr = 0;
1447 GFileAttributeValue *value;
1449 g_return_if_fail (G_IS_FILE_INFO (info));
1452 attr = lookup_attribute (G_FILE_ATTRIBUTE_STD_IS_SYMLINK);
1454 value = g_file_info_create_value (info, attr);
1456 g_file_attribute_value_set_boolean (value, is_symlink);
1460 * g_file_info_set_name:
1461 * @info: a #GFileInfo.
1462 * @name: a string containing a name.
1464 * Sets the name attribute for the current #GFileInfo.
1465 * See %G_FILE_ATTRIBUTE_STD_NAME.
1469 g_file_info_set_name (GFileInfo *info,
1472 static guint32 attr = 0;
1473 GFileAttributeValue *value;
1475 g_return_if_fail (G_IS_FILE_INFO (info));
1476 g_return_if_fail (name != NULL);
1479 attr = lookup_attribute (G_FILE_ATTRIBUTE_STD_NAME);
1481 value = g_file_info_create_value (info, attr);
1483 g_file_attribute_value_set_byte_string (value, name);
1487 * g_file_info_set_display_name:
1488 * @info: a #GFileInfo.
1489 * @display_name: a string containing a display name.
1491 * Sets the display name for the current #GFileInfo.
1492 * See %G_FILE_ATTRIBUTE_STD_DISPLAY_NAME.
1496 g_file_info_set_display_name (GFileInfo *info,
1497 const char *display_name)
1499 static guint32 attr = 0;
1500 GFileAttributeValue *value;
1502 g_return_if_fail (G_IS_FILE_INFO (info));
1503 g_return_if_fail (display_name != NULL);
1506 attr = lookup_attribute (G_FILE_ATTRIBUTE_STD_DISPLAY_NAME);
1508 value = g_file_info_create_value (info, attr);
1510 g_file_attribute_value_set_string (value, display_name);
1514 * g_file_info_set_edit_name:
1515 * @info: a #GFileInfo.
1516 * @edit_name: a string containing an edit name.
1518 * Sets the edit name for the current file.
1519 * See %G_FILE_ATTRIBUTE_STD_EDIT_NAME.
1524 g_file_info_set_edit_name (GFileInfo *info,
1525 const char *edit_name)
1527 static guint32 attr = 0;
1528 GFileAttributeValue *value;
1530 g_return_if_fail (G_IS_FILE_INFO (info));
1531 g_return_if_fail (edit_name != NULL);
1534 attr = lookup_attribute (G_FILE_ATTRIBUTE_STD_EDIT_NAME);
1536 value = g_file_info_create_value (info, attr);
1538 g_file_attribute_value_set_string (value, edit_name);
1542 * g_file_info_set_icon:
1543 * @info: a #GFileInfo.
1546 * Sets the icon for a given #GFileInfo.
1547 * See %G_FILE_ATTRIBUTE_STD_ICON.
1551 g_file_info_set_icon (GFileInfo *info,
1554 static guint32 attr = 0;
1555 GFileAttributeValue *value;
1557 g_return_if_fail (G_IS_FILE_INFO (info));
1558 g_return_if_fail (G_IS_ICON (icon));
1561 attr = lookup_attribute (G_FILE_ATTRIBUTE_STD_ICON);
1563 value = g_file_info_create_value (info, attr);
1565 g_file_attribute_value_set_object (value, G_OBJECT (icon));
1569 * g_file_info_set_content_type:
1570 * @info: a #GFileInfo.
1571 * @content_type: a content type. See #GContentType.
1573 * Sets the content type attribute for a given #GFileInfo.
1574 * See %G_FILE_ATTRIBUTE_STD_CONTENT_TYPE.
1578 g_file_info_set_content_type (GFileInfo *info,
1579 const char *content_type)
1581 static guint32 attr = 0;
1582 GFileAttributeValue *value;
1584 g_return_if_fail (G_IS_FILE_INFO (info));
1585 g_return_if_fail (content_type != NULL);
1588 attr = lookup_attribute (G_FILE_ATTRIBUTE_STD_CONTENT_TYPE);
1590 value = g_file_info_create_value (info, attr);
1592 g_file_attribute_value_set_string (value, content_type);
1596 * g_file_info_set_size:
1597 * @info: a #GFileInfo.
1598 * @size: a #goffset containing the file's size.
1600 * Sets the %G_FILE_ATTRIBUTE_STD_SIZE attribute in the file info
1601 * to the given size.
1605 g_file_info_set_size (GFileInfo *info,
1608 static guint32 attr = 0;
1609 GFileAttributeValue *value;
1611 g_return_if_fail (G_IS_FILE_INFO (info));
1614 attr = lookup_attribute (G_FILE_ATTRIBUTE_STD_SIZE);
1616 value = g_file_info_create_value (info, attr);
1618 g_file_attribute_value_set_uint64 (value, size);
1622 * g_file_info_set_modification_time
1623 * @info: a #GFileInfo.
1624 * @mtime: a #GTimeVal.
1626 * Sets the %G_FILE_ATTRIBUTE_TIME_MODIFIED attribute in the file
1627 * info to the given time value.
1631 g_file_info_set_modification_time (GFileInfo *info,
1634 static guint32 attr_mtime = 0, attr_mtime_usec;
1635 GFileAttributeValue *value;
1637 g_return_if_fail (G_IS_FILE_INFO (info));
1638 g_return_if_fail (mtime != NULL);
1640 if (attr_mtime == 0)
1642 attr_mtime = lookup_attribute (G_FILE_ATTRIBUTE_TIME_MODIFIED);
1643 attr_mtime_usec = lookup_attribute (G_FILE_ATTRIBUTE_TIME_MODIFIED_USEC);
1646 value = g_file_info_create_value (info, attr_mtime);
1648 g_file_attribute_value_set_uint64 (value, mtime->tv_sec);
1649 value = g_file_info_create_value (info, attr_mtime_usec);
1651 g_file_attribute_value_set_uint32 (value, mtime->tv_usec);
1655 * g_file_info_set_symlink_target:
1656 * @info: a #GFileInfo.
1657 * @symlink_target: a static string containing a path to a symlink target.
1659 * Sets the %G_FILE_ATTRIBUTE_STD_SYMLINK_TARGET attribute in the file info
1660 * to the given symlink target.
1664 g_file_info_set_symlink_target (GFileInfo *info,
1665 const char *symlink_target)
1667 static guint32 attr = 0;
1668 GFileAttributeValue *value;
1670 g_return_if_fail (G_IS_FILE_INFO (info));
1671 g_return_if_fail (symlink_target != NULL);
1674 attr = lookup_attribute (G_FILE_ATTRIBUTE_STD_SYMLINK_TARGET);
1676 value = g_file_info_create_value (info, attr);
1678 g_file_attribute_value_set_byte_string (value, symlink_target);
1682 * g_file_info_set_sort_order:
1683 * @info: a #GFileInfo.
1684 * @sort_order: a sort order integer.
1686 * Sets the sort order attribute in the file info structure. See
1687 * %G_FILE_ATTRIBUTE_STD_SORT_ORDER.
1691 g_file_info_set_sort_order (GFileInfo *info,
1694 static guint32 attr = 0;
1695 GFileAttributeValue *value;
1697 g_return_if_fail (G_IS_FILE_INFO (info));
1700 attr = lookup_attribute (G_FILE_ATTRIBUTE_STD_SORT_ORDER);
1702 value = g_file_info_create_value (info, attr);
1704 g_file_attribute_value_set_int32 (value, sort_order);
1708 #define ON_STACK_MATCHERS 5
1715 struct _GFileAttributeMatcher {
1717 SubMatcher sub_matchers[ON_STACK_MATCHERS];
1718 GArray *more_sub_matchers;
1721 guint32 iterator_ns;
1727 matcher_add (GFileAttributeMatcher *matcher,
1728 guint id, guint mask)
1730 SubMatcher *sub_matchers;
1734 for (i = 0; i < ON_STACK_MATCHERS; i++)
1736 /* First empty spot, not found, use this */
1737 if (matcher->sub_matchers[i].id == 0)
1739 matcher->sub_matchers[i].id = id;
1740 matcher->sub_matchers[i].mask = mask;
1745 if (matcher->sub_matchers[i].id == id &&
1746 matcher->sub_matchers[i].mask == mask)
1750 if (matcher->more_sub_matchers == NULL)
1751 matcher->more_sub_matchers = g_array_new (FALSE, FALSE, sizeof (SubMatcher));
1753 sub_matchers = (SubMatcher *)matcher->more_sub_matchers->data;
1754 for (i = 0; i < matcher->more_sub_matchers->len; i++)
1757 if (sub_matchers[i].id == id &&
1758 sub_matchers[i].mask == mask)
1765 g_array_append_val (matcher->more_sub_matchers, s);
1769 * g_file_attribute_matcher_new:
1770 * @attributes: an attribute string to match.
1772 * Creates a new file attribute matcher, which matches attributes against
1773 * a given string. #GFileAttributeMatcher<!-- -->s are reference counted structures,
1774 * and are created with a reference count of 1. If the number of references
1775 * falls to 0, the #GFileAttributeMatcher is automatically destroyed.
1777 * The @attribute string should be formatted with specific keys separated
1778 * from namespaces with a colon. Several "namespace:key" strings may be
1779 * concatenated with a single comma (e.g. "std:type,std:is_hidden").
1780 * The wildcard "*" may be used to match all keys and namespaces, or "namespace:*" will
1781 * match all keys in a given namespace.
1783 * Examples of strings to use:
1785 * <title>File Attribute Matcher strings and results</title>
1786 * <tgroup cols='2' align='left'><thead>
1787 * <row><entry> Matcher String </entry><entry> Matches </entry></row></thead>
1789 * <row><entry>"*"</entry><entry>matches all attributes.</entry></row>
1790 * <row><entry>"std:is_hidden"</entry><entry>matches only the key is_hidden in the std namespace.</entry></row>
1791 * <row><entry>"std:type,unix:*"</entry><entry>matches the type key in the std namespace and all keys in the unix
1792 * namespace.</entry></row>
1796 * Returns: a #GFileAttributeMatcher.
1798 GFileAttributeMatcher *
1799 g_file_attribute_matcher_new (const char *attributes)
1804 GFileAttributeMatcher *matcher;
1806 if (attributes == NULL || *attributes == '\0')
1809 matcher = g_malloc0 (sizeof (GFileAttributeMatcher));
1812 split = g_strsplit (attributes, ",", -1);
1814 for (i = 0; split[i] != NULL; i++)
1816 if (strcmp (split[i], "*") == 0)
1817 matcher->all = TRUE;
1822 colon = strchr (split[i], ':');
1823 if (colon != NULL &&
1828 id = lookup_attribute (split[i]);
1836 id = lookup_namespace (split[i]) << NS_POS;
1837 mask = NS_MASK << NS_POS;
1840 matcher_add (matcher, id, mask);
1850 * g_file_attribute_matcher_ref:
1851 * @matcher: a #GFileAttributeMatcher.
1853 * References a file attribute matcher.
1855 * Returns: a #GFileAttributeMatcher.
1857 GFileAttributeMatcher *
1858 g_file_attribute_matcher_ref (GFileAttributeMatcher *matcher)
1860 g_return_val_if_fail (matcher != NULL, NULL);
1861 g_return_val_if_fail (matcher->ref > 0, NULL);
1863 g_atomic_int_inc (&matcher->ref);
1869 * g_file_attribute_matcher_unref:
1870 * @matcher: a #GFileAttributeMatcher.
1872 * Unreferences @matcher. If the reference count falls below 1,
1873 * the @matcher is automatically freed.
1877 g_file_attribute_matcher_unref (GFileAttributeMatcher *matcher)
1879 g_return_if_fail (matcher != NULL);
1880 g_return_if_fail (matcher->ref > 0);
1882 if (g_atomic_int_dec_and_test (&matcher->ref))
1884 if (matcher->more_sub_matchers)
1885 g_array_free (matcher->more_sub_matchers, TRUE);
1892 * g_file_attribute_matcher_matches_only:
1893 * @matcher: a #GFileAttributeMatcher.
1894 * @attribute: a file attribute key.
1896 * Checks if a attribute matcher only matches a given attribute. Always
1897 * returns %FALSE if "*" was used when creating the matcher.
1899 * Returns: %TRUE if the matcher only matches @attribute. %FALSE otherwise.
1902 g_file_attribute_matcher_matches_only (GFileAttributeMatcher *matcher,
1903 const char *attribute)
1907 g_return_val_if_fail (matcher != NULL, FALSE);
1908 g_return_val_if_fail (attribute != NULL && *attribute != '\0', FALSE);
1913 id = lookup_attribute (attribute);
1915 if (matcher->sub_matchers[0].id != 0 &&
1916 matcher->sub_matchers[1].id == 0 &&
1917 matcher->sub_matchers[0].mask == 0xffffffff &&
1918 matcher->sub_matchers[0].id == id)
1925 matcher_matches_id (GFileAttributeMatcher *matcher,
1928 SubMatcher *sub_matchers;
1931 for (i = 0; i < ON_STACK_MATCHERS; i++)
1933 if (matcher->sub_matchers[i].id == 0)
1936 if (matcher->sub_matchers[i].id == (id & matcher->sub_matchers[i].mask))
1940 if (matcher->more_sub_matchers)
1942 sub_matchers = (SubMatcher *)matcher->more_sub_matchers->data;
1943 for (i = 0; i < matcher->more_sub_matchers->len; i++)
1945 if (sub_matchers[i].id == (id & sub_matchers[i].mask))
1954 g_file_attribute_matcher_matches_id (GFileAttributeMatcher *matcher,
1957 g_return_val_if_fail (matcher != NULL, FALSE);
1962 return matcher_matches_id (matcher, id);
1966 * g_file_attribute_matcher_matches:
1967 * @matcher: a #GFileAttributeMatcher.
1968 * @attribute: a file attribute key.
1970 * Checks if an attribute will be matched by an attribute matcher. If
1971 * the matcher was created with the "*" matching string, this function
1972 * will always return %TRUE.
1974 * Returns: %TRUE if @attribute matches @matcher. %FALSE otherwise.
1977 g_file_attribute_matcher_matches (GFileAttributeMatcher *matcher,
1978 const char *attribute)
1980 g_return_val_if_fail (matcher != NULL, FALSE);
1981 g_return_val_if_fail (attribute != NULL && *attribute != '\0', FALSE);
1986 return matcher_matches_id (matcher, lookup_attribute (attribute));
1989 /* return TRUE -> all */
1991 * g_file_attribute_matcher_enumerate_namespace:
1992 * @matcher: a #GFileAttributeMatcher.
1993 * @ns: a string containing a file attribute namespace.
1995 * Checks if the matcher will match all of the keys in a given namespace.
1996 * This will always return %TRUE if a wildcard character is in use (e.g. if
1997 * matcher was created with "std:*" and @ns is "std", or if matcher was created
1998 * using "*" and namespace is anything.)
2000 * TODO: this is awkwardly worded.
2002 * Returns: %TRUE if the matcher matches all of the entries
2003 * in the given @ns, %FALSE otherwise.
2006 g_file_attribute_matcher_enumerate_namespace (GFileAttributeMatcher *matcher,
2009 SubMatcher *sub_matchers;
2013 g_return_val_if_fail (matcher != NULL, FALSE);
2014 g_return_val_if_fail (ns != NULL && *ns != '\0', FALSE);
2019 ns_id = lookup_namespace (ns) << NS_POS;
2021 for (i = 0; i < ON_STACK_MATCHERS; i++)
2023 if (matcher->sub_matchers[i].id == ns_id)
2027 if (matcher->more_sub_matchers)
2029 sub_matchers = (SubMatcher *)matcher->more_sub_matchers->data;
2030 for (i = 0; i < matcher->more_sub_matchers->len; i++)
2032 if (sub_matchers[i].id == ns_id)
2037 matcher->iterator_ns = ns_id;
2038 matcher->iterator_pos = 0;
2044 * g_file_attribute_matcher_enumerate_next:
2045 * @matcher: a #GFileAttributeMatcher.
2047 * Gets the next matched attribute from a #GFileAttributeMatcher.
2049 * Returns: a string containing the next attribute or %NULL if
2050 * no more attribute exist.
2053 g_file_attribute_matcher_enumerate_next (GFileAttributeMatcher *matcher)
2056 SubMatcher *sub_matcher;
2058 g_return_val_if_fail (matcher != NULL, NULL);
2062 i = matcher->iterator_pos++;
2064 if (i < ON_STACK_MATCHERS)
2066 if (matcher->sub_matchers[i].id == 0)
2069 sub_matcher = &matcher->sub_matchers[i];
2073 if (matcher->more_sub_matchers == NULL)
2076 i -= ON_STACK_MATCHERS;
2077 if (i < matcher->more_sub_matchers->len)
2078 sub_matcher = &g_array_index (matcher->more_sub_matchers, SubMatcher, i);
2083 if (sub_matcher->mask == 0xffffffff &&
2084 (sub_matcher->id & (NS_MASK << NS_POS)) == matcher->iterator_ns)
2085 return get_attribute_for_id (sub_matcher->id);
2089 #define __G_FILE_INFO_C__
2090 #include "gioaliasdef.c"