Add new error codes for when compilation fails and make compilation error
[platform/upstream/glib.git] / gio / gcontenttype.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 #include <config.h>
24 #include <sys/types.h>
25 #include <dirent.h>
26 #include <string.h>
27 #include <stdio.h>
28 #include "gcontenttypeprivate.h"
29 #include "glibintl.h"
30
31 #include "gioalias.h"
32
33 /**
34  * SECTION:gcontenttype
35  * @short_description: Platform-specific content typing
36  *
37  * A content type is a platform specific string that defines the type
38  * of a file. On unix it is a mime type, on win32 it is an extension string
39  * like ".doc", ".txt" or a percieved string like "audio". Such strings
40  * can be looked up in the registry at HKEY_CLASSES_ROOT.
41  **/
42
43 #ifdef G_OS_WIN32
44
45 #include <windows.h>
46
47 static char *
48 get_registry_classes_key (const char    *subdir,
49                           const wchar_t *key_name)
50 {
51   wchar_t *wc_key;
52   HKEY reg_key = NULL;
53   DWORD key_type;
54   DWORD nbytes;
55   char *value_utf8;
56
57   value_utf8 = NULL;
58   
59   nbytes = 0;
60   wc_key = g_utf8_to_utf16 (subdir, -1, NULL, NULL, NULL);
61   if (RegOpenKeyExW (HKEY_CLASSES_ROOT, wc_key, 0,
62                      KEY_QUERY_VALUE, &reg_key) == ERROR_SUCCESS &&
63       RegQueryValueExW (reg_key, key_name, 0,
64                         &key_type, NULL, &nbytes) == ERROR_SUCCESS &&
65       key_type == REG_SZ)
66     {
67       wchar_t *wc_temp = g_new (wchar_t, (nbytes+1)/2 + 1);
68       RegQueryValueExW (reg_key, key_name, 0,
69                         &key_type, (LPBYTE) wc_temp, &nbytes);
70       wc_temp[nbytes/2] = '\0';
71       value_utf8 = g_utf16_to_utf8 (wc_temp, -1, NULL, NULL, NULL);
72       g_free (wc_temp);
73     }
74   g_free (wc_key);
75   
76   if (reg_key != NULL)
77     RegCloseKey (reg_key);
78
79   return value_utf8;
80 }
81
82 gboolean
83 g_content_type_equals (const char *type1,
84                        const char *type2)
85 {
86   char *progid1, *progid2;
87   gboolean res;
88   
89   g_return_val_if_fail (type1 != NULL, FALSE);
90   g_return_val_if_fail (type2 != NULL, FALSE);
91
92   if (g_ascii_strcasecmp (type1, type2) == 0)
93     return TRUE;
94
95   res = FALSE;
96   progid1 = get_registry_classes_key (type1, NULL);
97   progid2 = get_registry_classes_key (type2, NULL);
98   if (progid1 != NULL && progid2 != NULL &&
99       strcmp (progid1, progid2) == 0)
100     res = TRUE;
101   g_free (progid1);
102   g_free (progid2);
103   
104   return res;
105 }
106
107 gboolean
108 g_content_type_is_a (const char *type,
109                      const char *supertype)
110 {
111   gboolean res;
112   char *value_utf8;
113
114   g_return_val_if_fail (type != NULL, FALSE);
115   g_return_val_if_fail (supertype != NULL, FALSE);
116
117   if (g_content_type_equals (type, supertype))
118     return TRUE;
119
120   res = FALSE;
121   value_utf8 = get_registry_classes_key (type, L"PerceivedType");
122   if (value_utf8 && strcmp (value_utf8, supertype) == 0)
123     res = TRUE;
124   g_free (value_utf8);
125   
126   return res;
127 }
128
129 gboolean
130 g_content_type_is_unknown (const char *type)
131 {
132   g_return_val_if_fail (type != NULL, FALSE);
133
134   return strcmp ("*", type) == 0;
135 }
136
137 char *
138 g_content_type_get_description (const char *type)
139 {
140   char *progid;
141   char *description;
142
143   g_return_val_if_fail (type != NULL, NULL);
144
145   progid = get_registry_classes_key (type, NULL);
146   if (progid)
147     {
148       description = get_registry_classes_key (progid, NULL);
149       g_free (progid);
150
151       if (description)
152         return description;
153     }
154
155   if (g_content_type_is_unknown (type))
156     return g_strdup (_("Unknown type"));
157   return g_strdup_printf (_("%s filetype"), type);
158 }
159
160 char *
161 g_content_type_get_mime_type (const char *type)
162 {
163   char *mime;
164
165   g_return_val_if_fail (type != NULL, NULL);
166
167   mime = get_registry_classes_key (type, L"Content Type");
168   if (mime)
169     return mime;
170   else if (g_content_type_is_unknown (type))
171     return g_strdup ("application/octet-stream");
172   else if (*type == '.')
173     return g_strdup_printf ("application/x-ext-%s", type+1);
174   /* TODO: Map "image" to "image/ *", etc? */
175
176   return g_strdup ("application/octet-stream");
177 }
178
179 GIcon *
180 g_content_type_get_icon (const char *type)
181 {
182   g_return_val_if_fail (type != NULL, NULL);
183
184   /* TODO: How do we represent icons???
185      In the registry they are the default value of
186      HKEY_CLASSES_ROOT\<progid>\DefaultIcon with typical values like:
187      <type>: <value>
188      REG_EXPAND_SZ: %SystemRoot%\System32\Wscript.exe,3
189      REG_SZ: shimgvw.dll,3
190   */
191   return NULL;
192 }
193
194 gboolean
195 g_content_type_can_be_executable (const char *type)
196 {
197   g_return_val_if_fail (type != NULL, FALSE);
198
199   if (strcmp (type, ".exe") == 0 ||
200       strcmp (type, ".com") == 0 ||
201       strcmp (type, ".bat") == 0)
202     return TRUE;
203   return FALSE;
204 }
205
206 static gboolean
207 looks_like_text (const guchar *data, 
208                  gsize         data_size)
209 {
210   gsize i;
211   guchar c;
212   for (i = 0; i < data_size; i++)
213     {
214       c = data[i];
215       if (g_ascii_iscntrl (c) && !g_ascii_isspace (c))
216         return FALSE;
217     }
218   return TRUE;
219 }
220
221 char *
222 g_content_type_guess (const char   *filename,
223                       const guchar *data,
224                       gsize         data_size,
225                       gboolean     *result_uncertain)
226 {
227   char *basename;
228   char *type;
229   char *dot;
230
231   type = NULL;
232
233   if (filename)
234     {
235       basename = g_path_get_basename (filename);
236       dot = strrchr (basename, '.');
237       if (dot)
238         type = g_strdup (dot);
239       g_free (basename);
240     }
241
242   if (type)
243     return type;
244
245   if (data && looks_like_text (data, data_size))
246     return g_strdup (".txt");
247
248   return g_strdup ("*");
249 }
250
251 GList *
252 g_content_types_get_registered (void)
253 {
254   DWORD index;
255   wchar_t keyname[256];
256   DWORD key_len;
257   char *key_utf8;
258   GList *types;
259
260   types = NULL;
261   index = 0;
262   key_len = 256;
263   while (RegEnumKeyExW(HKEY_CLASSES_ROOT,
264                        index,
265                        keyname,
266                        &key_len,
267                        NULL,
268                        NULL,
269                        NULL,
270                        NULL) == ERROR_SUCCESS)
271     {
272       key_utf8 = g_utf16_to_utf8 (keyname, -1, NULL, NULL, NULL);
273       if (key_utf8)
274         {
275           if (*key_utf8 == '.')
276             types = g_list_prepend (types, key_utf8);
277           else
278             g_free (key_utf8);
279         }
280       index++;
281       key_len = 256;
282     }
283   
284   return g_list_reverse (types);
285 }
286
287 #else /* !G_OS_WIN32 - Unix specific version */
288
289 #define XDG_PREFIX _gio_xdg
290 #include "xdgmime/xdgmime.h"
291
292 /* We lock this mutex whenever we modify global state in this module.  */
293 G_LOCK_DEFINE_STATIC (gio_xdgmime);
294
295 gsize
296 _g_unix_content_type_get_sniff_len (void)
297 {
298   gsize size;
299
300   G_LOCK (gio_xdgmime);
301   size = xdg_mime_get_max_buffer_extents ();
302   G_UNLOCK (gio_xdgmime);
303
304   return size;
305 }
306
307 char *
308 _g_unix_content_type_unalias (const char *type)
309 {
310   char *res;
311   
312   G_LOCK (gio_xdgmime);
313   res = g_strdup (xdg_mime_unalias_mime_type (type));
314   G_UNLOCK (gio_xdgmime);
315   
316   return res;
317 }
318
319 char **
320 _g_unix_content_type_get_parents (const char *type)
321 {
322   const char *umime;
323   const char **parents;
324   GPtrArray *array;
325   int i;
326
327   array = g_ptr_array_new ();
328   
329   G_LOCK (gio_xdgmime);
330   
331   umime = xdg_mime_unalias_mime_type (type);
332   g_ptr_array_add (array, g_strdup (umime));
333   
334   parents = xdg_mime_get_mime_parents (umime);
335   for (i = 0; parents && parents[i] != NULL; i++)
336     g_ptr_array_add (array, g_strdup (parents[i]));
337   
338   G_UNLOCK (gio_xdgmime);
339   
340   g_ptr_array_add (array, NULL);
341   
342   return (char **)g_ptr_array_free (array, FALSE);
343 }
344
345 /**
346  * g_content_type_equals:
347  * @type1: a content type string.
348  * @type2: a content type string.
349  *
350  * Compares two content types for equality.
351  *
352  * Returns: %TRUE if the two strings are identical or equivalent,
353  * %FALSE otherwise.
354  **/  
355 gboolean
356 g_content_type_equals (const char *type1,
357                        const char *type2)
358 {
359   gboolean res;
360   
361   g_return_val_if_fail (type1 != NULL, FALSE);
362   g_return_val_if_fail (type2 != NULL, FALSE);
363   
364   G_LOCK (gio_xdgmime);
365   res = xdg_mime_mime_type_equal (type1, type2);
366   G_UNLOCK (gio_xdgmime);
367         
368   return res;
369 }
370
371 /**
372  * g_content_type_is_a:
373  * @type: a content type string. 
374  * @supertype: a string.
375  *
376  * Determines if @type is a subset of @supertype.  
377  *
378  * Returns: %TRUE if @type is a kind of @supertype,
379  * %FALSE otherwise. 
380  **/  
381 gboolean
382 g_content_type_is_a (const char *type,
383                      const char *supertype)
384 {
385   gboolean res;
386     
387   g_return_val_if_fail (type != NULL, FALSE);
388   g_return_val_if_fail (supertype != NULL, FALSE);
389   
390   G_LOCK (gio_xdgmime);
391   res = xdg_mime_mime_type_subclass (type, supertype);
392   G_UNLOCK (gio_xdgmime);
393         
394   return res;
395 }
396
397 /**
398  * g_content_type_is_unknown:
399  * @type: a content type string. 
400  * 
401  * Checks if the content type is known by GIO.
402  * 
403  * Returns: %TRUE if the type is unknown.
404  **/  
405 gboolean
406 g_content_type_is_unknown (const char *type)
407 {
408   g_return_val_if_fail (type != NULL, FALSE);
409
410   return strcmp (XDG_MIME_TYPE_UNKNOWN, type) == 0;
411 }
412
413
414 typedef enum {
415   MIME_TAG_TYPE_OTHER,
416   MIME_TAG_TYPE_COMMENT
417 } MimeTagType;
418
419 typedef struct {
420   int current_type;
421   int current_lang_level;
422   int comment_lang_level;
423   char *comment;
424 } MimeParser;
425
426
427 static int
428 language_level (const char *lang)
429 {
430   const char * const *lang_list;
431   int i;
432   
433   /* The returned list is sorted from most desirable to least
434      desirable and always contains the default locale "C". */
435   lang_list = g_get_language_names ();
436   
437   for (i = 0; lang_list[i]; i++)
438     if (strcmp (lang_list[i], lang) == 0)
439       return 1000-i;
440   
441   return 0;
442 }
443
444 static void
445 mime_info_start_element (GMarkupParseContext  *context,
446                          const gchar          *element_name,
447                          const gchar         **attribute_names,
448                          const gchar         **attribute_values,
449                          gpointer              user_data,
450                          GError              **error)
451 {
452   int i;
453   const char *lang;
454   MimeParser *parser = user_data;
455   
456   if (strcmp (element_name, "comment") == 0)
457     {
458       lang = "C";
459       for (i = 0; attribute_names[i]; i++)
460         if (strcmp (attribute_names[i], "xml:lang") == 0)
461           {
462             lang = attribute_values[i];
463             break;
464           }
465       
466       parser->current_lang_level = language_level (lang);
467       parser->current_type = MIME_TAG_TYPE_COMMENT;
468     }
469   else
470     parser->current_type = MIME_TAG_TYPE_OTHER;
471   
472 }
473
474 static void
475 mime_info_end_element (GMarkupParseContext  *context,
476                        const gchar          *element_name,
477                        gpointer              user_data,
478                        GError              **error)
479 {
480   MimeParser *parser = user_data;
481   
482   parser->current_type = MIME_TAG_TYPE_OTHER;
483 }
484
485 static void
486 mime_info_text (GMarkupParseContext  *context,
487                 const gchar          *text,
488                 gsize                 text_len,  
489                 gpointer              user_data,
490                 GError              **error)
491 {
492   MimeParser *parser = user_data;
493
494   if (parser->current_type == MIME_TAG_TYPE_COMMENT &&
495       parser->current_lang_level > parser->comment_lang_level)
496     {
497       g_free (parser->comment);
498       parser->comment = g_strndup (text, text_len);
499       parser->comment_lang_level = parser->current_lang_level;
500     }
501 }
502
503 static char *
504 load_comment_for_mime_helper (const char *dir, 
505                               const char *basename)
506 {
507   GMarkupParseContext *context;
508   char *filename, *data;
509   gsize len;
510   gboolean res;
511   MimeParser parse_data = {0};
512   GMarkupParser parser = {
513     mime_info_start_element,
514     mime_info_end_element,
515     mime_info_text
516   };
517
518   filename = g_build_filename (dir, "mime", basename, NULL);
519   
520   res = g_file_get_contents (filename,  &data,  &len,  NULL);
521   g_free (filename);
522   if (!res)
523     return NULL;
524   
525   context = g_markup_parse_context_new   (&parser, 0, &parse_data, NULL);
526   res = g_markup_parse_context_parse (context, data, len, NULL);
527   g_free (data);
528   g_markup_parse_context_free (context);
529   
530   if (!res)
531     return NULL;
532
533   return parse_data.comment;
534 }
535
536
537 static char *
538 load_comment_for_mime (const char *mimetype)
539 {
540   const char * const* dirs;
541   char *basename;
542   char *comment;
543   int i;
544
545   basename = g_strdup_printf ("%s.xml", mimetype);
546
547   comment = load_comment_for_mime_helper (g_get_user_data_dir (), basename);
548   if (comment)
549     {
550       g_free (basename);
551       return comment;
552     }
553   
554   dirs = g_get_system_data_dirs ();
555
556   for (i = 0; dirs[i] != NULL; i++)
557     {
558       comment = load_comment_for_mime_helper (dirs[i], basename);
559       if (comment)
560         {
561           g_free (basename);
562           return comment;
563         }
564     }
565   g_free (basename);
566   
567   return g_strdup_printf (_("%s type"), mimetype);
568 }
569
570 /**
571  * g_content_type_get_description:
572  * @type: a content type string. 
573  * 
574  * Gets the human readable description of the content type.
575  * 
576  * Returns: a short description of the content type @type. 
577  **/  
578 char *
579 g_content_type_get_description (const char *type)
580 {
581   static GHashTable *type_comment_cache = NULL;
582   char *comment;
583
584   g_return_val_if_fail (type != NULL, NULL);
585   
586   G_LOCK (gio_xdgmime);
587   if (type_comment_cache == NULL)
588     type_comment_cache = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free);
589
590   comment = g_hash_table_lookup (type_comment_cache, type);
591   comment = g_strdup (comment);
592   G_UNLOCK (gio_xdgmime);
593   
594   if (comment != NULL)
595     return comment;
596
597   comment = load_comment_for_mime (type);
598   
599   G_LOCK (gio_xdgmime);
600   g_hash_table_insert (type_comment_cache,
601                        g_strdup (type),
602                        g_strdup (comment));
603   G_UNLOCK (gio_xdgmime);
604
605   return comment;
606 }
607
608 /**
609  * g_content_type_get_mime_type:
610  * @type: a content type string. 
611  * 
612  * Gets the mime-type for the content type.
613  * 
614  * Returns: the registered mime-type for the given @type.
615  **/  
616 char *
617 g_content_type_get_mime_type (const char *type)
618 {
619   g_return_val_if_fail (type != NULL, NULL);
620
621   return g_strdup (type);
622 }
623
624 /**
625  * g_content_type_get_icon:
626  * @type: a content type string.
627  * 
628  * Gets the icon for a content type.
629  * 
630  * Returns: #GIcon corresponding to the content type.
631  **/  
632 GIcon *
633 g_content_type_get_icon (const char *type)
634 {
635   g_return_val_if_fail (type != NULL, NULL);
636
637   /* TODO: Implement */
638   return NULL;
639 }
640
641 /**
642  * g_content_type_can_be_executable:
643  * @type: a content type string.
644  * 
645  * Checks if a content type can be executable. Note that for instance
646  * things like text files can be executables (i.e. scripts and batch files).
647  * 
648  * Returns: %TRUE if the file type corresponds to a type that
649  * can be executable, %FALSE otherwise. 
650  **/  
651 gboolean
652 g_content_type_can_be_executable (const char *type)
653 {
654   g_return_val_if_fail (type != NULL, FALSE);
655
656   if (g_content_type_is_a (type, "application/x-executable")  ||
657       g_content_type_is_a (type, "text/plain"))
658     return TRUE;
659
660   return FALSE;
661 }
662
663 static gboolean
664 looks_like_text (const guchar *data, gsize data_size)
665 {
666   gsize i;
667   for (i = 0; i < data_size; i++)
668     {
669       if g_ascii_iscntrl (data[i])
670         return FALSE;
671     }
672   return TRUE;
673 }
674
675 /**
676  * g_content_type_guess:
677  * @filename: a string.
678  * @data: a stream of data.
679  * @data_size: the size of @data.
680  * @result_uncertain: a flag indicating the certainty of the 
681  * result.
682  * 
683  * Guesses the content type based on example data. If the function is 
684  * uncertain, @result_uncertain will be set to %TRUE.
685  * 
686  * Returns: a string indicating a guessed content type for the 
687  * given data. 
688  **/  
689 char *
690 g_content_type_guess (const char   *filename,
691                       const guchar *data,
692                       gsize         data_size,
693                       gboolean     *result_uncertain)
694 {
695   char *basename;
696   const char *name_mimetypes[10], *sniffed_mimetype;
697   char *mimetype;
698   int i;
699   int n_name_mimetypes;
700   int sniffed_prio;
701
702   sniffed_prio = 0;
703   n_name_mimetypes = 0;
704   sniffed_mimetype = XDG_MIME_TYPE_UNKNOWN;
705
706   if (result_uncertain)
707     *result_uncertain = FALSE;
708   
709   G_LOCK (gio_xdgmime);
710   
711   if (filename)
712     {
713       basename = g_path_get_basename (filename);
714       n_name_mimetypes = xdg_mime_get_mime_types_from_file_name (basename, name_mimetypes, 10);
715       g_free (basename);
716     }
717
718   /* Got an extension match, and no conflicts. This is it. */
719   if (n_name_mimetypes == 1)
720     {
721       G_UNLOCK (gio_xdgmime);
722       return g_strdup (name_mimetypes[0]);
723     }
724   
725   if (data)
726     {
727       sniffed_mimetype = xdg_mime_get_mime_type_for_data (data, data_size, &sniffed_prio);
728       if (sniffed_mimetype == XDG_MIME_TYPE_UNKNOWN &&
729           data &&
730           looks_like_text (data, data_size))
731         sniffed_mimetype = "text/plain";
732     }
733   
734   if (n_name_mimetypes == 0)
735     {
736       if (sniffed_mimetype == XDG_MIME_TYPE_UNKNOWN &&
737           result_uncertain)
738         *result_uncertain = TRUE;
739       
740       mimetype = g_strdup (sniffed_mimetype);
741     }
742   else
743     {
744       mimetype = NULL;
745       if (sniffed_mimetype != XDG_MIME_TYPE_UNKNOWN)
746         {
747           if (sniffed_prio >= 80) /* High priority sniffing match, use that */
748             mimetype = g_strdup (sniffed_mimetype);
749           else
750             {
751               /* There are conflicts between the name matches and we have a sniffed
752                  type, use that as a tie breaker. */
753               
754               for (i = 0; i < n_name_mimetypes; i++)
755                 {
756                   if ( xdg_mime_mime_type_subclass (name_mimetypes[i], sniffed_mimetype))
757                     {
758                       /* This nametype match is derived from (or the same as) the sniffed type).
759                          This is probably it. */
760                       mimetype = g_strdup (name_mimetypes[i]);
761                       break;
762                     }
763                 }
764             }
765         }
766       
767       if (mimetype == NULL)
768         {
769           /* Conflicts, and sniffed type was no help or not there. guess on the first one */
770           mimetype = g_strdup (name_mimetypes[0]);
771           if (result_uncertain)
772             *result_uncertain = TRUE;
773         }
774     }
775   
776   G_UNLOCK (gio_xdgmime);
777
778   return mimetype;
779 }
780
781 static gboolean
782 foreach_mimetype (gpointer key,
783                   gpointer value,
784                   gpointer user_data)
785 {
786   GList **l = user_data;
787
788   *l = g_list_prepend (*l, (char *)key);
789   return TRUE;
790 }
791
792 static void
793 enumerate_mimetypes_subdir (const char *dir, 
794                             const char *prefix, 
795                             GHashTable *mimetypes)
796 {
797   DIR *d;
798   struct dirent *ent;
799   char *mimetype;
800
801   d = opendir (dir);
802   if (d)
803     {
804       while ((ent = readdir (d)) != NULL)
805         {
806           if (g_str_has_suffix (ent->d_name, ".xml"))
807             {
808               mimetype = g_strdup_printf ("%s/%.*s", prefix, (int) strlen (ent->d_name) - 4, ent->d_name);
809               g_hash_table_insert (mimetypes, mimetype, NULL);
810             }
811         }
812       closedir (d);
813     }
814 }
815
816 static void
817 enumerate_mimetypes_dir (const char *dir, 
818                          GHashTable *mimetypes)
819 {
820   DIR *d;
821   struct dirent *ent;
822   char *mimedir;
823   char *name;
824
825   mimedir = g_build_filename (dir, "mime", NULL);
826   
827   d = opendir (mimedir);
828   if (d)
829     {
830       while ((ent = readdir (d)) != NULL)
831         {
832           if (strcmp (ent->d_name, "packages") != 0)
833             {
834               name = g_build_filename (mimedir, ent->d_name, NULL);
835               if (g_file_test (name, G_FILE_TEST_IS_DIR))
836                 enumerate_mimetypes_subdir (name, ent->d_name, mimetypes);
837               g_free (name);
838             }
839         }
840       closedir (d);
841     }
842   
843   g_free (mimedir);
844 }
845
846 /**
847  * g_content_types_get_registered:
848  * 
849  * Gets a list of strings containing the registered content types on 
850  * the system.
851  * 
852  * Returns: #GList of the registered content types.
853  **/  
854 GList *
855 g_content_types_get_registered (void)
856 {
857   const char * const* dirs;
858   GHashTable *mimetypes;
859   int i;
860   GList *l;
861
862   mimetypes = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL);
863
864   enumerate_mimetypes_dir (g_get_user_data_dir (), mimetypes);
865   dirs = g_get_system_data_dirs ();
866
867   for (i = 0; dirs[i] != NULL; i++)
868     enumerate_mimetypes_dir (dirs[i], mimetypes);
869
870   l = NULL;
871   g_hash_table_foreach_steal (mimetypes, foreach_mimetype, &l);
872   g_hash_table_destroy (mimetypes);
873
874   return l;
875 }
876
877 #endif /* Unix version */
878
879 #define __G_CONTENT_TYPE_C__
880 #include "gioaliasdef.c"