Correctly handle NULL GAttributeMatcher meaning matches nothing. (Fixes
[platform/upstream/glib.git] / gio / gfileinfo.c
1 /* GIO - GLib Input, Output and Streaming Library
2  * 
3  * Copyright (C) 2006-2007 Red Hat, Inc.
4  *
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.
9  *
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.
14  *
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.
19  *
20  * Author: Alexander Larsson <alexl@redhat.com>
21  */
22
23 /**
24  * SECTION:gfileinfo
25  * @short_description: File Information and Attributes
26  * @include: gio.h
27  * @see_also: #GFile, <link linkend="gio-GFileAttribute">GFileAttribute</link>
28  * 
29  * Functionality for manipulating basic metadata for files. #GFileInfo
30  * implements methods for getting information that all files should 
31  * contain, and allows for manipulation of extended attributes. 
32  *
33  * See <link linkend="gio-GFileAttribute">GFileAttribute</link> for more
34  * information on how GIO handles file attributes.
35  *
36  * To obtain a #GFileInfo for a #GFile, use g_file_query_info() (or its 
37  * async variant). To obtain a #GFileInfo for a file input or output 
38  * stream, use g_file_input_stream_query_info() or 
39  * g_file_output_stream_query_info() (or their async variants).
40  *
41  * To change the actual attributes of a file, you should then set the 
42  * attribute in the #GFileInfo and call g_file_set_attributes_from_info() 
43  * or g_file_set_attributes_async() on a GFile.
44  *
45  * However, not all attributes can be changed in the file. For instance, 
46  * the actual size of a file cannot be changed via g_file_info_set_size(). 
47  * You may call g_file_query_settable_attributes() and 
48  * g_file_query_writable_namespaces() to discover the settable attributes 
49  * of a particular file at runtime.
50  *
51  * #GFileAttributeMatcher allows for searching through a #GFileInfo for 
52  * attributes.
53  **/
54
55 #include <config.h>
56
57 #include <string.h>
58
59 #include "gfileinfo.h"
60 #include "gfileattribute-priv.h"
61 #include "glibintl.h"
62
63 #include "gioalias.h"
64
65 /* We use this nasty thing, because NULL is a valid attribute matcher (matches nothing) */
66 #define NO_ATTRIBUTE_MASK ((GFileAttributeMatcher *)1)
67
68 typedef struct  {
69   guint32 attribute;
70   GFileAttributeValue value;
71 } GFileAttribute;
72
73 struct _GFileInfo
74 {
75   GObject parent_instance;
76
77   GArray *attributes;
78   GFileAttributeMatcher *mask;
79 };
80
81 struct _GFileInfoClass
82 {
83   GObjectClass parent_class;
84 };
85
86
87 static gboolean g_file_attribute_matcher_matches_id (GFileAttributeMatcher *matcher,
88                                                      guint32 id);
89
90 G_DEFINE_TYPE (GFileInfo, g_file_info, G_TYPE_OBJECT);
91
92 typedef struct {
93   guint32 id;
94   guint32 attribute_id_counter;
95 } NSInfo;
96
97 G_LOCK_DEFINE_STATIC (attribute_hash);
98 static int namespace_id_counter = 0;
99 static GHashTable *ns_hash = NULL;
100 static GHashTable *attribute_hash = NULL;
101 static char ***attributes = NULL;
102
103 /* Attribute ids are 32bit, we split it up like this:
104  * |------------|--------------------|
105  *   12 bit          20 bit       
106  *   namespace      attribute id    
107  *
108  * This way the attributes gets sorted in namespace order
109  */
110
111 #define NS_POS 20
112 #define NS_MASK ((guint32)((1<<12) - 1))
113 #define ID_POS 0
114 #define ID_MASK ((guint32)((1<<20) - 1))
115
116 #define GET_NS(_attr_id) \
117     (((guint32) (_attr_id) >> NS_POS) & NS_MASK)
118 #define GET_ID(_attr_id) \
119     (((guint32)(_attr_id) >> ID_POS) & ID_MASK)
120
121 #define MAKE_ATTR_ID(_ns, _id)                          \
122     ( ((((guint32) _ns) & NS_MASK) << NS_POS) |         \
123       ((((guint32) _id) & ID_MASK) << ID_POS) )
124
125 static NSInfo *
126 _lookup_namespace (const char *namespace)
127 {
128   NSInfo *ns_info;
129   
130   ns_info = g_hash_table_lookup (ns_hash, namespace);
131   if (ns_info == NULL)
132     {
133       ns_info = g_new0 (NSInfo, 1);
134       ns_info->id = ++namespace_id_counter;
135       g_hash_table_insert (ns_hash, g_strdup (namespace), ns_info);
136       attributes = g_realloc (attributes, (ns_info->id + 1) * sizeof (char **));
137       attributes[ns_info->id] = NULL;
138     }
139   return ns_info;
140 }
141
142 static guint32
143 lookup_namespace (const char *namespace)
144 {
145   NSInfo *ns_info;
146   guint32 id;
147   
148   G_LOCK (attribute_hash);
149   
150   if (attribute_hash == NULL)
151     {
152       ns_hash = g_hash_table_new (g_str_hash, g_str_equal);
153       attribute_hash = g_hash_table_new (g_str_hash, g_str_equal);
154     }
155
156   ns_info = _lookup_namespace (namespace);
157   id = 0;
158   if (ns_info)
159     id = ns_info->id;
160   
161   G_UNLOCK (attribute_hash);
162
163   return id;
164 }
165
166 static char *
167 get_attribute_for_id (int attribute)
168 {
169   char *s;
170   G_LOCK (attribute_hash);
171   s = attributes[GET_NS(attribute)][GET_ID(attribute)];
172   G_UNLOCK (attribute_hash);
173   return s;
174 }
175
176 static guint32
177 lookup_attribute (const char *attribute)
178 {
179   guint32 attr_id, id;
180   char *ns;
181   const char *colon;
182   NSInfo *ns_info;
183   
184   G_LOCK (attribute_hash);
185   if (attribute_hash == NULL)
186     {
187       ns_hash = g_hash_table_new (g_str_hash, g_str_equal);
188       attribute_hash = g_hash_table_new (g_str_hash, g_str_equal);
189     }
190
191   attr_id = GPOINTER_TO_UINT (g_hash_table_lookup (attribute_hash, attribute));
192
193   if (attr_id != 0)
194     {
195       G_UNLOCK (attribute_hash);
196       return attr_id;
197     }
198
199   colon = strstr (attribute, "::");
200   if (colon)
201     ns = g_strndup (attribute, colon - attribute);
202   else
203     ns = g_strdup ("");
204
205   ns_info = _lookup_namespace (ns);
206   g_free (ns);
207
208   id = ++ns_info->attribute_id_counter;
209   attributes[ns_info->id] = g_realloc (attributes[ns_info->id], (id + 1) * sizeof (char *));
210   attributes[ns_info->id][id] = g_strdup (attribute);
211   
212   attr_id = MAKE_ATTR_ID (ns_info->id, id);
213
214   g_hash_table_insert (attribute_hash, attributes[ns_info->id][id], GUINT_TO_POINTER (attr_id));
215   
216   G_UNLOCK (attribute_hash);
217   
218   return attr_id;
219 }
220
221 static void
222 g_file_info_finalize (GObject *object)
223 {
224   GFileInfo *info;
225   int i;
226   GFileAttribute *attrs;
227
228   info = G_FILE_INFO (object);
229
230   attrs = (GFileAttribute *)info->attributes->data;
231   for (i = 0; i < info->attributes->len; i++)
232     _g_file_attribute_value_clear (&attrs[i].value);
233   g_array_free (info->attributes, TRUE);  
234
235   if (info->mask != NO_ATTRIBUTE_MASK)
236     g_file_attribute_matcher_unref (info->mask);
237   
238   if (G_OBJECT_CLASS (g_file_info_parent_class)->finalize)
239     (*G_OBJECT_CLASS (g_file_info_parent_class)->finalize) (object);
240 }
241
242 static void
243 g_file_info_class_init (GFileInfoClass *klass)
244 {
245   GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
246   
247   gobject_class->finalize = g_file_info_finalize;
248 }
249
250 static void
251 g_file_info_init (GFileInfo *info)
252 {
253   info->mask = NO_ATTRIBUTE_MASK;
254   info->attributes = g_array_new (FALSE, FALSE,
255                                   sizeof (GFileAttribute));
256 }
257
258 /**
259  * g_file_info_new:
260  * 
261  * Creates a new file info structure.
262  * 
263  * Returns: a #GFileInfo.
264  **/
265 GFileInfo *
266 g_file_info_new (void)
267 {
268   return g_object_new (G_TYPE_FILE_INFO, NULL);
269 }
270
271 /**
272  * g_file_info_copy_into:
273  * @src_info: source to copy attributes from.
274  * @dest_info: destination to copy attributes to.
275  * 
276  * Copies all of the #GFileAttribute<!-- -->s from @src_info to @dest_info.
277  **/
278 void
279 g_file_info_copy_into (GFileInfo *src_info, 
280                        GFileInfo *dest_info)
281 {
282   GFileAttribute *source, *dest;
283   int i;
284
285   g_return_if_fail (G_IS_FILE_INFO (src_info));
286   g_return_if_fail (G_IS_FILE_INFO (dest_info));
287
288   dest = (GFileAttribute *)dest_info->attributes->data;
289   for (i = 0; i < dest_info->attributes->len; i++)
290     _g_file_attribute_value_clear (&dest[i].value);
291   
292   g_array_set_size (dest_info->attributes,
293                     src_info->attributes->len);
294
295   source = (GFileAttribute *)src_info->attributes->data;
296   dest = (GFileAttribute *)dest_info->attributes->data;
297   
298   for (i = 0; i < src_info->attributes->len; i++)
299     {
300       dest[i].attribute = source[i].attribute;
301       dest[i].value.type = G_FILE_ATTRIBUTE_TYPE_INVALID;
302       _g_file_attribute_value_set (&dest[i].value, &source[i].value);
303     }
304
305   if (src_info->mask == NO_ATTRIBUTE_MASK)
306     dest_info->mask = NO_ATTRIBUTE_MASK;
307   else
308     dest_info->mask = g_file_attribute_matcher_ref (src_info->mask);
309 }
310
311 /**
312  * g_file_info_dup:
313  * @other: a #GFileInfo.
314  * 
315  * Duplicates a file info structure.
316  * 
317  * Returns: a duplicate #GFileInfo of @other.
318  **/
319 GFileInfo *
320 g_file_info_dup (GFileInfo *other)
321 {
322   GFileInfo *new;
323   
324   g_return_val_if_fail (G_IS_FILE_INFO (other), NULL);
325   
326   new = g_file_info_new ();
327   g_file_info_copy_into (other, new);
328   return new;
329 }
330
331 /**
332  * g_file_info_set_attribute_mask:
333  * @info: a #GFileInfo.
334  * @mask: a #GFileAttributeMatcher.
335  *
336  * Sets @mask on @info to match specific attribute types.
337  **/
338 void
339 g_file_info_set_attribute_mask (GFileInfo             *info,
340                                 GFileAttributeMatcher *mask)
341 {
342   GFileAttribute *attr;
343   int i;
344   
345   g_return_if_fail (G_IS_FILE_INFO (info));
346   
347   if (mask != info->mask)
348     {
349       if (info->mask != NO_ATTRIBUTE_MASK)
350         g_file_attribute_matcher_unref (info->mask);
351       info->mask = g_file_attribute_matcher_ref (mask);
352
353       /* Remove non-matching attributes */
354       for (i = 0; i < info->attributes->len; i++)
355         {
356           attr = &g_array_index (info->attributes, GFileAttribute, i);
357           if (!g_file_attribute_matcher_matches_id (mask,
358                                                     attr->attribute))
359             {
360               _g_file_attribute_value_clear (&attr->value);
361               g_array_remove_index (info->attributes, i);
362               i--;
363             }
364         }
365     }
366 }
367
368 /**
369  * g_file_info_unset_attribute_mask:
370  * @info: #GFileInfo.
371  * 
372  * Unsets a mask set by g_file_info_set_attribute_mask(), if one
373  * is set.
374  **/
375 void
376 g_file_info_unset_attribute_mask (GFileInfo *info)
377 {
378   g_return_if_fail (G_IS_FILE_INFO (info));
379
380   if (info->mask != NO_ATTRIBUTE_MASK)
381     g_file_attribute_matcher_unref (info->mask);
382   info->mask = NO_ATTRIBUTE_MASK;
383 }
384
385 /**
386  * g_file_info_clear_status:
387  * @info: a #GFileInfo.
388  *
389  * Clears the status information from @info.
390  **/
391 void
392 g_file_info_clear_status (GFileInfo  *info)
393 {
394   GFileAttribute *attrs;
395   int i;
396   
397   g_return_if_fail (G_IS_FILE_INFO (info));
398
399   attrs = (GFileAttribute *)info->attributes->data;
400   for (i = 0; i < info->attributes->len; i++)
401     attrs[i].value.status = G_FILE_ATTRIBUTE_STATUS_UNSET;
402 }
403
404 static int
405 g_file_info_find_place (GFileInfo  *info,
406                         guint32     attribute)
407 {
408   int min, max, med;
409   GFileAttribute *attrs;
410   /* Binary search for the place where attribute would be, if its
411      in the array */
412
413   min = 0;
414   max = info->attributes->len;
415
416   attrs = (GFileAttribute *)info->attributes->data;
417
418   while (min < max)
419     {
420       med = min + (max - min) / 2;
421       if (attrs[med].attribute == attribute)
422         {
423           min = med;
424           break;
425         }
426       else if (attrs[med].attribute < attribute)
427         min = med + 1;
428       else /* attrs[med].attribute > attribute */
429         max = med;
430     }
431
432   return min;
433 }
434
435 static GFileAttributeValue *
436 g_file_info_find_value (GFileInfo *info,
437                         guint32    attr_id)
438 {
439   GFileAttribute *attrs;
440   int i;
441
442   i = g_file_info_find_place (info, attr_id);
443   attrs = (GFileAttribute *)info->attributes->data;
444   if (i < info->attributes->len &&
445       attrs[i].attribute == attr_id)
446     return &attrs[i].value;
447   
448   return NULL;
449 }
450
451 static GFileAttributeValue *
452 g_file_info_find_value_by_name (GFileInfo  *info,
453                                 const char *attribute)
454 {
455   guint32 attr_id;
456
457   attr_id = lookup_attribute (attribute);
458   return g_file_info_find_value (info, attr_id);
459 }
460
461 /**
462  * g_file_info_has_attribute:
463  * @info: a #GFileInfo.
464  * @attribute: a file attribute key.
465  * 
466  * Checks if a file info structure has an attribute named @attribute.
467  * 
468  * Returns: %TRUE if @Ginfo has an attribute named @attribute, 
469  *     %FALSE otherwise.
470  **/
471 gboolean
472 g_file_info_has_attribute (GFileInfo  *info,
473                            const char *attribute)
474 {
475   GFileAttributeValue *value;
476
477   g_return_val_if_fail (G_IS_FILE_INFO (info), FALSE);
478   g_return_val_if_fail (attribute != NULL && *attribute != '\0', FALSE);
479
480   value = g_file_info_find_value_by_name (info, attribute);
481   return value != NULL;
482 }
483
484 /**
485  * g_file_info_list_attributes:
486  * @info: a #GFileInfo.
487  * @name_space: a file attribute key's namespace.
488  * 
489  * Lists the file info structure's attributes.
490  * 
491  * Returns: a null-terminated array of strings of all of the 
492  * possible attribute types for the given @name_space, or 
493  * %NULL on error.
494  **/
495 char **
496 g_file_info_list_attributes (GFileInfo  *info,
497                              const char *name_space)
498 {
499   GPtrArray *names;
500   GFileAttribute *attrs;
501   guint32 attribute;
502   guint32 ns_id = (name_space) ? lookup_namespace (name_space) : 0;
503   int i;
504  
505   g_return_val_if_fail (G_IS_FILE_INFO (info), NULL);
506
507   names = g_ptr_array_new ();
508   attrs = (GFileAttribute *)info->attributes->data;
509   for (i = 0; i < info->attributes->len; i++)
510     {
511       attribute = attrs[i].attribute;
512       if (ns_id == 0 || GET_NS (attribute) == ns_id)
513         g_ptr_array_add (names, g_strdup (get_attribute_for_id (attribute)));
514     }
515
516   /* NULL terminate */
517   g_ptr_array_add (names, NULL);
518   
519   return (char **)g_ptr_array_free (names, FALSE);
520 }
521
522 /**
523  * g_file_info_get_attribute_type:
524  * @info: a #GFileInfo.
525  * @attribute: a file attribute key.
526  * 
527  * Gets the attribute type for an attribute key.
528  * 
529  * Returns: a #GFileAttributeType for the given @attribute, or 
530  * %G_FILE_ATTRIBUTE_TYPE_INVALID if the key is invalid.
531  **/
532 GFileAttributeType
533 g_file_info_get_attribute_type (GFileInfo  *info,
534                                 const char *attribute)
535 {
536   GFileAttributeValue *value;
537   
538   g_return_val_if_fail (G_IS_FILE_INFO (info), G_FILE_ATTRIBUTE_TYPE_INVALID);
539   g_return_val_if_fail (attribute != NULL && *attribute != '\0', G_FILE_ATTRIBUTE_TYPE_INVALID);
540
541   value = g_file_info_find_value_by_name (info, attribute);
542   if (value)
543     return value->type;
544   else
545     return G_FILE_ATTRIBUTE_TYPE_INVALID;
546 }
547
548 /**
549  * g_file_info_remove_attribute:
550  * @info: a #GFileInfo.
551  * @attribute: a file attribute key.
552  * 
553  * Removes all cases of @attribute from @info if it exists.
554  **/
555 void
556 g_file_info_remove_attribute (GFileInfo  *info,
557                               const char *attribute)
558 {
559   guint32 attr_id;
560   GFileAttribute *attrs;
561   int i;
562
563   g_return_if_fail (G_IS_FILE_INFO (info));
564   g_return_if_fail (attribute != NULL && *attribute != '\0');
565
566   attr_id = lookup_attribute (attribute);
567   
568   i = g_file_info_find_place (info, attr_id);
569   attrs = (GFileAttribute *)info->attributes->data;
570   if (i < info->attributes->len &&
571       attrs[i].attribute == attr_id)
572     {
573       _g_file_attribute_value_clear (&attrs[i].value);
574       g_array_remove_index (info->attributes, i);
575     }
576 }
577
578 /**
579  * g_file_info_get_attribute_data:
580  * @info: a #GFileInfo
581  * @attribute: a file attribute key
582  * @type: return location for the attribute type, or %NULL
583  * @value_pp: return location for the attribute value, or %NULL
584  * @status: return location for the attribute status, or %NULL
585  *
586  * Gets the attribute type, value and status for an attribute key.
587  *
588  * Returns: %TRUE if @info has an attribute named @attribute, 
589  *      %FALSE otherwise.
590  */
591 gboolean
592 g_file_info_get_attribute_data (GFileInfo            *info,
593                                 const char           *attribute,
594                                 GFileAttributeType   *type,
595                                 gpointer             *value_pp,
596                                 GFileAttributeStatus *status)
597 {
598   GFileAttributeValue *value;
599
600   value = g_file_info_find_value_by_name (info, attribute);
601   if (value == NULL)
602     return FALSE;
603
604   if (status)
605     *status = value->status;
606
607   if (type)
608     *type = value->type;
609
610   if (value_pp)
611     *value_pp = _g_file_attribute_value_peek_as_pointer (value);
612   
613   return TRUE;
614 }
615
616 /** 
617  * g_file_info_get_attribute_status:
618  * @info: a #GFileInfo
619  * @attribute: a file attribute key
620  *
621  * Gets the attribute status for an attribute key.
622  *
623  * Returns: a #GFileAttributeStatus for the given @attribute, or 
624  *    %G_FILE_ATTRIBUTE_STATUS_UNSET if the key is invalid.
625  *
626  */
627 GFileAttributeStatus
628 g_file_info_get_attribute_status (GFileInfo  *info,
629                                   const char *attribute)
630 {
631   GFileAttributeValue *val;
632   
633   g_return_val_if_fail (G_IS_FILE_INFO (info), 0);
634   g_return_val_if_fail (attribute != NULL && *attribute != '\0', 0);
635
636   val = g_file_info_find_value_by_name (info, attribute);
637   if (val)
638     return val->status;
639
640   return G_FILE_ATTRIBUTE_STATUS_UNSET;
641 }
642
643
644 GFileAttributeValue *
645 _g_file_info_get_attribute_value (GFileInfo  *info,
646                                   const char *attribute)
647   
648 {
649   g_return_val_if_fail (G_IS_FILE_INFO (info), NULL);
650   g_return_val_if_fail (attribute != NULL && *attribute != '\0', NULL);
651
652   return g_file_info_find_value_by_name (info, attribute);
653 }
654
655 /**
656  * g_file_info_get_attribute_as_string:
657  * @info: a #GFileInfo.
658  * @attribute: a file attribute key.
659  * 
660  * Gets the value of a attribute, formated as a string.
661  * This escapes things as needed to make the string valid
662  * utf8.
663  * 
664  * Returns: a UTF-8 string associated with the given @attribute.
665  *    When you're done with the string it must be freed with g_free().
666  **/
667 char *
668 g_file_info_get_attribute_as_string (GFileInfo  *info,
669                                      const char *attribute)
670 {
671   GFileAttributeValue *val;
672   val = _g_file_info_get_attribute_value (info, attribute);
673   if (val) 
674     return _g_file_attribute_value_as_string (val);
675   return NULL;
676 }
677
678
679 /**
680  * g_file_info_get_attribute_object:
681  * @info: a #GFileInfo.
682  * @attribute: a file attribute key.
683  * 
684  * Gets the value of a #GObject attribute. If the attribute does 
685  * not contain a #GObject, %NULL will be returned.
686  * 
687  * Returns: a #GObject associated with the given @attribute, or
688  * %NULL otherwise.
689  **/
690 GObject *
691 g_file_info_get_attribute_object (GFileInfo  *info,
692                                   const char *attribute)
693 {
694   GFileAttributeValue *value;
695   
696   g_return_val_if_fail (G_IS_FILE_INFO (info), NULL);
697   g_return_val_if_fail (attribute != NULL && *attribute != '\0', NULL);
698
699   value = g_file_info_find_value_by_name (info, attribute);
700   return _g_file_attribute_value_get_object (value);
701 }
702
703 /**
704  * g_file_info_get_attribute_string:
705  * @info: a #GFileInfo.
706  * @attribute: a file attribute key.
707  * 
708  * Gets the value of a string attribute. If the attribute does 
709  * not contain a string, %NULL will be returned.
710  * 
711  * Returns: the contents of the @attribute value as a string, or 
712  * %NULL otherwise.
713  **/
714 const char *
715 g_file_info_get_attribute_string (GFileInfo  *info,
716                                   const char *attribute)
717 {
718   GFileAttributeValue *value;
719   
720   g_return_val_if_fail (G_IS_FILE_INFO (info), NULL);
721   g_return_val_if_fail (attribute != NULL && *attribute != '\0', NULL);
722
723   value = g_file_info_find_value_by_name (info, attribute);
724   return _g_file_attribute_value_get_string (value);
725 }
726
727 /**
728  * g_file_info_get_attribute_byte_string:
729  * @info: a #GFileInfo.
730  * @attribute: a file attribute key.
731  * 
732  * Gets the value of a byte string attribute. If the attribute does 
733  * not contain a byte string, %NULL will be returned.
734  * 
735  * Returns: the contents of the @attribute value as a byte string, or 
736  * %NULL otherwise.
737  **/
738 const char *
739 g_file_info_get_attribute_byte_string (GFileInfo  *info,
740                                        const char *attribute)
741 {
742   GFileAttributeValue *value;
743   
744   g_return_val_if_fail (G_IS_FILE_INFO (info), NULL);
745   g_return_val_if_fail (attribute != NULL && *attribute != '\0', NULL);
746
747   value = g_file_info_find_value_by_name (info, attribute);
748   return _g_file_attribute_value_get_byte_string (value);
749 }
750
751 /**
752  * g_file_info_get_attribute_boolean:
753  * @info: a #GFileInfo.
754  * @attribute: a file attribute key.
755  * 
756  * Gets the value of a boolean attribute. If the attribute does not
757  * contain a boolean value, %FALSE will be returned.
758  * 
759  * Returns: the boolean value contained within the attribute. 
760  **/
761 gboolean
762 g_file_info_get_attribute_boolean (GFileInfo  *info,
763                                    const char *attribute)
764 {
765   GFileAttributeValue *value;
766   
767   g_return_val_if_fail (G_IS_FILE_INFO (info), FALSE);
768   g_return_val_if_fail (attribute != NULL && *attribute != '\0', FALSE);
769
770   value = g_file_info_find_value_by_name (info, attribute);
771   return _g_file_attribute_value_get_boolean (value);
772 }
773
774 /**
775  * g_file_info_get_attribute_uint32:
776  * @info: a #GFileInfo.
777  * @attribute: a file attribute key.
778  * 
779  * Gets an unsigned 32-bit integer contained within the attribute. If the 
780  * attribute does not contain an unsigned 32-bit integer, or is invalid, 
781  * 0 will be returned.
782  * 
783  * Returns: an unsigned 32-bit integer from the attribute. 
784  **/
785 guint32
786 g_file_info_get_attribute_uint32 (GFileInfo  *info,
787                                   const char *attribute)
788 {
789   GFileAttributeValue *value;
790   
791   g_return_val_if_fail (G_IS_FILE_INFO (info), 0);
792   g_return_val_if_fail (attribute != NULL && *attribute != '\0', 0);
793
794   value = g_file_info_find_value_by_name (info, attribute);
795   return _g_file_attribute_value_get_uint32 (value);
796 }
797
798 /**
799  * g_file_info_get_attribute_int32:
800  * @info: a #GFileInfo.
801  * @attribute: a file attribute key.
802  * 
803  * Gets a signed 32-bit integer contained within the attribute. If the 
804  * attribute does not contain a signed 32-bit integer, or is invalid, 
805  * 0 will be returned.
806  * 
807  * Returns: a signed 32-bit integer from the attribute.
808  **/
809 gint32
810 g_file_info_get_attribute_int32 (GFileInfo  *info,
811                                  const char *attribute)
812 {
813   GFileAttributeValue *value;
814
815   g_return_val_if_fail (G_IS_FILE_INFO (info), 0);
816   g_return_val_if_fail (attribute != NULL && *attribute != '\0', 0);
817
818   value = g_file_info_find_value_by_name (info, attribute);
819   return _g_file_attribute_value_get_int32 (value);
820 }
821
822 /**
823  * g_file_info_get_attribute_uint64:
824  * @info: a #GFileInfo.
825  * @attribute: a file attribute key.
826  * 
827  * Gets a unsigned 64-bit integer contained within the attribute. If the 
828  * attribute does not contain an unsigned 64-bit integer, or is invalid, 
829  * 0 will be returned.
830  * 
831  * Returns: a unsigned 64-bit integer from the attribute. 
832  **/
833 guint64
834 g_file_info_get_attribute_uint64 (GFileInfo  *info,
835                                   const char *attribute)
836 {
837   GFileAttributeValue *value;
838
839   g_return_val_if_fail (G_IS_FILE_INFO (info), 0);
840   g_return_val_if_fail (attribute != NULL && *attribute != '\0', 0);
841
842   value = g_file_info_find_value_by_name (info, attribute);
843   return _g_file_attribute_value_get_uint64 (value);
844 }
845
846 /**
847  * g_file_info_get_attribute_int64:
848  * @info: a #GFileInfo.
849  * @attribute: a file attribute key.
850  * 
851  * Gets a signed 64-bit integer contained within the attribute. If the 
852  * attribute does not contain an signed 64-bit integer, or is invalid, 
853  * 0 will be returned.
854  * 
855  * Returns: a signed 64-bit integer from the attribute. 
856  **/
857 gint64
858 g_file_info_get_attribute_int64  (GFileInfo  *info,
859                                   const char *attribute)
860 {
861   GFileAttributeValue *value;
862
863   g_return_val_if_fail (G_IS_FILE_INFO (info), 0);
864   g_return_val_if_fail (attribute != NULL && *attribute != '\0', 0);
865
866   value = g_file_info_find_value_by_name (info, attribute);
867   return _g_file_attribute_value_get_int64 (value);
868 }
869
870 static GFileAttributeValue *
871 g_file_info_create_value (GFileInfo *info,
872                           guint32 attr_id)
873 {
874   GFileAttribute *attrs;
875   int i;
876
877   if (info->mask != NO_ATTRIBUTE_MASK &&
878       !g_file_attribute_matcher_matches_id (info->mask, attr_id))
879     return NULL;
880   
881   i = g_file_info_find_place (info, attr_id);
882   
883   attrs = (GFileAttribute *)info->attributes->data;
884   if (i < info->attributes->len &&
885       attrs[i].attribute == attr_id)
886     return &attrs[i].value;
887   else
888     {
889       GFileAttribute attr = { 0 };
890       attr.attribute = attr_id;
891       g_array_insert_val (info->attributes, i, attr);
892
893       attrs = (GFileAttribute *)info->attributes->data;
894       return &attrs[i].value;
895     }
896 }
897
898 static GFileAttributeValue *
899 g_file_info_create_value_by_name (GFileInfo *info,
900                                   const char *attribute)
901 {
902   guint32 attr_id;
903
904   attr_id = lookup_attribute (attribute);
905
906   return g_file_info_create_value (info, attr_id);
907 }
908
909 /**
910  * g_file_info_set_attribute:
911  * @info: a #GFileInfo.
912  * @attribute: a file attribute key.
913  * @type: a #GFileAttributeType
914  * @value_p: pointer to the value
915  * 
916  * Sets the @attribute to contain the given value, if possible.
917  **/
918 void
919 g_file_info_set_attribute (GFileInfo                 *info,
920                            const char                *attribute,
921                            GFileAttributeType         type,
922                            gpointer                   value_p)
923 {
924   GFileAttributeValue *value;
925
926   g_return_if_fail (G_IS_FILE_INFO (info));
927   g_return_if_fail (attribute != NULL && *attribute != '\0');
928
929   value = g_file_info_create_value_by_name (info, attribute);
930
931   if (value)
932     _g_file_attribute_value_set_from_pointer (value, type, value_p, TRUE);
933 }
934
935 /**
936  * g_file_info_set_attribute_object:
937  * @info: a #GFileInfo.
938  * @attribute: a file attribute key.
939  * @attr_value: a #GObject.
940  * 
941  * Sets the @attribute to contain the given @attr_value, 
942  * if possible.
943  **/
944 void
945 g_file_info_set_attribute_object (GFileInfo  *info,
946                                   const char *attribute,
947                                   GObject    *attr_value)
948 {
949   GFileAttributeValue *value;
950
951   g_return_if_fail (G_IS_FILE_INFO (info));
952   g_return_if_fail (attribute != NULL && *attribute != '\0');
953   g_return_if_fail (G_IS_OBJECT (attr_value));
954
955   value = g_file_info_create_value_by_name (info, attribute);
956   if (value)
957     _g_file_attribute_value_set_object (value, attr_value);
958 }
959
960 /**
961  * g_file_info_set_attribute_string:
962  * @info: a #GFileInfo.
963  * @attribute: a file attribute key.
964  * @attr_value: a string.
965  * 
966  * Sets the @attribute to contain the given @attr_value, 
967  * if possible.
968  **/
969 void
970 g_file_info_set_attribute_string (GFileInfo  *info,
971                                   const char *attribute,
972                                   const char *attr_value)
973 {
974   GFileAttributeValue *value;
975   
976   g_return_if_fail (G_IS_FILE_INFO (info));
977   g_return_if_fail (attribute != NULL && *attribute != '\0');
978   g_return_if_fail (attr_value != NULL);
979
980   value = g_file_info_create_value_by_name (info, attribute);
981   if (value)
982     _g_file_attribute_value_set_string (value, attr_value);
983 }
984
985 /**
986  * g_file_info_set_attribute_byte_string:
987  * @info: a #GFileInfo.
988  * @attribute: a file attribute key.
989  * @attr_value: a byte string.
990  * 
991  * Sets the @attribute to contain the given @attr_value, 
992  * if possible.
993  **/
994 void
995 g_file_info_set_attribute_byte_string (GFileInfo  *info,
996                                        const char *attribute,
997                                        const char *attr_value)
998 {
999   GFileAttributeValue *value;
1000
1001   g_return_if_fail (G_IS_FILE_INFO (info));
1002   g_return_if_fail (attribute != NULL && *attribute != '\0');
1003   g_return_if_fail (attr_value != NULL);
1004
1005   value = g_file_info_create_value_by_name (info, attribute);
1006   if (value)
1007     _g_file_attribute_value_set_byte_string (value, attr_value);
1008 }
1009
1010 /**
1011  * g_file_info_set_attribute_boolean:
1012  * @info: a #GFileInfo.
1013  * @attribute: a file attribute key.
1014  * @attr_value: a boolean value.
1015  * 
1016  * Sets the @attribute to contain the given @attr_value, 
1017  * if possible.
1018  **/
1019 void
1020 g_file_info_set_attribute_boolean (GFileInfo  *info,
1021                                    const char *attribute,
1022                                    gboolean    attr_value)
1023 {
1024   GFileAttributeValue *value;
1025
1026   g_return_if_fail (G_IS_FILE_INFO (info));
1027   g_return_if_fail (attribute != NULL && *attribute != '\0');
1028
1029   value = g_file_info_create_value_by_name (info, attribute);
1030   if (value)
1031     _g_file_attribute_value_set_boolean (value, attr_value);
1032 }
1033
1034 /**
1035  * g_file_info_set_attribute_uint32:
1036  * @info: a #GFileInfo.
1037  * @attribute: a file attribute key.
1038  * @attr_value: an unsigned 32-bit integer.
1039  * 
1040  * Sets the @attribute to contain the given @attr_value, 
1041  * if possible.
1042  **/
1043 void
1044 g_file_info_set_attribute_uint32 (GFileInfo  *info,
1045                                   const char *attribute,
1046                                   guint32     attr_value)
1047 {
1048   GFileAttributeValue *value;
1049
1050   g_return_if_fail (G_IS_FILE_INFO (info));
1051   g_return_if_fail (attribute != NULL && *attribute != '\0');
1052
1053   value = g_file_info_create_value_by_name (info, attribute);
1054   if (value)
1055     _g_file_attribute_value_set_uint32 (value, attr_value);
1056 }
1057
1058
1059 /**
1060  * g_file_info_set_attribute_int32:
1061  * @info: a #GFileInfo.
1062  * @attribute: a file attribute key.
1063  * @attr_value: a signed 32-bit integer
1064  * 
1065  * Sets the @attribute to contain the given @attr_value, 
1066  * if possible.
1067  **/
1068 void
1069 g_file_info_set_attribute_int32 (GFileInfo  *info,
1070                                  const char *attribute,
1071                                  gint32      attr_value)
1072 {
1073   GFileAttributeValue *value;
1074  
1075   g_return_if_fail (G_IS_FILE_INFO (info));
1076   g_return_if_fail (attribute != NULL && *attribute != '\0');
1077
1078   value = g_file_info_create_value_by_name (info, attribute);
1079   if (value)
1080     _g_file_attribute_value_set_int32 (value, attr_value);
1081 }
1082
1083 /**
1084  * g_file_info_set_attribute_uint64:
1085  * @info: a #GFileInfo.
1086  * @attribute: a file attribute key.
1087  * @attr_value: an unsigned 64-bit integer.
1088  * 
1089  * Sets the @attribute to contain the given @attr_value, 
1090  * if possible.
1091  **/
1092 void
1093 g_file_info_set_attribute_uint64 (GFileInfo  *info,
1094                                   const char *attribute,
1095                                   guint64     attr_value)
1096 {
1097   GFileAttributeValue *value;
1098
1099   g_return_if_fail (G_IS_FILE_INFO (info));
1100   g_return_if_fail (attribute != NULL && *attribute != '\0');
1101
1102   value = g_file_info_create_value_by_name (info, attribute);
1103   if (value)
1104     _g_file_attribute_value_set_uint64 (value, attr_value);
1105 }
1106
1107 /**
1108  * g_file_info_set_attribute_int64:
1109  * @info: a #GFileInfo.
1110  * @attribute: attribute name to set.
1111  * @attr_value: int64 value to set attribute to.
1112  * 
1113  * Sets the @attribute to contain the given @attr_value, 
1114  * if possible.
1115  * 
1116  **/
1117 void
1118 g_file_info_set_attribute_int64  (GFileInfo  *info,
1119                                   const char *attribute,
1120                                   gint64      attr_value)
1121 {
1122   GFileAttributeValue *value;
1123
1124   g_return_if_fail (G_IS_FILE_INFO (info));
1125   g_return_if_fail (attribute != NULL && *attribute != '\0');
1126
1127   value = g_file_info_create_value_by_name (info, attribute);
1128   if (value)
1129     _g_file_attribute_value_set_int64 (value, attr_value);
1130 }
1131
1132 /* Helper getters */
1133 /**
1134  * g_file_info_get_file_type:
1135  * @info: a #GFileInfo.
1136  * 
1137  * Gets a file's type (whether it is a regular file, symlink, etc). 
1138  * This is different from the file's content type, see g_file_info_get_content_type().
1139  * 
1140  * Returns: a #GFileType for the given file.
1141  **/
1142 GFileType
1143 g_file_info_get_file_type (GFileInfo *info)
1144 {
1145   static guint32 attr = 0;
1146   GFileAttributeValue *value;
1147
1148   g_return_val_if_fail (G_IS_FILE_INFO (info), G_FILE_TYPE_UNKNOWN);
1149   
1150   if (attr == 0)
1151     attr = lookup_attribute (G_FILE_ATTRIBUTE_STANDARD_TYPE);
1152   
1153   value = g_file_info_find_value (info, attr);
1154   return (GFileType)_g_file_attribute_value_get_uint32 (value);
1155 }
1156
1157 /**
1158  * g_file_info_get_is_hidden:
1159  * @info: a #GFileInfo.
1160  * 
1161  * Checks if a file is hidden.
1162  * 
1163  * Returns: %TRUE if the file is a hidden file, %FALSE otherwise.
1164  **/
1165 gboolean
1166 g_file_info_get_is_hidden (GFileInfo *info)
1167 {
1168   static guint32 attr = 0;
1169   GFileAttributeValue *value;
1170   
1171   g_return_val_if_fail (G_IS_FILE_INFO (info), FALSE);
1172   
1173   if (attr == 0)
1174     attr = lookup_attribute (G_FILE_ATTRIBUTE_STANDARD_IS_HIDDEN);
1175   
1176   value = g_file_info_find_value (info, attr);
1177   return (GFileType)_g_file_attribute_value_get_boolean (value);
1178 }
1179
1180 /**
1181  * g_file_info_get_is_backup:
1182  * @info: a #GFileInfo.
1183  * 
1184  * Checks if a file is a backup file.
1185  * 
1186  * Returns: %TRUE if file is a backup file, %FALSE otherwise.
1187  **/
1188 gboolean
1189 g_file_info_get_is_backup (GFileInfo *info)
1190 {
1191   static guint32 attr = 0;
1192   GFileAttributeValue *value;
1193   
1194   g_return_val_if_fail (G_IS_FILE_INFO (info), FALSE);
1195   
1196   if (attr == 0)
1197     attr = lookup_attribute (G_FILE_ATTRIBUTE_STANDARD_IS_BACKUP);
1198   
1199   value = g_file_info_find_value (info, attr);
1200   return (GFileType)_g_file_attribute_value_get_boolean (value);
1201 }
1202
1203 /**
1204  * g_file_info_get_is_symlink:
1205  * @info: a #GFileInfo.
1206  * 
1207  * Checks if a file is a symlink.
1208  * 
1209  * Returns: %TRUE if the given @info is a symlink.
1210  **/
1211 gboolean
1212 g_file_info_get_is_symlink (GFileInfo *info)
1213 {
1214   static guint32 attr = 0;
1215   GFileAttributeValue *value;
1216   
1217   g_return_val_if_fail (G_IS_FILE_INFO (info), FALSE);
1218   
1219   if (attr == 0)
1220     attr = lookup_attribute (G_FILE_ATTRIBUTE_STANDARD_IS_SYMLINK);
1221   
1222   value = g_file_info_find_value (info, attr);
1223   return (GFileType)_g_file_attribute_value_get_boolean (value);
1224 }
1225
1226 /**
1227  * g_file_info_get_name:
1228  * @info: a #GFileInfo.
1229  * 
1230  * Gets the name for a file.
1231  * 
1232  * Returns: a string containing the file name.
1233  **/
1234 const char *
1235 g_file_info_get_name (GFileInfo *info)
1236 {
1237   static guint32 attr = 0;
1238   GFileAttributeValue *value;
1239   
1240   g_return_val_if_fail (G_IS_FILE_INFO (info), NULL);
1241   
1242   if (attr == 0)
1243     attr = lookup_attribute (G_FILE_ATTRIBUTE_STANDARD_NAME);
1244   
1245   value = g_file_info_find_value (info, attr);
1246   return _g_file_attribute_value_get_byte_string (value);
1247 }
1248
1249 /**
1250  * g_file_info_get_display_name:
1251  * @info: a #GFileInfo.
1252  * 
1253  * Gets a display name for a file.
1254  * 
1255  * Returns: a string containing the display name.
1256  **/
1257 const char *
1258 g_file_info_get_display_name (GFileInfo *info)
1259 {
1260   static guint32 attr = 0;
1261   GFileAttributeValue *value;
1262   
1263   g_return_val_if_fail (G_IS_FILE_INFO (info), NULL);
1264   
1265   if (attr == 0)
1266     attr = lookup_attribute (G_FILE_ATTRIBUTE_STANDARD_DISPLAY_NAME);
1267   
1268   value = g_file_info_find_value (info, attr);
1269   return _g_file_attribute_value_get_string (value);
1270 }
1271
1272 /**
1273  * g_file_info_get_edit_name:
1274  * @info: a #GFileInfo.
1275  * 
1276  * Gets the edit name for a file.
1277  * 
1278  * Returns: a string containing the edit name.
1279  **/
1280 const char *
1281 g_file_info_get_edit_name (GFileInfo *info)
1282 {
1283   static guint32 attr = 0;
1284   GFileAttributeValue *value;
1285   
1286   g_return_val_if_fail (G_IS_FILE_INFO (info), NULL);
1287   
1288   if (attr == 0)
1289     attr = lookup_attribute (G_FILE_ATTRIBUTE_STANDARD_EDIT_NAME);
1290   
1291   value = g_file_info_find_value (info, attr);
1292   return _g_file_attribute_value_get_string (value);
1293 }
1294
1295 /**
1296  * g_file_info_get_icon:
1297  * @info: a #GFileInfo.
1298  * 
1299  * Gets the icon for a file.
1300  * 
1301  * Returns: #GIcon for the given @info.
1302  **/
1303 GIcon *
1304 g_file_info_get_icon (GFileInfo *info)
1305 {
1306   static guint32 attr = 0;
1307   GFileAttributeValue *value;
1308   GObject *obj;
1309   
1310   g_return_val_if_fail (G_IS_FILE_INFO (info), NULL);
1311   
1312   if (attr == 0)
1313     attr = lookup_attribute (G_FILE_ATTRIBUTE_STANDARD_ICON);
1314   
1315   value = g_file_info_find_value (info, attr);
1316   obj = _g_file_attribute_value_get_object (value);
1317   if (G_IS_ICON (obj))
1318     return G_ICON (obj);
1319   return NULL;
1320 }
1321
1322 /**
1323  * g_file_info_get_content_type:
1324  * @info: a #GFileInfo.
1325  * 
1326  * Gets the file's content type.
1327  * 
1328  * Returns: a string containing the file's content type.s
1329  **/
1330 const char *
1331 g_file_info_get_content_type (GFileInfo *info)
1332 {
1333   static guint32 attr = 0;
1334   GFileAttributeValue *value;
1335   
1336   g_return_val_if_fail (G_IS_FILE_INFO (info), NULL);
1337   
1338   if (attr == 0)
1339     attr = lookup_attribute (G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE);
1340   
1341   value = g_file_info_find_value (info, attr);
1342   return _g_file_attribute_value_get_string (value);
1343 }
1344
1345 /**
1346  * g_file_info_get_size:
1347  * @info: a #GFileInfo.
1348  * 
1349  * Gets the file's size.
1350  * 
1351  * Returns: a #goffset containing the file's size. 
1352  **/
1353 goffset
1354 g_file_info_get_size (GFileInfo *info)
1355 {
1356   static guint32 attr = 0;
1357   GFileAttributeValue *value;
1358  
1359   g_return_val_if_fail (G_IS_FILE_INFO (info), (goffset) 0);
1360   
1361   if (attr == 0)
1362     attr = lookup_attribute (G_FILE_ATTRIBUTE_STANDARD_SIZE);
1363   
1364   value = g_file_info_find_value (info, attr);
1365   return (goffset) _g_file_attribute_value_get_uint64 (value);
1366 }
1367
1368 /**
1369  * g_file_info_get_modification_time:
1370  * @info: a #GFileInfo.
1371  * @result: a #GTimeVal.
1372  * 
1373  * Gets the modification time of the current @info and sets it
1374  * in @result.
1375  **/
1376 void
1377 g_file_info_get_modification_time (GFileInfo *info,
1378                                    GTimeVal  *result)
1379 {
1380   static guint32 attr_mtime = 0, attr_mtime_usec;
1381   GFileAttributeValue *value;
1382
1383   g_return_if_fail (G_IS_FILE_INFO (info));
1384   g_return_if_fail (result != NULL);
1385   
1386   if (attr_mtime == 0)
1387     {
1388       attr_mtime = lookup_attribute (G_FILE_ATTRIBUTE_TIME_MODIFIED);
1389       attr_mtime_usec = lookup_attribute (G_FILE_ATTRIBUTE_TIME_MODIFIED_USEC);
1390     }
1391   
1392   value = g_file_info_find_value (info, attr_mtime);
1393   result->tv_sec = _g_file_attribute_value_get_uint64 (value);
1394   value = g_file_info_find_value (info, attr_mtime_usec);
1395   result->tv_usec = _g_file_attribute_value_get_uint32 (value);
1396 }
1397
1398 /**
1399  * g_file_info_get_symlink_target:
1400  * @info: a #GFileInfo.
1401  * 
1402  * Gets the symlink target for a given #GFileInfo.
1403  * 
1404  * Returns: a string containing the symlink target.
1405  **/
1406 const char *
1407 g_file_info_get_symlink_target (GFileInfo *info)
1408 {
1409   static guint32 attr = 0;
1410   GFileAttributeValue *value;
1411   
1412   g_return_val_if_fail (G_IS_FILE_INFO (info), NULL);
1413   
1414   if (attr == 0)
1415     attr = lookup_attribute (G_FILE_ATTRIBUTE_STANDARD_SYMLINK_TARGET);
1416   
1417   value = g_file_info_find_value (info, attr);
1418   return _g_file_attribute_value_get_byte_string (value);
1419 }
1420
1421 /**
1422  * g_file_info_get_etag:
1423  * @info: a #GFileInfo.
1424  * 
1425  * Gets the <link linkend="gfile-etag">entity tag</link> for a given 
1426  * #GFileInfo. See %G_FILE_ATTRIBUTE_ETAG_VALUE.
1427  * 
1428  * Returns: a string containing the value of the "etag:value" attribute.
1429  **/
1430 const char *
1431 g_file_info_get_etag (GFileInfo *info)
1432 {
1433   static guint32 attr = 0;
1434   GFileAttributeValue *value;
1435   
1436   g_return_val_if_fail (G_IS_FILE_INFO (info), NULL);
1437   
1438   if (attr == 0)
1439     attr = lookup_attribute (G_FILE_ATTRIBUTE_ETAG_VALUE);
1440   
1441   value = g_file_info_find_value (info, attr);
1442   return _g_file_attribute_value_get_string (value);
1443 }
1444
1445 /**
1446  * g_file_info_get_sort_order:
1447  * @info: a #GFileInfo.
1448  * 
1449  * Gets the value of the sort_order attribute from the #GFileInfo.
1450  * See %G_FILE_ATTRIBUTE_STANDARD_SORT_ORDER.
1451  * 
1452  * Returns: a #gint32 containing the value of the "standard::sort_order" attribute.
1453  **/
1454 gint32
1455 g_file_info_get_sort_order (GFileInfo *info)
1456 {
1457   static guint32 attr = 0;
1458   GFileAttributeValue *value;
1459   
1460   g_return_val_if_fail (G_IS_FILE_INFO (info), 0);
1461   
1462   if (attr == 0)
1463     attr = lookup_attribute (G_FILE_ATTRIBUTE_STANDARD_SORT_ORDER);
1464   
1465   value = g_file_info_find_value (info, attr);
1466   return _g_file_attribute_value_get_int32 (value);
1467 }
1468
1469 /* Helper setters: */
1470 /**
1471  * g_file_info_set_file_type:
1472  * @info: a #GFileInfo.
1473  * @type: a #GFileType.
1474  * 
1475  * Sets the file type in a #GFileInfo to @type.
1476  * See %G_FILE_ATTRIBUTE_STANDARD_TYPE.
1477  **/
1478 void
1479 g_file_info_set_file_type (GFileInfo *info,
1480                            GFileType  type)
1481 {
1482   static guint32 attr = 0;
1483   GFileAttributeValue *value;
1484   
1485   g_return_if_fail (G_IS_FILE_INFO (info));
1486   
1487   if (attr == 0)
1488     attr = lookup_attribute (G_FILE_ATTRIBUTE_STANDARD_TYPE);
1489   
1490   value = g_file_info_create_value (info, attr);
1491   if (value)
1492     _g_file_attribute_value_set_uint32 (value, type);
1493 }
1494
1495 /**
1496  * g_file_info_set_is_hidden:
1497  * @info: a #GFileInfo.
1498  * @is_hidden: a #gboolean.
1499  * 
1500  * Sets the "is_hidden" attribute in a #GFileInfo according to @is_symlink.
1501  * See %G_FILE_ATTRIBUTE_STANDARD_IS_HIDDEN.
1502  **/
1503 void
1504 g_file_info_set_is_hidden (GFileInfo *info,
1505                            gboolean   is_hidden)
1506 {
1507   static guint32 attr = 0;
1508   GFileAttributeValue *value;
1509   
1510   g_return_if_fail (G_IS_FILE_INFO (info));
1511   
1512   if (attr == 0)
1513     attr = lookup_attribute (G_FILE_ATTRIBUTE_STANDARD_IS_HIDDEN);
1514   
1515   value = g_file_info_create_value (info, attr);
1516   if (value)
1517     _g_file_attribute_value_set_boolean (value, is_hidden);
1518 }
1519
1520 /**
1521  * g_file_info_set_is_symlink:
1522  * @info: a #GFileInfo.
1523  * @is_symlink: a #gboolean.
1524  * 
1525  * Sets the "is_symlink" attribute in a #GFileInfo according to @is_symlink.
1526  * See %G_FILE_ATTRIBUTE_STANDARD_IS_SYMLINK.
1527  **/
1528 void
1529 g_file_info_set_is_symlink (GFileInfo *info,
1530                             gboolean   is_symlink)
1531 {
1532   static guint32 attr = 0;
1533   GFileAttributeValue *value;
1534   
1535   g_return_if_fail (G_IS_FILE_INFO (info));
1536   
1537   if (attr == 0)
1538     attr = lookup_attribute (G_FILE_ATTRIBUTE_STANDARD_IS_SYMLINK);
1539   
1540   value = g_file_info_create_value (info, attr);
1541   if (value)
1542     _g_file_attribute_value_set_boolean (value, is_symlink);
1543 }
1544
1545 /**
1546  * g_file_info_set_name:
1547  * @info: a #GFileInfo.
1548  * @name: a string containing a name.
1549  * 
1550  * Sets the name attribute for the current #GFileInfo. 
1551  * See %G_FILE_ATTRIBUTE_STANDARD_NAME.
1552  **/
1553 void
1554 g_file_info_set_name (GFileInfo  *info,
1555                       const char *name)
1556 {
1557   static guint32 attr = 0;
1558   GFileAttributeValue *value;
1559   
1560   g_return_if_fail (G_IS_FILE_INFO (info));
1561   g_return_if_fail (name != NULL);
1562   
1563   if (attr == 0)
1564     attr = lookup_attribute (G_FILE_ATTRIBUTE_STANDARD_NAME);
1565   
1566   value = g_file_info_create_value (info, attr);
1567   if (value)
1568     _g_file_attribute_value_set_byte_string (value, name);
1569 }
1570
1571 /**
1572  * g_file_info_set_display_name:
1573  * @info: a #GFileInfo.
1574  * @display_name: a string containing a display name.
1575  * 
1576  * Sets the display name for the current #GFileInfo.
1577  * See %G_FILE_ATTRIBUTE_STANDARD_DISPLAY_NAME.
1578  **/
1579 void
1580 g_file_info_set_display_name (GFileInfo  *info,
1581                               const char *display_name)
1582 {
1583   static guint32 attr = 0;
1584   GFileAttributeValue *value;
1585   
1586   g_return_if_fail (G_IS_FILE_INFO (info));
1587   g_return_if_fail (display_name != NULL);
1588   
1589   if (attr == 0)
1590     attr = lookup_attribute (G_FILE_ATTRIBUTE_STANDARD_DISPLAY_NAME);
1591   
1592   value = g_file_info_create_value (info, attr);
1593   if (value)
1594     _g_file_attribute_value_set_string (value, display_name);
1595 }
1596
1597 /**
1598  * g_file_info_set_edit_name:
1599  * @info: a #GFileInfo.
1600  * @edit_name: a string containing an edit name.
1601  * 
1602  * Sets the edit name for the current file.
1603  * See %G_FILE_ATTRIBUTE_STANDARD_EDIT_NAME.
1604  **/
1605 void
1606 g_file_info_set_edit_name (GFileInfo  *info,
1607                            const char *edit_name)
1608 {
1609   static guint32 attr = 0;
1610   GFileAttributeValue *value;
1611   
1612   g_return_if_fail (G_IS_FILE_INFO (info));
1613   g_return_if_fail (edit_name != NULL);
1614   
1615   if (attr == 0)
1616     attr = lookup_attribute (G_FILE_ATTRIBUTE_STANDARD_EDIT_NAME);
1617   
1618   value = g_file_info_create_value (info, attr);
1619   if (value)
1620     _g_file_attribute_value_set_string (value, edit_name);
1621 }
1622
1623 /**
1624  * g_file_info_set_icon:
1625  * @info: a #GFileInfo.
1626  * @icon: a #GIcon.
1627  * 
1628  * Sets the icon for a given #GFileInfo. 
1629  * See %G_FILE_ATTRIBUTE_STANDARD_ICON.
1630  **/
1631 void
1632 g_file_info_set_icon (GFileInfo *info,
1633                       GIcon     *icon)
1634 {
1635   static guint32 attr = 0;
1636   GFileAttributeValue *value;
1637   
1638   g_return_if_fail (G_IS_FILE_INFO (info));
1639   g_return_if_fail (G_IS_ICON (icon));
1640   
1641   if (attr == 0)
1642     attr = lookup_attribute (G_FILE_ATTRIBUTE_STANDARD_ICON);
1643   
1644   value = g_file_info_create_value (info, attr);
1645   if (value)
1646     _g_file_attribute_value_set_object (value, G_OBJECT (icon));
1647 }
1648
1649 /**
1650  * g_file_info_set_content_type:
1651  * @info: a #GFileInfo.
1652  * @content_type: a content type. See #GContentType.
1653  * 
1654  * Sets the content type attribute for a given #GFileInfo.
1655  * See %G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE.
1656  **/
1657 void
1658 g_file_info_set_content_type (GFileInfo  *info,
1659                               const char *content_type)
1660 {
1661   static guint32 attr = 0;
1662   GFileAttributeValue *value;
1663   
1664   g_return_if_fail (G_IS_FILE_INFO (info));
1665   g_return_if_fail (content_type != NULL);
1666   
1667   if (attr == 0)
1668     attr = lookup_attribute (G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE);
1669   
1670   value = g_file_info_create_value (info, attr);
1671   if (value)
1672     _g_file_attribute_value_set_string (value, content_type);
1673 }
1674
1675 /**
1676  * g_file_info_set_size:
1677  * @info: a #GFileInfo.
1678  * @size: a #goffset containing the file's size.
1679  * 
1680  * Sets the %G_FILE_ATTRIBUTE_STANDARD_SIZE attribute in the file info 
1681  * to the given size.
1682  **/
1683 void
1684 g_file_info_set_size (GFileInfo *info,
1685                       goffset    size)
1686 {
1687   static guint32 attr = 0;
1688   GFileAttributeValue *value;
1689   
1690   g_return_if_fail (G_IS_FILE_INFO (info));
1691   
1692   if (attr == 0)
1693     attr = lookup_attribute (G_FILE_ATTRIBUTE_STANDARD_SIZE);
1694   
1695   value = g_file_info_create_value (info, attr);
1696   if (value)
1697     _g_file_attribute_value_set_uint64 (value, size);
1698 }
1699
1700 /**
1701  * g_file_info_set_modification_time
1702  * @info: a #GFileInfo.
1703  * @mtime: a #GTimeVal.
1704  * 
1705  * Sets the %G_FILE_ATTRIBUTE_TIME_MODIFIED attribute in the file
1706  * info to the given time value.
1707  **/
1708 void
1709 g_file_info_set_modification_time (GFileInfo *info,
1710                                    GTimeVal  *mtime)
1711 {
1712   static guint32 attr_mtime = 0, attr_mtime_usec;
1713   GFileAttributeValue *value;
1714   
1715   g_return_if_fail (G_IS_FILE_INFO (info));
1716   g_return_if_fail (mtime != NULL);
1717   
1718   if (attr_mtime == 0)
1719     {
1720       attr_mtime = lookup_attribute (G_FILE_ATTRIBUTE_TIME_MODIFIED);
1721       attr_mtime_usec = lookup_attribute (G_FILE_ATTRIBUTE_TIME_MODIFIED_USEC);
1722     }
1723   
1724   value = g_file_info_create_value (info, attr_mtime);
1725   if (value)
1726     _g_file_attribute_value_set_uint64 (value, mtime->tv_sec);
1727   value = g_file_info_create_value (info, attr_mtime_usec);
1728   if (value)
1729     _g_file_attribute_value_set_uint32 (value, mtime->tv_usec);
1730 }
1731
1732 /**
1733  * g_file_info_set_symlink_target:
1734  * @info: a #GFileInfo.
1735  * @symlink_target: a static string containing a path to a symlink target.
1736  * 
1737  * Sets the %G_FILE_ATTRIBUTE_STANDARD_SYMLINK_TARGET attribute in the file info 
1738  * to the given symlink target.
1739  **/
1740 void
1741 g_file_info_set_symlink_target (GFileInfo  *info,
1742                                 const char *symlink_target)
1743 {
1744   static guint32 attr = 0;
1745   GFileAttributeValue *value;
1746   
1747   g_return_if_fail (G_IS_FILE_INFO (info));
1748   g_return_if_fail (symlink_target != NULL);
1749   
1750   if (attr == 0)
1751     attr = lookup_attribute (G_FILE_ATTRIBUTE_STANDARD_SYMLINK_TARGET);
1752   
1753   value = g_file_info_create_value (info, attr);
1754   if (value)
1755     _g_file_attribute_value_set_byte_string (value, symlink_target);
1756 }
1757
1758 /**
1759  * g_file_info_set_sort_order:
1760  * @info: a #GFileInfo.
1761  * @sort_order: a sort order integer.
1762  * 
1763  * Sets the sort order attribute in the file info structure. See 
1764  * %G_FILE_ATTRIBUTE_STANDARD_SORT_ORDER.
1765  **/
1766 void
1767 g_file_info_set_sort_order (GFileInfo *info,
1768                             gint32     sort_order)
1769 {
1770   static guint32 attr = 0;
1771   GFileAttributeValue *value;
1772   
1773   g_return_if_fail (G_IS_FILE_INFO (info));
1774   
1775   if (attr == 0)
1776     attr = lookup_attribute (G_FILE_ATTRIBUTE_STANDARD_SORT_ORDER);
1777   
1778   value = g_file_info_create_value (info, attr);
1779   if (value)
1780     _g_file_attribute_value_set_int32 (value, sort_order);
1781 }
1782
1783
1784 #define ON_STACK_MATCHERS 5
1785
1786 typedef struct {
1787   guint32 id;
1788   guint32 mask;
1789 } SubMatcher;
1790
1791 struct _GFileAttributeMatcher {
1792   gboolean all;
1793   SubMatcher sub_matchers[ON_STACK_MATCHERS];
1794   GArray *more_sub_matchers;
1795
1796   /* Interator */
1797   guint32 iterator_ns;
1798   int iterator_pos;
1799   int ref;
1800 };
1801
1802 static void
1803 matcher_add (GFileAttributeMatcher *matcher,
1804              guint                  id,
1805              guint                  mask)
1806 {
1807   SubMatcher *sub_matchers;
1808   int i;
1809   SubMatcher s;
1810
1811   for (i = 0; i < ON_STACK_MATCHERS; i++)
1812     {
1813       /* First empty spot, not found, use this */
1814       if (matcher->sub_matchers[i].id == 0)
1815         {
1816           matcher->sub_matchers[i].id = id;
1817           matcher->sub_matchers[i].mask = mask;
1818           return;
1819         }
1820       
1821       /* Already added */
1822       if (matcher->sub_matchers[i].id == id &&
1823           matcher->sub_matchers[i].mask == mask)
1824         return;
1825     }
1826
1827   if (matcher->more_sub_matchers == NULL)
1828     matcher->more_sub_matchers = g_array_new (FALSE, FALSE, sizeof (SubMatcher));
1829       
1830   sub_matchers = (SubMatcher *)matcher->more_sub_matchers->data;
1831   for (i = 0; i < matcher->more_sub_matchers->len; i++)
1832     {
1833       /* Already added */
1834       if (sub_matchers[i].id == id &&
1835           sub_matchers[i].mask == mask)
1836         return;
1837     }
1838
1839   s.id = id;
1840   s.mask = mask;
1841   
1842   g_array_append_val (matcher->more_sub_matchers, s);
1843 }
1844
1845 /**
1846  * g_file_attribute_matcher_new:
1847  * @attributes: an attribute string to match.
1848  * 
1849  * Creates a new file attribute matcher, which matches attributes 
1850  * against a given string. #GFileAttributeMatcher<!-- -->s are reference 
1851  * counted structures, and are created with a reference count of 1. If 
1852  * the number of references falls to 0, the #GFileAttributeMatcher is 
1853  * automatically destroyed.
1854  * 
1855  * The @attribute string should be formatted with specific keys separated
1856  * from namespaces with a double colon. Several "namespace::key" strings may be 
1857  * concatenated with a single comma (e.g. "standard::type,standard::is-hidden"). 
1858  * The wildcard "*" may be used to match all keys and namespaces, or 
1859  * "namespace::*" will match all keys in a given namespace. 
1860  * 
1861  * Examples of strings to use:
1862  * <table>
1863  * <title>File Attribute Matcher strings and results</title>
1864  * <tgroup cols='2' align='left'><thead>
1865  * <row><entry> Matcher String </entry><entry> Matches </entry></row></thead>
1866  * <tbody>
1867  * <row><entry>"*"</entry><entry>matches all attributes.</entry></row>
1868  * <row><entry>"standard::is-hidden"</entry><entry>matches only the key is-hidden in the standard namespace.</entry></row>
1869  * <row><entry>"standard::type,unix::*"</entry><entry>matches the type key in the standard namespace and
1870  * all keys in the unix namespace.</entry></row>
1871  * </tbody></tgroup>
1872  * </table>
1873  * 
1874  * Returns: a #GFileAttributeMatcher.
1875  **/
1876 GFileAttributeMatcher *
1877 g_file_attribute_matcher_new (const char *attributes)
1878 {
1879   char **split;
1880   char *colon;
1881   int i;
1882   GFileAttributeMatcher *matcher;
1883
1884   if (attributes == NULL || *attributes == '\0')
1885     return NULL;
1886
1887   matcher = g_malloc0 (sizeof (GFileAttributeMatcher));
1888   matcher->ref = 1;
1889
1890   split = g_strsplit (attributes, ",", -1);
1891
1892   for (i = 0; split[i] != NULL; i++)
1893     {
1894       if (strcmp (split[i], "*") == 0)
1895         matcher->all = TRUE;
1896       else
1897         {
1898           guint32 id, mask;
1899   
1900           colon = strstr (split[i], "::");
1901           if (colon != NULL &&
1902               !(colon[2] == 0 ||
1903                 (colon[2] == '*' &&
1904                  colon[3] == 0)))
1905             {
1906               id = lookup_attribute (split[i]);
1907               mask = 0xffffffff;
1908             }
1909           else
1910             {
1911               if (colon)
1912                 *colon = 0;
1913
1914               id = lookup_namespace (split[i]) << NS_POS;
1915               mask = NS_MASK << NS_POS;
1916             }
1917           
1918           matcher_add (matcher, id, mask);
1919         }
1920     }
1921
1922   g_strfreev (split);
1923
1924   return matcher;
1925 }
1926
1927 /**
1928  * g_file_attribute_matcher_ref:
1929  * @matcher: a #GFileAttributeMatcher.
1930  * 
1931  * References a file attribute matcher.
1932  * 
1933  * Returns: a #GFileAttributeMatcher.
1934  **/
1935 GFileAttributeMatcher *
1936 g_file_attribute_matcher_ref (GFileAttributeMatcher *matcher)
1937 {
1938   if (matcher)
1939     {
1940       g_return_val_if_fail (matcher->ref > 0, NULL);
1941       g_atomic_int_inc (&matcher->ref);
1942     }
1943   return matcher;
1944 }
1945
1946 /**
1947  * g_file_attribute_matcher_unref:
1948  * @matcher: a #GFileAttributeMatcher.
1949  * 
1950  * Unreferences @matcher. If the reference count falls below 1, 
1951  * the @matcher is automatically freed.
1952  * 
1953  **/
1954 void
1955 g_file_attribute_matcher_unref (GFileAttributeMatcher *matcher)
1956 {
1957   if (matcher)
1958     {
1959       g_return_if_fail (matcher->ref > 0);
1960       
1961       if (g_atomic_int_dec_and_test (&matcher->ref))
1962         {
1963           if (matcher->more_sub_matchers)
1964             g_array_free (matcher->more_sub_matchers, TRUE);
1965           
1966           g_free (matcher);
1967         }
1968     }
1969 }
1970
1971 /**
1972  * g_file_attribute_matcher_matches_only:
1973  * @matcher: a #GFileAttributeMatcher.
1974  * @attribute: a file attribute key.
1975  * 
1976  * Checks if a attribute matcher only matches a given attribute. Always
1977  * returns %FALSE if "*" was used when creating the matcher.
1978  * 
1979  * Returns: %TRUE if the matcher only matches @attribute. %FALSE otherwise.
1980  **/
1981 gboolean
1982 g_file_attribute_matcher_matches_only (GFileAttributeMatcher *matcher,
1983                                        const char            *attribute)
1984 {
1985   guint32 id;
1986
1987   g_return_val_if_fail (attribute != NULL && *attribute != '\0', FALSE);
1988
1989   if (matcher == NULL ||
1990       matcher->all)
1991     return FALSE;
1992   
1993   id = lookup_attribute (attribute);
1994
1995   if (matcher->sub_matchers[0].id != 0 &&
1996       matcher->sub_matchers[1].id == 0 &&
1997       matcher->sub_matchers[0].mask == 0xffffffff &&
1998       matcher->sub_matchers[0].id == id)
1999     return TRUE;
2000   
2001   return FALSE;
2002 }
2003
2004 static gboolean
2005 matcher_matches_id (GFileAttributeMatcher *matcher,
2006                     guint32                id)
2007 {
2008   SubMatcher *sub_matchers;
2009   int i;
2010   
2011   for (i = 0; i < ON_STACK_MATCHERS; i++)
2012     {
2013       if (matcher->sub_matchers[i].id == 0)
2014         return FALSE;
2015       
2016       if (matcher->sub_matchers[i].id == (id & matcher->sub_matchers[i].mask))
2017         return TRUE;
2018     }
2019
2020   if (matcher->more_sub_matchers)
2021     {
2022       sub_matchers = (SubMatcher *)matcher->more_sub_matchers->data;
2023       for (i = 0; i < matcher->more_sub_matchers->len; i++)
2024         {
2025           if (sub_matchers[i].id == (id & sub_matchers[i].mask))
2026             return TRUE;
2027         }
2028     }
2029   
2030   return FALSE;
2031 }
2032
2033 static gboolean
2034 g_file_attribute_matcher_matches_id (GFileAttributeMatcher *matcher,
2035                                      guint32                id)
2036 {
2037   /* We return a NULL matcher for an empty match string, so handle this */
2038   if (matcher == NULL)
2039     return FALSE;
2040   
2041   if (matcher->all)
2042     return TRUE;
2043   
2044   return matcher_matches_id (matcher, id);
2045 }
2046
2047 /**
2048  * g_file_attribute_matcher_matches:
2049  * @matcher: a #GFileAttributeMatcher.
2050  * @attribute: a file attribute key.
2051  *
2052  * Checks if an attribute will be matched by an attribute matcher. If 
2053  * the matcher was created with the "*" matching string, this function
2054  * will always return %TRUE.
2055  * 
2056  * Returns: %TRUE if @attribute matches @matcher. %FALSE otherwise.
2057  **/
2058 gboolean
2059 g_file_attribute_matcher_matches (GFileAttributeMatcher *matcher,
2060                                   const char            *attribute)
2061 {
2062   g_return_val_if_fail (attribute != NULL && *attribute != '\0', FALSE);
2063
2064   /* We return a NULL matcher for an empty match string, so handle this */
2065   if (matcher == NULL)
2066     return FALSE;
2067   
2068   if (matcher->all)
2069     return TRUE;
2070   
2071   return matcher_matches_id (matcher, lookup_attribute (attribute));
2072 }
2073
2074 /* return TRUE -> all */
2075 /**
2076  * g_file_attribute_matcher_enumerate_namespace:
2077  * @matcher: a #GFileAttributeMatcher.
2078  * @ns: a string containing a file attribute namespace.
2079  * 
2080  * Checks if the matcher will match all of the keys in a given namespace.
2081  * This will always return %TRUE if a wildcard character is in use (e.g. if 
2082  * matcher was created with "standard::*" and @ns is "standard", or if matcher was created
2083  * using "*" and namespace is anything.) 
2084  * 
2085  * TODO: this is awkwardly worded.
2086  * 
2087  * Returns: %TRUE if the matcher matches all of the entries
2088  * in the given @ns, %FALSE otherwise.
2089  **/
2090 gboolean
2091 g_file_attribute_matcher_enumerate_namespace (GFileAttributeMatcher *matcher,
2092                                               const char            *ns)
2093 {
2094   SubMatcher *sub_matchers;
2095   int ns_id;
2096   int i;
2097   
2098   g_return_val_if_fail (ns != NULL && *ns != '\0', FALSE);
2099
2100   /* We return a NULL matcher for an empty match string, so handle this */
2101   if (matcher == NULL)
2102     return FALSE;
2103   
2104   if (matcher->all)
2105     return TRUE;
2106
2107   ns_id = lookup_namespace (ns) << NS_POS;
2108
2109   for (i = 0; i < ON_STACK_MATCHERS; i++)
2110     {
2111       if (matcher->sub_matchers[i].id == ns_id)
2112         return TRUE;
2113     }
2114
2115   if (matcher->more_sub_matchers)
2116     {
2117       sub_matchers = (SubMatcher *)matcher->more_sub_matchers->data;
2118       for (i = 0; i < matcher->more_sub_matchers->len; i++)
2119         {
2120           if (sub_matchers[i].id == ns_id)
2121             return TRUE;
2122         }
2123     }
2124
2125   matcher->iterator_ns = ns_id;
2126   matcher->iterator_pos = 0;
2127   
2128   return FALSE;
2129 }
2130
2131 /**
2132  * g_file_attribute_matcher_enumerate_next:
2133  * @matcher: a #GFileAttributeMatcher.
2134  * 
2135  * Gets the next matched attribute from a #GFileAttributeMatcher.
2136  * 
2137  * Returns: a string containing the next attribute or %NULL if 
2138  * no more attribute exist.
2139  **/
2140 const char *
2141 g_file_attribute_matcher_enumerate_next (GFileAttributeMatcher *matcher)
2142 {
2143   int i;
2144   SubMatcher *sub_matcher;
2145
2146   /* We return a NULL matcher for an empty match string, so handle this */
2147   if (matcher == NULL)
2148     return NULL;
2149
2150   while (1)
2151     {
2152       i = matcher->iterator_pos++;
2153
2154       if (i < ON_STACK_MATCHERS)
2155         {
2156           if (matcher->sub_matchers[i].id == 0)
2157             return NULL;
2158
2159           sub_matcher = &matcher->sub_matchers[i];
2160         }
2161       else
2162         {
2163           if (matcher->more_sub_matchers == NULL)
2164             return NULL;
2165       
2166           i -= ON_STACK_MATCHERS;
2167           if (i < matcher->more_sub_matchers->len)
2168             sub_matcher = &g_array_index (matcher->more_sub_matchers, SubMatcher, i);
2169           else
2170             return NULL;
2171         }
2172
2173       if (sub_matcher->mask == 0xffffffff &&
2174           (sub_matcher->id & (NS_MASK << NS_POS)) == matcher->iterator_ns)
2175         return get_attribute_for_id (sub_matcher->id);
2176     }
2177 }
2178
2179 #define __G_FILE_INFO_C__
2180 #include "gioaliasdef.c"