<HTML ><HEAD ><TITLE >gnome-mime</TITLE ><META NAME="GENERATOR" CONTENT="Modular DocBook HTML Stylesheet Version 1.74b"><LINK REL="HOME" TITLE="Gnome Library Reference Manual" HREF="book1.html"><LINK REL="UP" TITLE="Gnome Library" HREF="libgnome.html"><LINK REL="PREVIOUS" TITLE="gnome-mime-info" HREF="gnome-gnome-mime-info.html"><LINK REL="NEXT" TITLE="gnome-paper" HREF="gnome-gnome-paper.html"></HEAD ><BODY CLASS="REFENTRY" BGCOLOR="#FFFFFF" TEXT="#000000" LINK="#0000FF" VLINK="#840084" ALINK="#0000FF" ><DIV CLASS="NAVHEADER" ><TABLE WIDTH="100%" BORDER="0" BGCOLOR="#000000" CELLPADDING="1" CELLSPACING="0" ><TR ><TH COLSPAN="4" ALIGN="center" ><FONT COLOR="#FFFFFF" SIZE="5" >Gnome Library Reference Manual</FONT ></TH ></TR ><TR ><TD WIDTH="25%" BGCOLOR="#C00000" ALIGN="left" ><A HREF="gnome-gnome-mime-info.html" ><FONT COLOR="#FFFFFF" SIZE="3" ><B ><<< Previous Page</B ></FONT ></A ></TD ><TD WIDTH="25%" BGCOLOR="#0000C0" ALIGN="center" ><FONT COLOR="#FFFFFF" SIZE="3" ><B ><A HREF="book1.html" ><FONT COLOR="#FFFFFF" SIZE="3" ><B >Home</B ></FONT ></A ></B ></FONT ></TD ><TD WIDTH="25%" BGCOLOR="#00C000" ALIGN="center" ><FONT COLOR="#FFFFFF" SIZE="3" ><B ><A HREF="libgnome.html" ><FONT COLOR="#FFFFFF" SIZE="3" ><B >Up</B ></FONT ></A ></B ></FONT ></TD ><TD WIDTH="25%" BGCOLOR="#C00000" ALIGN="right" ><A HREF="gnome-gnome-paper.html" ><FONT COLOR="#FFFFFF" SIZE="3" ><B >Next Page >>></B ></FONT ></A ></TD ></TR ></TABLE ></DIV ><H1 ><A NAME="GNOME-GNOME-MIME" >gnome-mime</A ></H1 ><DIV CLASS="REFNAMEDIV" ><A NAME="AEN3102" ></A ><H2 >Name</H2 >gnome-mime -- Routines to determine the MIME type of a file</DIV ><DIV CLASS="REFSYNOPSISDIV" ><A NAME="AEN3105" ></A ><H2 >Synopsis</H2 ><TABLE BORDER="0" BGCOLOR="#D6E8FF" WIDTH="100%" CELLPADDING="6" ><TR ><TD ><PRE CLASS="SYNOPSIS" > #include <gnome.h> const char* <A HREF="gnome-gnome-mime.html#GNOME-MIME-TYPE" >gnome_mime_type</A > (const <GTKDOCLINK HREF="GCHAR" >gchar</GTKDOCLINK > *filename); const char* <A HREF="gnome-gnome-mime.html#GNOME-MIME-TYPE-OR-DEFAULT" >gnome_mime_type_or_default</A > (const <GTKDOCLINK HREF="GCHAR" >gchar</GTKDOCLINK > *filename, const <GTKDOCLINK HREF="GCHAR" >gchar</GTKDOCLINK > *defaultv); const char* <A HREF="gnome-gnome-mime.html#GNOME-MIME-TYPE-OF-FILE" >gnome_mime_type_of_file</A > (const char *existing_filename); const char* <A HREF="gnome-gnome-mime.html#GNOME-MIME-TYPE-OR-DEFAULT-OF-FILE" >gnome_mime_type_or_default_of_file</A > (const char *existing_filename, const <GTKDOCLINK HREF="GCHAR" >gchar</GTKDOCLINK > *defaultv); const char* <A HREF="gnome-gnome-mime.html#GNOME-MIME-TYPE-FROM-MAGIC" >gnome_mime_type_from_magic</A > (const <GTKDOCLINK HREF="GCHAR" >gchar</GTKDOCLINK > *filename); <GTKDOCLINK HREF="GLIST" >GList</GTKDOCLINK >* <A HREF="gnome-gnome-mime.html#GNOME-URI-LIST-EXTRACT-FILENAMES" >gnome_uri_list_extract_filenames</A > (const <GTKDOCLINK HREF="GCHAR" >gchar</GTKDOCLINK > *uri_list); <GTKDOCLINK HREF="GLIST" >GList</GTKDOCLINK >* <A HREF="gnome-gnome-mime.html#GNOME-URI-LIST-EXTRACT-URIS" >gnome_uri_list_extract_uris</A > (const <GTKDOCLINK HREF="GCHAR" >gchar</GTKDOCLINK > *uri_list); void <A HREF="gnome-gnome-mime.html#GNOME-URI-LIST-FREE-STRINGS" >gnome_uri_list_free_strings</A > (<GTKDOCLINK HREF="GLIST" >GList</GTKDOCLINK > *list);</PRE ></TD ></TR ></TABLE ></DIV ><DIV CLASS="REFSECT1" ><A NAME="AEN3126" ></A ><H2 >Description</H2 ><P >The routines in gnome-mime provide a way to obtain the MIME (Multipurpose Internet Mail Extension) type of a given file and some utility functions.</P ><P >There are two different methods for getting the MIME type of a particular file: Using only the filename to find the corresponding MIME type by matching the name against a database of known extensions and regular expressions; Or obtaining the MIME type by peeking at the contents of the file. Generally it should be faster using the former method, because the routines only do in-memory operations, while the latter method needs to do possibly time-expensive disk operations to obtain the necessary information.</P ><P >The routines that classify a file only by its name, look at the <TT CLASS="FILENAME" >*.mime</TT > files in the <TT CLASS="FILENAME" >$gnome_prefix/share/mime-info/</TT > directory and in <TT CLASS="FILENAME" >~/.gnome/mime-info/</TT > to build the extension database. This gives the user the possibility to extend and/or override the system defaults.</P ><P >Applications wanting to make additional MIME types available only need to install their files in one of these directories.</P ><P >The file <TT CLASS="FILENAME" >$gnome_prefix/share/mime-info/gnome.mime</TT > contains the defaults for Gnome and is read first. In addition, <TT CLASS="FILENAME" >~/.gnome/mime-info/user.mime</TT > is the last file to be read and thus makes it possible to set system-wide defaults and still gives the user a chance to override them. However, there is currently no determined order in which the other files in these directories will be read, nor is there any way to override system defaults, yet.</P ><P >The <A HREF="gnome-gnome-mime.html#GNOME-MIME-TYPE-FROM-MAGIC" >gnome_mime_type_from_magic</A >() function looks at the <TT CLASS="FILENAME" >$gnome_prefix/etc/mime-magic</TT > file to determine the MIME type of a given file (This database in usually kept in a pre-processed, easily readable format in <TT CLASS="FILENAME" >$gnome_prefix/etc/mime-magic.dat</TT >).</P ></DIV ><DIV CLASS="REFSECT1" ><A NAME="AEN3142" ></A ><H2 >Details</H2 ><DIV CLASS="REFSECT2" ><A NAME="AEN3144" ></A ><H3 ><A NAME="GNOME-MIME-TYPE" ></A >gnome_mime_type ()</H3 ><TABLE BORDER="0" BGCOLOR="#D6E8FF" WIDTH="100%" CELLPADDING="6" ><TR ><TD ><PRE CLASS="PROGRAMLISTING" >const char* gnome_mime_type (const <GTKDOCLINK HREF="GCHAR" >gchar</GTKDOCLINK > *filename);</PRE ></TD ></TR ></TABLE ><P >Determined the mime type for <TT CLASS="PARAMETER" ><I >filename</I ></TT >.</P ><P ></P ><DIV CLASS="INFORMALTABLE" ><A NAME="AEN3152" ></A ><P ></P ><TABLE BORDER="0" WIDTH="100%" BGCOLOR="#FFD0D0" CELLSPACING="0" CELLPADDING="4" CLASS="CALSTABLE" ><TBODY ><TR ><TD WIDTH="20%" ALIGN="RIGHT" VALIGN="TOP" ><TT CLASS="PARAMETER" ><I >filename</I ></TT > :</TD ><TD WIDTH="80%" ALIGN="LEFT" VALIGN="TOP" > A filename (the file does not necesarily exist).</TD ></TR ><TR ><TD WIDTH="20%" ALIGN="RIGHT" VALIGN="TOP" ><SPAN CLASS="emphasis" ><I CLASS="EMPHASIS" >Returns</I ></SPAN > :</TD ><TD WIDTH="80%" ALIGN="LEFT" VALIGN="TOP" >the mime-type for this filename.</TD ></TR ></TBODY ></TABLE ><P ></P ></DIV ></DIV ><HR><DIV CLASS="REFSECT2" ><A NAME="AEN3165" ></A ><H3 ><A NAME="GNOME-MIME-TYPE-OR-DEFAULT" ></A >gnome_mime_type_or_default ()</H3 ><TABLE BORDER="0" BGCOLOR="#D6E8FF" WIDTH="100%" CELLPADDING="6" ><TR ><TD ><PRE CLASS="PROGRAMLISTING" >const char* gnome_mime_type_or_default (const <GTKDOCLINK HREF="GCHAR" >gchar</GTKDOCLINK > *filename, const <GTKDOCLINK HREF="GCHAR" >gchar</GTKDOCLINK > *defaultv);</PRE ></TD ></TR ></TABLE ><P >This routine tries to determine the mime-type of the filename only by looking at the filename from the GNOME database of mime-types.</P ><P ></P ><DIV CLASS="INFORMALTABLE" ><A NAME="AEN3173" ></A ><P ></P ><TABLE BORDER="0" WIDTH="100%" BGCOLOR="#FFD0D0" CELLSPACING="0" CELLPADDING="4" CLASS="CALSTABLE" ><TBODY ><TR ><TD WIDTH="20%" ALIGN="RIGHT" VALIGN="TOP" ><TT CLASS="PARAMETER" ><I >filename</I ></TT > :</TD ><TD WIDTH="80%" ALIGN="LEFT" VALIGN="TOP" > A filename (the file does not necesarily exist).</TD ></TR ><TR ><TD WIDTH="20%" ALIGN="RIGHT" VALIGN="TOP" ><TT CLASS="PARAMETER" ><I >defaultv</I ></TT > :</TD ><TD WIDTH="80%" ALIGN="LEFT" VALIGN="TOP" > A default value to be returned if no match is found</TD ></TR ><TR ><TD WIDTH="20%" ALIGN="RIGHT" VALIGN="TOP" ><SPAN CLASS="emphasis" ><I CLASS="EMPHASIS" >Returns</I ></SPAN > :</TD ><TD WIDTH="80%" ALIGN="LEFT" VALIGN="TOP" >the mime-type of the <TT CLASS="PARAMETER" ><I >filename</I ></TT >. If no value could not be determined, it will return <TT CLASS="PARAMETER" ><I >defaultv</I ></TT >.</TD ></TR ></TBODY ></TABLE ><P ></P ></DIV ></DIV ><HR><DIV CLASS="REFSECT2" ><A NAME="AEN3192" ></A ><H3 ><A NAME="GNOME-MIME-TYPE-OF-FILE" ></A >gnome_mime_type_of_file ()</H3 ><TABLE BORDER="0" BGCOLOR="#D6E8FF" WIDTH="100%" CELLPADDING="6" ><TR ><TD ><PRE CLASS="PROGRAMLISTING" >const char* gnome_mime_type_of_file (const char *existing_filename);</PRE ></TD ></TR ></TABLE ><P >Determined the mime type for <TT CLASS="PARAMETER" ><I >existing_filename</I ></TT >. It will try to figure this out by looking at the contents of the file, if this fails it will use the filename to figure out a name.</P ><P ></P ><DIV CLASS="INFORMALTABLE" ><A NAME="AEN3199" ></A ><P ></P ><TABLE BORDER="0" WIDTH="100%" BGCOLOR="#FFD0D0" CELLSPACING="0" CELLPADDING="4" CLASS="CALSTABLE" ><TBODY ><TR ><TD WIDTH="20%" ALIGN="RIGHT" VALIGN="TOP" ><TT CLASS="PARAMETER" ><I >existing_filename</I ></TT > :</TD ><TD WIDTH="80%" ALIGN="LEFT" VALIGN="TOP" > A filename pointing to an existing file.</TD ></TR ><TR ><TD WIDTH="20%" ALIGN="RIGHT" VALIGN="TOP" ><SPAN CLASS="emphasis" ><I CLASS="EMPHASIS" >Returns</I ></SPAN > :</TD ><TD WIDTH="80%" ALIGN="LEFT" VALIGN="TOP" >the mime-type for this filename.</TD ></TR ></TBODY ></TABLE ><P ></P ></DIV ></DIV ><HR><DIV CLASS="REFSECT2" ><A NAME="AEN3212" ></A ><H3 ><A NAME="GNOME-MIME-TYPE-OR-DEFAULT-OF-FILE" ></A >gnome_mime_type_or_default_of_file ()</H3 ><TABLE BORDER="0" BGCOLOR="#D6E8FF" WIDTH="100%" CELLPADDING="6" ><TR ><TD ><PRE CLASS="PROGRAMLISTING" >const char* gnome_mime_type_or_default_of_file (const char *existing_filename, const <GTKDOCLINK HREF="GCHAR" >gchar</GTKDOCLINK > *defaultv);</PRE ></TD ></TR ></TABLE ><P >This routine tries to determine the mime-type of the filename by trying to guess the content of the file. If this fails, it will return the mime-type based only on the filename.</P ><P ></P ><DIV CLASS="INFORMALTABLE" ><A NAME="AEN3219" ></A ><P ></P ><TABLE BORDER="0" WIDTH="100%" BGCOLOR="#FFD0D0" CELLSPACING="0" CELLPADDING="4" CLASS="CALSTABLE" ><TBODY ><TR ><TD WIDTH="20%" ALIGN="RIGHT" VALIGN="TOP" ><TT CLASS="PARAMETER" ><I >existing_filename</I ></TT > :</TD ><TD WIDTH="80%" ALIGN="LEFT" VALIGN="TOP" > A filename that points to an existing filename.</TD ></TR ><TR ><TD WIDTH="20%" ALIGN="RIGHT" VALIGN="TOP" ><TT CLASS="PARAMETER" ><I >defaultv</I ></TT > :</TD ><TD WIDTH="80%" ALIGN="LEFT" VALIGN="TOP" > A default value to be returned if no match is found</TD ></TR ><TR ><TD WIDTH="20%" ALIGN="RIGHT" VALIGN="TOP" ><SPAN CLASS="emphasis" ><I CLASS="EMPHASIS" >Returns</I ></SPAN > :</TD ><TD WIDTH="80%" ALIGN="LEFT" VALIGN="TOP" >the mime-type of the <TT CLASS="PARAMETER" ><I >existing_filename</I ></TT >. If no value could not be determined, it will return <TT CLASS="PARAMETER" ><I >defaultv</I ></TT >.</TD ></TR ></TBODY ></TABLE ><P ></P ></DIV ></DIV ><HR><DIV CLASS="REFSECT2" ><A NAME="AEN3238" ></A ><H3 ><A NAME="GNOME-MIME-TYPE-FROM-MAGIC" ></A >gnome_mime_type_from_magic ()</H3 ><TABLE BORDER="0" BGCOLOR="#D6E8FF" WIDTH="100%" CELLPADDING="6" ><TR ><TD ><PRE CLASS="PROGRAMLISTING" >const char* gnome_mime_type_from_magic (const <GTKDOCLINK HREF="GCHAR" >gchar</GTKDOCLINK > *filename);</PRE ></TD ></TR ></TABLE ><P >This routine uses a magic database as described in magic(5) that maps files into their mime-type (so our modified magic database contains mime-types rather than textual descriptions of the files).</P ><P ></P ><DIV CLASS="INFORMALTABLE" ><A NAME="AEN3245" ></A ><P ></P ><TABLE BORDER="0" WIDTH="100%" BGCOLOR="#FFD0D0" CELLSPACING="0" CELLPADDING="4" CLASS="CALSTABLE" ><TBODY ><TR ><TD WIDTH="20%" ALIGN="RIGHT" VALIGN="TOP" ><TT CLASS="PARAMETER" ><I >filename</I ></TT > :</TD ><TD WIDTH="80%" ALIGN="LEFT" VALIGN="TOP" > an existing file name for which we want to guess the mime-type</TD ></TR ><TR ><TD WIDTH="20%" ALIGN="RIGHT" VALIGN="TOP" ><SPAN CLASS="emphasis" ><I CLASS="EMPHASIS" >Returns</I ></SPAN > :</TD ><TD WIDTH="80%" ALIGN="LEFT" VALIGN="TOP" >a pointer to an internal copy of the mime-type for <TT CLASS="PARAMETER" ><I >filename</I ></TT >.</TD ></TR ></TBODY ></TABLE ><P ></P ></DIV ></DIV ><HR><DIV CLASS="REFSECT2" ><A NAME="AEN3259" ></A ><H3 ><A NAME="GNOME-URI-LIST-EXTRACT-FILENAMES" ></A >gnome_uri_list_extract_filenames ()</H3 ><TABLE BORDER="0" BGCOLOR="#D6E8FF" WIDTH="100%" CELLPADDING="6" ><TR ><TD ><PRE CLASS="PROGRAMLISTING" ><GTKDOCLINK HREF="GLIST" >GList</GTKDOCLINK >* gnome_uri_list_extract_filenames (const <GTKDOCLINK HREF="GCHAR" >gchar</GTKDOCLINK > *uri_list);</PRE ></TD ></TR ></TABLE ><P ></P ><P ></P ><DIV CLASS="INFORMALTABLE" ><A NAME="AEN3267" ></A ><P ></P ><TABLE BORDER="0" WIDTH="100%" BGCOLOR="#FFD0D0" CELLSPACING="0" CELLPADDING="4" CLASS="CALSTABLE" ><TBODY ><TR ><TD WIDTH="20%" ALIGN="RIGHT" VALIGN="TOP" ><TT CLASS="PARAMETER" ><I >uri_list</I ></TT > :</TD ><TD WIDTH="80%" ALIGN="LEFT" VALIGN="TOP" > an uri-list in the standard format</TD ></TR ><TR ><TD WIDTH="20%" ALIGN="RIGHT" VALIGN="TOP" ><SPAN CLASS="emphasis" ><I CLASS="EMPHASIS" >Returns</I ></SPAN > :</TD ><TD WIDTH="80%" ALIGN="LEFT" VALIGN="TOP" >a GList containing strings allocated with g_malloc that contain the filenames in the uri-list. Note that unlike <A HREF="gnome-gnome-mime.html#GNOME-URI-LIST-EXTRACT-URIS" >gnome_uri_list_extract_uris</A >() function, this will discard any non-file uri from the result value.</TD ></TR ></TBODY ></TABLE ><P ></P ></DIV ></DIV ><HR><DIV CLASS="REFSECT2" ><A NAME="AEN3281" ></A ><H3 ><A NAME="GNOME-URI-LIST-EXTRACT-URIS" ></A >gnome_uri_list_extract_uris ()</H3 ><TABLE BORDER="0" BGCOLOR="#D6E8FF" WIDTH="100%" CELLPADDING="6" ><TR ><TD ><PRE CLASS="PROGRAMLISTING" ><GTKDOCLINK HREF="GLIST" >GList</GTKDOCLINK >* gnome_uri_list_extract_uris (const <GTKDOCLINK HREF="GCHAR" >gchar</GTKDOCLINK > *uri_list);</PRE ></TD ></TR ></TABLE ><P ></P ><P ></P ><DIV CLASS="INFORMALTABLE" ><A NAME="AEN3289" ></A ><P ></P ><TABLE BORDER="0" WIDTH="100%" BGCOLOR="#FFD0D0" CELLSPACING="0" CELLPADDING="4" CLASS="CALSTABLE" ><TBODY ><TR ><TD WIDTH="20%" ALIGN="RIGHT" VALIGN="TOP" ><TT CLASS="PARAMETER" ><I >uri_list</I ></TT > :</TD ><TD WIDTH="80%" ALIGN="LEFT" VALIGN="TOP" > an uri-list in the standard format.</TD ></TR ><TR ><TD WIDTH="20%" ALIGN="RIGHT" VALIGN="TOP" ><SPAN CLASS="emphasis" ><I CLASS="EMPHASIS" >Returns</I ></SPAN > :</TD ><TD WIDTH="80%" ALIGN="LEFT" VALIGN="TOP" >a GList containing strings allocated with g_malloc that have been splitted from <TT CLASS="PARAMETER" ><I >uri</I ></TT >-list.</TD ></TR ></TBODY ></TABLE ><P ></P ></DIV ></DIV ><HR><DIV CLASS="REFSECT2" ><A NAME="AEN3303" ></A ><H3 ><A NAME="GNOME-URI-LIST-FREE-STRINGS" ></A >gnome_uri_list_free_strings ()</H3 ><TABLE BORDER="0" BGCOLOR="#D6E8FF" WIDTH="100%" CELLPADDING="6" ><TR ><TD ><PRE CLASS="PROGRAMLISTING" >void gnome_uri_list_free_strings (<GTKDOCLINK HREF="GLIST" >GList</GTKDOCLINK > *list);</PRE ></TD ></TR ></TABLE ><P >Releases all of the resources allocated by <TT CLASS="PARAMETER" ><I >list</I ></TT >.</P ><P ></P ><DIV CLASS="INFORMALTABLE" ><A NAME="AEN3311" ></A ><P ></P ><TABLE BORDER="0" WIDTH="100%" BGCOLOR="#FFD0D0" CELLSPACING="0" CELLPADDING="4" CLASS="CALSTABLE" ><TBODY ><TR ><TD WIDTH="20%" ALIGN="RIGHT" VALIGN="TOP" ><TT CLASS="PARAMETER" ><I >list</I ></TT > :</TD ><TD WIDTH="80%" ALIGN="LEFT" VALIGN="TOP" > A GList returned by <A HREF="gnome-gnome-mime.html#GNOME-URI-LIST-EXTRACT-URIS" >gnome_uri_list_extract_uris</A >() or <A HREF="gnome-gnome-mime.html#GNOME-URI-LIST-EXTRACT-FILENAMES" >gnome_uri_list_extract_filenames</A >()</TD ></TR ></TBODY ></TABLE ><P ></P ></DIV ></DIV ></DIV ><DIV CLASS="NAVFOOTER" ><BR CLEAR="all"><BR><TABLE WIDTH="100%" BORDER="0" BGCOLOR="#000000" CELLPADDING="1" CELLSPACING="0" ><TR ><TD WIDTH="25%" BGCOLOR="#C00000" ALIGN="left" ><A HREF="gnome-gnome-mime-info.html" ><FONT COLOR="#FFFFFF" SIZE="3" ><B ><<< Previous Page</B ></FONT ></A ></TD ><TD WIDTH="25%" BGCOLOR="#0000C0" ALIGN="center" ><FONT COLOR="#FFFFFF" SIZE="3" ><B ><A HREF="book1.html" ><FONT COLOR="#FFFFFF" SIZE="3" ><B >Home</B ></FONT ></A ></B ></FONT ></TD ><TD WIDTH="25%" BGCOLOR="#00C000" ALIGN="center" ><FONT COLOR="#FFFFFF" SIZE="3" ><B ><A HREF="libgnome.html" ><FONT COLOR="#FFFFFF" SIZE="3" ><B >Up</B ></FONT ></A ></B ></FONT ></TD ><TD WIDTH="25%" BGCOLOR="#C00000" ALIGN="right" ><A HREF="gnome-gnome-paper.html" ><FONT COLOR="#FFFFFF" SIZE="3" ><B >Next Page >>></B ></FONT ></A ></TD ></TR ><TR ><TD COLSPAN="2" ALIGN="left" ><FONT COLOR="#FFFFFF" SIZE="3" ><B >gnome-mime-info</B ></FONT ></TD ><TD COLSPAN="2" ALIGN="right" ><FONT COLOR="#FFFFFF" SIZE="3" ><B >gnome-paper</B ></FONT ></TD ></TR ></TABLE ></DIV ></BODY ></HTML >