<refentry id="glib-Character-Set-Conversion">
<refmeta>
<refentrytitle role="top_of_page" id="glib-Character-Set-Conversion.top_of_page">Character Set Conversion</refentrytitle>
<manvolnum>3</manvolnum>
<refmiscinfo>GLIB Library</refmiscinfo>
</refmeta>

<refnamediv>
<refname>Character Set Conversion</refname>
<refpurpose>convert strings between different character sets using <link linkend="iconv"><function>iconv()</function></link></refpurpose>
</refnamediv>

<refsynopsisdiv id="glib-Character-Set-Conversion.synopsis" role="synopsis">
<title role="synopsis.title">Synopsis</title>

<synopsis>

#include &lt;glib.h&gt;

<link linkend="gchar">gchar</link>*              <link linkend="g-convert">g_convert</link>                           (const <link linkend="gchar">gchar</link> *str,
                                                         <link linkend="gssize">gssize</link> len,
                                                         const <link linkend="gchar">gchar</link> *to_codeset,
                                                         const <link linkend="gchar">gchar</link> *from_codeset,
                                                         <link linkend="gsize">gsize</link> *bytes_read,
                                                         <link linkend="gsize">gsize</link> *bytes_written,
                                                         <link linkend="GError">GError</link> **error);
<link linkend="gchar">gchar</link>*              <link linkend="g-convert-with-fallback">g_convert_with_fallback</link>             (const <link linkend="gchar">gchar</link> *str,
                                                         <link linkend="gssize">gssize</link> len,
                                                         const <link linkend="gchar">gchar</link> *to_codeset,
                                                         const <link linkend="gchar">gchar</link> *from_codeset,
                                                         <link linkend="gchar">gchar</link> *fallback,
                                                         <link linkend="gsize">gsize</link> *bytes_read,
                                                         <link linkend="gsize">gsize</link> *bytes_written,
                                                         <link linkend="GError">GError</link> **error);
                    <link linkend="GIConv">GIConv</link>;
<link linkend="gchar">gchar</link>*              <link linkend="g-convert-with-iconv">g_convert_with_iconv</link>                (const <link linkend="gchar">gchar</link> *str,
                                                         <link linkend="gssize">gssize</link> len,
                                                         <link linkend="GIConv">GIConv</link> converter,
                                                         <link linkend="gsize">gsize</link> *bytes_read,
                                                         <link linkend="gsize">gsize</link> *bytes_written,
                                                         <link linkend="GError">GError</link> **error);
#define             <link linkend="G-CONVERT-ERROR--CAPS">G_CONVERT_ERROR</link>
<link linkend="GIConv">GIConv</link>              <link linkend="g-iconv-open">g_iconv_open</link>                        (const <link linkend="gchar">gchar</link> *to_codeset,
                                                         const <link linkend="gchar">gchar</link> *from_codeset);
<link linkend="gsize">gsize</link>               <link linkend="g-iconv">g_iconv</link>                             (<link linkend="GIConv">GIConv</link> converter,
                                                         <link linkend="gchar">gchar</link> **inbuf,
                                                         <link linkend="gsize">gsize</link> *inbytes_left,
                                                         <link linkend="gchar">gchar</link> **outbuf,
                                                         <link linkend="gsize">gsize</link> *outbytes_left);
<link linkend="gint">gint</link>                <link linkend="g-iconv-close">g_iconv_close</link>                       (<link linkend="GIConv">GIConv</link> converter);
<link linkend="gchar">gchar</link>*              <link linkend="g-locale-to-utf8">g_locale_to_utf8</link>                    (const <link linkend="gchar">gchar</link> *opsysstring,
                                                         <link linkend="gssize">gssize</link> len,
                                                         <link linkend="gsize">gsize</link> *bytes_read,
                                                         <link linkend="gsize">gsize</link> *bytes_written,
                                                         <link linkend="GError">GError</link> **error);
<link linkend="gchar">gchar</link>*              <link linkend="g-filename-to-utf8">g_filename_to_utf8</link>                  (const <link linkend="gchar">gchar</link> *opsysstring,
                                                         <link linkend="gssize">gssize</link> len,
                                                         <link linkend="gsize">gsize</link> *bytes_read,
                                                         <link linkend="gsize">gsize</link> *bytes_written,
                                                         <link linkend="GError">GError</link> **error);
<link linkend="gchar">gchar</link>*              <link linkend="g-filename-from-utf8">g_filename_from_utf8</link>                (const <link linkend="gchar">gchar</link> *utf8string,
                                                         <link linkend="gssize">gssize</link> len,
                                                         <link linkend="gsize">gsize</link> *bytes_read,
                                                         <link linkend="gsize">gsize</link> *bytes_written,
                                                         <link linkend="GError">GError</link> **error);
<link linkend="gchar">gchar</link> *             <link linkend="g-filename-from-uri">g_filename_from_uri</link>                 (const <link linkend="gchar">gchar</link> *uri,
                                                         <link linkend="gchar">gchar</link> **hostname,
                                                         <link linkend="GError">GError</link> **error);
<link linkend="gchar">gchar</link> *             <link linkend="g-filename-to-uri">g_filename_to_uri</link>                   (const <link linkend="gchar">gchar</link> *filename,
                                                         const <link linkend="gchar">gchar</link> *hostname,
                                                         <link linkend="GError">GError</link> **error);
<link linkend="gboolean">gboolean</link>            <link linkend="g-get-filename-charsets">g_get_filename_charsets</link>             (G_CONST_RETURN <link linkend="gchar">gchar</link> ***charsets);
<link linkend="gchar">gchar</link> *             <link linkend="g-filename-display-name">g_filename_display_name</link>             (const <link linkend="gchar">gchar</link> *filename);
<link linkend="gchar">gchar</link> *             <link linkend="g-filename-display-basename">g_filename_display_basename</link>         (const <link linkend="gchar">gchar</link> *filename);
<link linkend="gchar">gchar</link>*              <link linkend="g-locale-from-utf8">g_locale_from_utf8</link>                  (const <link linkend="gchar">gchar</link> *utf8string,
                                                         <link linkend="gssize">gssize</link> len,
                                                         <link linkend="gsize">gsize</link> *bytes_read,
                                                         <link linkend="gsize">gsize</link> *bytes_written,
                                                         <link linkend="GError">GError</link> **error);
enum                <link linkend="GConvertError">GConvertError</link>;

<link linkend="gboolean">gboolean</link>            <link linkend="g-get-charset">g_get_charset</link>                       (G_CONST_RETURN <link linkend="char">char</link> **charset);
</synopsis>
</refsynopsisdiv>









<refsect1 id="glib-Character-Set-Conversion.description" role="desc">
<title role="desc.title">Description</title>
<para>
</para>
    <refsect2 id="file-name-encodings">
      <title>File Name Encodings</title>
      <para>
	Historically, Unix has not had a defined encoding for file
	names:  a file name is valid as long as it does not have path
	separators in it ("/").  However, displaying file names may
	require conversion:  from the character set in which they were
	created, to the character set in which the application
	operates.  Consider the Spanish file name
	"<filename>Presentaci&oacute;n.sxi</filename>".  If the
	application which created it uses ISO-8859-1 for its encoding,
	then the actual file name on disk would look like this:
      </para>
      <programlisting id="filename-iso8859-1">
Character:  P  r  e  s  e  n  t  a  c  i  &oacute;  n  .  s  x  i
Hex code:   50 72 65 73 65 6e 74 61 63 69 f3 6e 2e 73 78 69
      </programlisting>
      <para>
	However, if the application use UTF-8, the actual file name on
	disk would look like this:
      </para>
      <programlisting id="filename-utf-8">
Character:  P  r  e  s  e  n  t  a  c  i  &oacute;     n  .  s  x  i
Hex code:   50 72 65 73 65 6e 74 61 63 69 c3 b3 6e 2e 73 78 69
      </programlisting>
      <para>
	Glib uses UTF-8 for its strings, and GUI toolkits like GTK+
	that use Glib do the same thing.  If you get a file name from
	the file system, for example, from
	<function>readdir(3)</function> or from <link
	linkend="g_dir_read_name"><function><link linkend="g-dir-read-name"><function>g_dir_read_name()</function></link></function></link>,
	and you wish to display the file name to the user, you
	<emphasis>will</emphasis> need to convert it into UTF-8.  The
	opposite case is when the user types the name of a file he
	wishes to save:  the toolkit will give you that string in
	UTF-8 encoding, and you will need to convert it to the
	character set used for file names before you can create the
	file with <function>open(2)</function> or
	<function>fopen(3)</function>.
      </para>
      <para>
	By default, Glib assumes that file names on disk are in UTF-8
	encoding.  This is a valid assumption for file systems which
	were created relatively recently:  most applications use UTF-8
	encoding for their strings, and that is also what they use for
	the file names they create.  However, older file systems may
	still contain file names created in "older" encodings, such as
	ISO-8859-1.  In this case, for compatibility reasons, you may
	want to instruct Glib to use that particular encoding for file
	names rather than UTF-8.  You can do this by specifying the
	encoding for file names in the <link
	linkend="G_FILENAME_ENCODING"><envar>G_FILENAME_ENCODING</envar></link>
	environment variable.  For example, if your installation uses
	ISO-8859-1 for file names, you can put this in your
	<filename>~/.profile</filename>:
      </para>
      <programlisting>
export G_FILENAME_ENCODING=ISO-8859-1
      </programlisting>
      <para>
	Glib provides the functions <link
	linkend="g_filename_to_utf8"><function><link linkend="g-filename-to-utf8"><function>g_filename_to_utf8()</function></link></function></link>
	and <link
	linkend="g_filename_from_utf8"><function><link linkend="g-filename-from-utf8"><function>g_filename_from_utf8()</function></link></function></link>
	to perform the necessary conversions.  These functions convert
	file names from the encoding specified in
	<envar>G_FILENAME_ENCODING</envar> to UTF-8 and vice-versa.
	<xref linkend="file-name-encodings-diagram"/> illustrates how
	these functions are used to convert between UTF-8 and the
	encoding for file names in the file system.
      </para>
      <figure id="file-name-encodings-diagram">
	<title>Conversion between File Name Encodings</title>
	<graphic fileref="file-name-encodings.png" format="PNG"/>
      </figure>
      <refsect3 id="file-name-encodings-checklist">
	<title>Checklist for Application Writers</title>
	<para>
	  This section is a practical summary of the detailed
	  description above.  You can use this as a checklist of
	  things to do to make sure your applications process file
	  name encodings correctly.
	</para>
	<orderedlist>
	  <listitem>
	    <para>
	      If you get a file name from the file system from a
	      function such as <function>readdir(3)</function> or
	      <function><link linkend="gtk-file-chooser-get-filename"><function>gtk_file_chooser_get_filename()</function></link></function>,
	      you do not need to do any conversion to pass that
	      file name to functions like <function>open(2)</function>,
	      <function>rename(2)</function>, or
	      <function>fopen(3)</function> &mdash; those are "raw"
	      file names which the file system understands.
	    </para>
	  </listitem>
	  <listitem>
	    <para>
	      If you need to display a file name, convert it to UTF-8
	      first by using <link
	      linkend="g_filename_to_utf8"><function><link linkend="g-filename-to-utf8"><function>g_filename_to_utf8()</function></link></function></link>.
	      If conversion fails, display a string like
	      "<literal>Unknown file name</literal>".  <emphasis>Do
	      not</emphasis> convert this string back into the
	      encoding used for file names if you wish to pass it to
	      the file system; use the original file name instead.
	      For example, the document window of a word processor
	      could display "Unknown file name" in its title bar but
	      still let the user save the file, as it would keep the
	      raw file name internally.  This can happen if the user
	      has not set the <envar>G_FILENAME_ENCODING</envar>
	      environment variable even though he has files whose
	      names are not encoded in UTF-8.
	    </para>
	  </listitem>
	  <listitem>
	    <para>
	      If your user interface lets the user type a file name
	      for saving or renaming, convert it to the encoding used
	      for file names in the file system by using <link
	      linkend="g_filename_from_utf8"><function><link linkend="g-filename-from-utf8"><function>g_filename_from_utf8()</function></link></function></link>.
	      Pass the converted file name to functions like
	      <function>fopen(3)</function>.  If conversion fails, ask
	      the user to enter a different file name.  This can
	      happen if the user types Japanese characters when
	      <envar>G_FILENAME_ENCODING</envar> is set to
	      <literal>ISO-8859-1</literal>, for example.
	    </para>
	  </listitem>
	</orderedlist>
      </refsect3>
    </refsect2>
</refsect1>

<refsect1 id="glib-Character-Set-Conversion.details" role="details">
<title role="details.title">Details</title>
<refsect2 id="g-convert" role="function">
<title>g_convert ()</title>
<indexterm zone="g-convert"><primary sortas="convert">g_convert</primary></indexterm><programlisting><link linkend="gchar">gchar</link>*              g_convert                           (const <link linkend="gchar">gchar</link> *str,
                                                         <link linkend="gssize">gssize</link> len,
                                                         const <link linkend="gchar">gchar</link> *to_codeset,
                                                         const <link linkend="gchar">gchar</link> *from_codeset,
                                                         <link linkend="gsize">gsize</link> *bytes_read,
                                                         <link linkend="gsize">gsize</link> *bytes_written,
                                                         <link linkend="GError">GError</link> **error);</programlisting>
<para>
Converts a string from one character set to another.
</para>
<para>
Note that you should use <link linkend="g-iconv"><function>g_iconv()</function></link> for streaming 
conversions<footnoteref linkend="streaming-state"/>.</para>
<para>
</para><variablelist role="params">
<varlistentry><term><parameter>str</parameter>&#160;:</term>
<listitem><simpara>           the string to convert
</simpara></listitem></varlistentry>
<varlistentry><term><parameter>len</parameter>&#160;:</term>
<listitem><simpara>           the length of the string, or -1 if the string is 
                nul-terminated<footnote id="nul-unsafe">
                     <para>
                       Note that some encodings may allow nul bytes to 
                       occur inside strings. In that case, using -1 for 
                       the <parameter>len</parameter> parameter is unsafe.
                     </para>
                   </footnote>. 
</simpara></listitem></varlistentry>
<varlistentry><term><parameter>to_codeset</parameter>&#160;:</term>
<listitem><simpara>    name of character set into which to convert <parameter>str</parameter>
</simpara></listitem></varlistentry>
<varlistentry><term><parameter>from_codeset</parameter>&#160;:</term>
<listitem><simpara>  character set of <parameter>str</parameter>.
</simpara></listitem></varlistentry>
<varlistentry><term><parameter>bytes_read</parameter>&#160;:</term>
<listitem><simpara>    location to store the number of bytes in the
                input string that were successfully converted, or <link linkend="NULL--CAPS"><literal>NULL</literal></link>.
                Even if the conversion was successful, this may be 
                less than <parameter>len</parameter> if there were partial characters
                at the end of the input. If the error
                <link linkend="G-CONVERT-ERROR-ILLEGAL-SEQUENCE--CAPS"><type>G_CONVERT_ERROR_ILLEGAL_SEQUENCE</type></link> occurs, the value
                stored will the byte offset after the last valid
                input sequence.
</simpara></listitem></varlistentry>
<varlistentry><term><parameter>bytes_written</parameter>&#160;:</term>
<listitem><simpara> the number of bytes stored in the output buffer (not 
                including the terminating nul).
</simpara></listitem></varlistentry>
<varlistentry><term><parameter>error</parameter>&#160;:</term>
<listitem><simpara>         location to store the error occuring, or <link linkend="NULL--CAPS"><literal>NULL</literal></link> to ignore
                errors. Any of the errors in <link linkend="GConvertError"><type>GConvertError</type></link> may occur.
</simpara></listitem></varlistentry>
<varlistentry><term><emphasis>Returns</emphasis>&#160;:</term><listitem><simpara> If the conversion was successful, a newly allocated
              nul-terminated string, which must be freed with
              <link linkend="g-free"><function>g_free()</function></link>. Otherwise <link linkend="NULL--CAPS"><literal>NULL</literal></link> and <parameter>error</parameter> will be set.
</simpara></listitem></varlistentry>
</variablelist></refsect2>
<refsect2 id="g-convert-with-fallback" role="function">
<title>g_convert_with_fallback ()</title>
<indexterm zone="g-convert-with-fallback"><primary sortas="convert_with_fallback">g_convert_with_fallback</primary></indexterm><programlisting><link linkend="gchar">gchar</link>*              g_convert_with_fallback             (const <link linkend="gchar">gchar</link> *str,
                                                         <link linkend="gssize">gssize</link> len,
                                                         const <link linkend="gchar">gchar</link> *to_codeset,
                                                         const <link linkend="gchar">gchar</link> *from_codeset,
                                                         <link linkend="gchar">gchar</link> *fallback,
                                                         <link linkend="gsize">gsize</link> *bytes_read,
                                                         <link linkend="gsize">gsize</link> *bytes_written,
                                                         <link linkend="GError">GError</link> **error);</programlisting>
<para>
Converts a string from one character set to another, possibly
including fallback sequences for characters not representable
in the output. Note that it is not guaranteed that the specification
for the fallback sequences in <parameter>fallback</parameter> will be honored. Some
systems may do an approximate conversion from <parameter>from_codeset</parameter>
to <parameter>to_codeset</parameter> in their <link linkend="iconv"><function>iconv()</function></link> functions, 
in which case GLib will simply return that approximate conversion.
</para>
<para>
Note that you should use <link linkend="g-iconv"><function>g_iconv()</function></link> for streaming 
conversions<footnoteref linkend="streaming-state"/>.</para>
<para>
</para><variablelist role="params">
<varlistentry><term><parameter>str</parameter>&#160;:</term>
<listitem><simpara>          the string to convert
</simpara></listitem></varlistentry>
<varlistentry><term><parameter>len</parameter>&#160;:</term>
<listitem><simpara>          the length of the string, or -1 if the string is 
               nul-terminated<footnoteref linkend="nul-unsafe"/>. 
</simpara></listitem></varlistentry>
<varlistentry><term><parameter>to_codeset</parameter>&#160;:</term>
<listitem><simpara>   name of character set into which to convert <parameter>str</parameter>
</simpara></listitem></varlistentry>
<varlistentry><term><parameter>from_codeset</parameter>&#160;:</term>
<listitem><simpara> character set of <parameter>str</parameter>.
</simpara></listitem></varlistentry>
<varlistentry><term><parameter>fallback</parameter>&#160;:</term>
<listitem><simpara>     UTF-8 string to use in place of character not
               present in the target encoding. (The string must be
               representable in the target encoding). 
                  If <link linkend="NULL--CAPS"><literal>NULL</literal></link>, characters not in the target encoding will 
                  be represented as Unicode escapes \uxxxx or \Uxxxxyyyy.
</simpara></listitem></varlistentry>
<varlistentry><term><parameter>bytes_read</parameter>&#160;:</term>
<listitem><simpara>   location to store the number of bytes in the
               input string that were successfully converted, or <link linkend="NULL--CAPS"><literal>NULL</literal></link>.
               Even if the conversion was successful, this may be 
               less than <parameter>len</parameter> if there were partial characters
               at the end of the input.
</simpara></listitem></varlistentry>
<varlistentry><term><parameter>bytes_written</parameter>&#160;:</term>
<listitem><simpara> the number of bytes stored in the output buffer (not 
               including the terminating nul).
</simpara></listitem></varlistentry>
<varlistentry><term><parameter>error</parameter>&#160;:</term>
<listitem><simpara>        location to store the error occuring, or <link linkend="NULL--CAPS"><literal>NULL</literal></link> to ignore
               errors. Any of the errors in <link linkend="GConvertError"><type>GConvertError</type></link> may occur.
</simpara></listitem></varlistentry>
<varlistentry><term><emphasis>Returns</emphasis>&#160;:</term><listitem><simpara> If the conversion was successful, a newly allocated
              nul-terminated string, which must be freed with
              <link linkend="g-free"><function>g_free()</function></link>. Otherwise <link linkend="NULL--CAPS"><literal>NULL</literal></link> and <parameter>error</parameter> will be set.
</simpara></listitem></varlistentry>
</variablelist></refsect2>
<refsect2 id="GIConv" role="struct">
<title>GIConv</title>
<indexterm zone="GIConv"><primary sortas="IConv">GIConv</primary></indexterm><programlisting>typedef struct _GIConv GIConv;</programlisting>
<para>
The <structname>GIConv</structname> struct wraps an
<function><link linkend="iconv"><function>iconv()</function></link></function> conversion descriptor. It contains private data
and should only be accessed using the following functions.
</para></refsect2>
<refsect2 id="g-convert-with-iconv" role="function">
<title>g_convert_with_iconv ()</title>
<indexterm zone="g-convert-with-iconv"><primary sortas="convert_with_iconv">g_convert_with_iconv</primary></indexterm><programlisting><link linkend="gchar">gchar</link>*              g_convert_with_iconv                (const <link linkend="gchar">gchar</link> *str,
                                                         <link linkend="gssize">gssize</link> len,
                                                         <link linkend="GIConv">GIConv</link> converter,
                                                         <link linkend="gsize">gsize</link> *bytes_read,
                                                         <link linkend="gsize">gsize</link> *bytes_written,
                                                         <link linkend="GError">GError</link> **error);</programlisting>
<para>
Converts a string from one character set to another. 
</para>
<para>
Note that you should use <link linkend="g-iconv"><function>g_iconv()</function></link> for streaming 
conversions<footnote id="streaming-state">
 <para>
Despite the fact that <parameter>byes_read</parameter> can return information about partial 
characters, the <literal>g_convert_...</literal> functions
are not generally suitable for streaming. If the underlying converter 
being used maintains internal state, then this won't be preserved 
across successive calls to <link linkend="g-convert"><function>g_convert()</function></link>, <link linkend="g-convert-with-iconv"><function>g_convert_with_iconv()</function></link> or 
<link linkend="g-convert-with-fallback"><function>g_convert_with_fallback()</function></link>. (An example of this is the GNU C converter 
for CP1255 which does not emit a base character until it knows that 
the next character is not a mark that could combine with the base 
character.)
 </para>
</footnote>.</para>
<para>
</para><variablelist role="params">
<varlistentry><term><parameter>str</parameter>&#160;:</term>
<listitem><simpara>           the string to convert
</simpara></listitem></varlistentry>
<varlistentry><term><parameter>len</parameter>&#160;:</term>
<listitem><simpara>           the length of the string, or -1 if the string is 
                nul-terminated<footnoteref linkend="nul-unsafe"/>. 
</simpara></listitem></varlistentry>
<varlistentry><term><parameter>converter</parameter>&#160;:</term>
<listitem><simpara>     conversion descriptor from <link linkend="g-iconv-open"><function>g_iconv_open()</function></link>
</simpara></listitem></varlistentry>
<varlistentry><term><parameter>bytes_read</parameter>&#160;:</term>
<listitem><simpara>    location to store the number of bytes in the
                input string that were successfully converted, or <link linkend="NULL--CAPS"><literal>NULL</literal></link>.
                Even if the conversion was successful, this may be 
                less than <parameter>len</parameter> if there were partial characters
                at the end of the input. If the error
                <link linkend="G-CONVERT-ERROR-ILLEGAL-SEQUENCE--CAPS"><type>G_CONVERT_ERROR_ILLEGAL_SEQUENCE</type></link> occurs, the value
                stored will the byte offset after the last valid
                input sequence.
</simpara></listitem></varlistentry>
<varlistentry><term><parameter>bytes_written</parameter>&#160;:</term>
<listitem><simpara> the number of bytes stored in the output buffer (not 
                including the terminating nul).
</simpara></listitem></varlistentry>
<varlistentry><term><parameter>error</parameter>&#160;:</term>
<listitem><simpara>         location to store the error occuring, or <link linkend="NULL--CAPS"><literal>NULL</literal></link> to ignore
                errors. Any of the errors in <link linkend="GConvertError"><type>GConvertError</type></link> may occur.
</simpara></listitem></varlistentry>
<varlistentry><term><emphasis>Returns</emphasis>&#160;:</term><listitem><simpara> If the conversion was successful, a newly allocated
              nul-terminated string, which must be freed with
              <link linkend="g-free"><function>g_free()</function></link>. Otherwise <link linkend="NULL--CAPS"><literal>NULL</literal></link> and <parameter>error</parameter> will be set.
</simpara></listitem></varlistentry>
</variablelist></refsect2>
<refsect2 id="G-CONVERT-ERROR--CAPS" role="macro">
<title>G_CONVERT_ERROR</title>
<indexterm zone="G-CONVERT-ERROR--CAPS"><primary sortas="CONVERT_ERROR">G_CONVERT_ERROR</primary></indexterm><programlisting>#define G_CONVERT_ERROR g_convert_error_quark()
</programlisting>
<para>
Error domain for character set conversions. Errors in this domain will
be from the <link linkend="GConvertError"><type>GConvertError</type></link> enumeration. See <link linkend="GError"><type>GError</type></link> for information on
error domains.
</para></refsect2>
<refsect2 id="g-iconv-open" role="function">
<title>g_iconv_open ()</title>
<indexterm zone="g-iconv-open"><primary sortas="iconv_open">g_iconv_open</primary></indexterm><programlisting><link linkend="GIConv">GIConv</link>              g_iconv_open                        (const <link linkend="gchar">gchar</link> *to_codeset,
                                                         const <link linkend="gchar">gchar</link> *from_codeset);</programlisting>
<para>
Same as the standard UNIX routine <link linkend="iconv-open"><function>iconv_open()</function></link>, but
may be implemented via libiconv on UNIX flavors that lack
a native implementation.
</para>
<para>
GLib provides <link linkend="g-convert"><function>g_convert()</function></link> and <link linkend="g-locale-to-utf8"><function>g_locale_to_utf8()</function></link> which are likely
more convenient than the raw iconv wrappers.</para>
<para>
</para><variablelist role="params">
<varlistentry><term><parameter>to_codeset</parameter>&#160;:</term>
<listitem><simpara> destination codeset
</simpara></listitem></varlistentry>
<varlistentry><term><parameter>from_codeset</parameter>&#160;:</term>
<listitem><simpara> source codeset
</simpara></listitem></varlistentry>
<varlistentry><term><emphasis>Returns</emphasis>&#160;:</term><listitem><simpara> a "conversion descriptor", or (GIConv)-1 if
 opening the converter failed.
</simpara></listitem></varlistentry>
</variablelist></refsect2>
<refsect2 id="g-iconv" role="function">
<title>g_iconv ()</title>
<indexterm zone="g-iconv"><primary sortas="iconv">g_iconv</primary></indexterm><programlisting><link linkend="gsize">gsize</link>               g_iconv                             (<link linkend="GIConv">GIConv</link> converter,
                                                         <link linkend="gchar">gchar</link> **inbuf,
                                                         <link linkend="gsize">gsize</link> *inbytes_left,
                                                         <link linkend="gchar">gchar</link> **outbuf,
                                                         <link linkend="gsize">gsize</link> *outbytes_left);</programlisting>
<para>
Same as the standard UNIX routine <link linkend="iconv"><function>iconv()</function></link>, but
may be implemented via libiconv on UNIX flavors that lack
a native implementation.
</para>
<para>
GLib provides <link linkend="g-convert"><function>g_convert()</function></link> and <link linkend="g-locale-to-utf8"><function>g_locale_to_utf8()</function></link> which are likely
more convenient than the raw iconv wrappers.</para>
<para>
</para><variablelist role="params">
<varlistentry><term><parameter>converter</parameter>&#160;:</term>
<listitem><simpara> conversion descriptor from <link linkend="g-iconv-open"><function>g_iconv_open()</function></link>
</simpara></listitem></varlistentry>
<varlistentry><term><parameter>inbuf</parameter>&#160;:</term>
<listitem><simpara> bytes to convert
</simpara></listitem></varlistentry>
<varlistentry><term><parameter>inbytes_left</parameter>&#160;:</term>
<listitem><simpara> inout parameter, bytes remaining to convert in <parameter>inbuf</parameter>
</simpara></listitem></varlistentry>
<varlistentry><term><parameter>outbuf</parameter>&#160;:</term>
<listitem><simpara> converted output bytes
</simpara></listitem></varlistentry>
<varlistentry><term><parameter>outbytes_left</parameter>&#160;:</term>
<listitem><simpara> inout parameter, bytes available to fill in <parameter>outbuf</parameter>
</simpara></listitem></varlistentry>
<varlistentry><term><emphasis>Returns</emphasis>&#160;:</term><listitem><simpara> count of non-reversible conversions, or -1 on error
</simpara></listitem></varlistentry>
</variablelist></refsect2>
<refsect2 id="g-iconv-close" role="function">
<title>g_iconv_close ()</title>
<indexterm zone="g-iconv-close"><primary sortas="iconv_close">g_iconv_close</primary></indexterm><programlisting><link linkend="gint">gint</link>                g_iconv_close                       (<link linkend="GIConv">GIConv</link> converter);</programlisting>
<para>
Same as the standard UNIX routine <link linkend="iconv-close"><function>iconv_close()</function></link>, but
may be implemented via libiconv on UNIX flavors that lack
a native implementation. Should be called to clean up
the conversion descriptor from <link linkend="g-iconv-open"><function>g_iconv_open()</function></link> when
you are done converting things.
</para>
<para>
GLib provides <link linkend="g-convert"><function>g_convert()</function></link> and <link linkend="g-locale-to-utf8"><function>g_locale_to_utf8()</function></link> which are likely
more convenient than the raw iconv wrappers.</para>
<para>
</para><variablelist role="params">
<varlistentry><term><parameter>converter</parameter>&#160;:</term>
<listitem><simpara> a conversion descriptor from <link linkend="g-iconv-open"><function>g_iconv_open()</function></link>
</simpara></listitem></varlistentry>
<varlistentry><term><emphasis>Returns</emphasis>&#160;:</term><listitem><simpara> -1 on error, 0 on success
</simpara></listitem></varlistentry>
</variablelist></refsect2>
<refsect2 id="g-locale-to-utf8" role="function">
<title>g_locale_to_utf8 ()</title>
<indexterm zone="g-locale-to-utf8"><primary sortas="locale_to_utf8">g_locale_to_utf8</primary></indexterm><programlisting><link linkend="gchar">gchar</link>*              g_locale_to_utf8                    (const <link linkend="gchar">gchar</link> *opsysstring,
                                                         <link linkend="gssize">gssize</link> len,
                                                         <link linkend="gsize">gsize</link> *bytes_read,
                                                         <link linkend="gsize">gsize</link> *bytes_written,
                                                         <link linkend="GError">GError</link> **error);</programlisting>
<para>
Converts a string which is in the encoding used for strings by
the C runtime (usually the same as that used by the operating
system) in the <link linkend="setlocale">current locale</link> into a
UTF-8 string.</para>
<para>
</para><variablelist role="params">
<varlistentry><term><parameter>opsysstring</parameter>&#160;:</term>
<listitem><simpara>   a string in the encoding of the current locale. On Windows
                this means the system codepage.
</simpara></listitem></varlistentry>
<varlistentry><term><parameter>len</parameter>&#160;:</term>
<listitem><simpara>           the length of the string, or -1 if the string is
                nul-terminated<footnoteref linkend="nul-unsafe"/>. 
</simpara></listitem></varlistentry>
<varlistentry><term><parameter>bytes_read</parameter>&#160;:</term>
<listitem><simpara>    location to store the number of bytes in the
                input string that were successfully converted, or <link linkend="NULL--CAPS"><literal>NULL</literal></link>.
                Even if the conversion was successful, this may be 
                less than <parameter>len</parameter> if there were partial characters
                at the end of the input. If the error
                <link linkend="G-CONVERT-ERROR-ILLEGAL-SEQUENCE--CAPS"><type>G_CONVERT_ERROR_ILLEGAL_SEQUENCE</type></link> occurs, the value
                stored will the byte offset after the last valid
                input sequence.
</simpara></listitem></varlistentry>
<varlistentry><term><parameter>bytes_written</parameter>&#160;:</term>
<listitem><simpara> the number of bytes stored in the output buffer (not 
                including the terminating nul).
</simpara></listitem></varlistentry>
<varlistentry><term><parameter>error</parameter>&#160;:</term>
<listitem><simpara>         location to store the error occuring, or <link linkend="NULL--CAPS"><literal>NULL</literal></link> to ignore
                errors. Any of the errors in <link linkend="GConvertError"><type>GConvertError</type></link> may occur.
</simpara></listitem></varlistentry>
<varlistentry><term><emphasis>Returns</emphasis>&#160;:</term><listitem><simpara> The converted string, or <link linkend="NULL--CAPS"><literal>NULL</literal></link> on an error.
</simpara></listitem></varlistentry>
</variablelist></refsect2>
<refsect2 id="g-filename-to-utf8" role="function">
<title>g_filename_to_utf8 ()</title>
<indexterm zone="g-filename-to-utf8"><primary sortas="filename_to_utf8">g_filename_to_utf8</primary></indexterm><programlisting><link linkend="gchar">gchar</link>*              g_filename_to_utf8                  (const <link linkend="gchar">gchar</link> *opsysstring,
                                                         <link linkend="gssize">gssize</link> len,
                                                         <link linkend="gsize">gsize</link> *bytes_read,
                                                         <link linkend="gsize">gsize</link> *bytes_written,
                                                         <link linkend="GError">GError</link> **error);</programlisting>
<para>
Converts a string which is in the encoding used by GLib for
filenames into a UTF-8 string. Note that on Windows GLib uses UTF-8
for filenames; on other platforms, this function indirectly depends on 
the <link linkend="setlocale">current locale</link>.</para>
<para>
</para><variablelist role="params">
<varlistentry><term><parameter>opsysstring</parameter>&#160;:</term>
<listitem><simpara>   a string in the encoding for filenames
</simpara></listitem></varlistentry>
<varlistentry><term><parameter>len</parameter>&#160;:</term>
<listitem><simpara>           the length of the string, or -1 if the string is
                nul-terminated<footnoteref linkend="nul-unsafe"/>. 
</simpara></listitem></varlistentry>
<varlistentry><term><parameter>bytes_read</parameter>&#160;:</term>
<listitem><simpara>    location to store the number of bytes in the
                input string that were successfully converted, or <link linkend="NULL--CAPS"><literal>NULL</literal></link>.
                Even if the conversion was successful, this may be 
                less than <parameter>len</parameter> if there were partial characters
                at the end of the input. If the error
                <link linkend="G-CONVERT-ERROR-ILLEGAL-SEQUENCE--CAPS"><type>G_CONVERT_ERROR_ILLEGAL_SEQUENCE</type></link> occurs, the value
                stored will the byte offset after the last valid
                input sequence.
</simpara></listitem></varlistentry>
<varlistentry><term><parameter>bytes_written</parameter>&#160;:</term>
<listitem><simpara> the number of bytes stored in the output buffer (not 
                including the terminating nul).
</simpara></listitem></varlistentry>
<varlistentry><term><parameter>error</parameter>&#160;:</term>
<listitem><simpara>         location to store the error occuring, or <link linkend="NULL--CAPS"><literal>NULL</literal></link> to ignore
                errors. Any of the errors in <link linkend="GConvertError"><type>GConvertError</type></link> may occur.
</simpara></listitem></varlistentry>
<varlistentry><term><emphasis>Returns</emphasis>&#160;:</term><listitem><simpara> The converted string, or <link linkend="NULL--CAPS"><literal>NULL</literal></link> on an error.
</simpara></listitem></varlistentry>
</variablelist></refsect2>
<refsect2 id="g-filename-from-utf8" role="function">
<title>g_filename_from_utf8 ()</title>
<indexterm zone="g-filename-from-utf8"><primary sortas="filename_from_utf8">g_filename_from_utf8</primary></indexterm><programlisting><link linkend="gchar">gchar</link>*              g_filename_from_utf8                (const <link linkend="gchar">gchar</link> *utf8string,
                                                         <link linkend="gssize">gssize</link> len,
                                                         <link linkend="gsize">gsize</link> *bytes_read,
                                                         <link linkend="gsize">gsize</link> *bytes_written,
                                                         <link linkend="GError">GError</link> **error);</programlisting>
<para>
Converts a string from UTF-8 to the encoding GLib uses for
filenames. Note that on Windows GLib uses UTF-8 for filenames;
on other platforms, this function indirectly depends on the 
<link linkend="setlocale">current locale</link>.</para>
<para>
</para><variablelist role="params">
<varlistentry><term><parameter>utf8string</parameter>&#160;:</term>
<listitem><simpara>    a UTF-8 encoded string.
</simpara></listitem></varlistentry>
<varlistentry><term><parameter>len</parameter>&#160;:</term>
<listitem><simpara>           the length of the string, or -1 if the string is
                nul-terminated.
</simpara></listitem></varlistentry>
<varlistentry><term><parameter>bytes_read</parameter>&#160;:</term>
<listitem><simpara>    location to store the number of bytes in the
                input string that were successfully converted, or <link linkend="NULL--CAPS"><literal>NULL</literal></link>.
                Even if the conversion was successful, this may be 
                less than <parameter>len</parameter> if there were partial characters
                at the end of the input. If the error
                <link linkend="G-CONVERT-ERROR-ILLEGAL-SEQUENCE--CAPS"><type>G_CONVERT_ERROR_ILLEGAL_SEQUENCE</type></link> occurs, the value
                stored will the byte offset after the last valid
                input sequence.
</simpara></listitem></varlistentry>
<varlistentry><term><parameter>bytes_written</parameter>&#160;:</term>
<listitem><simpara> the number of bytes stored in the output buffer (not 
                including the terminating nul).
</simpara></listitem></varlistentry>
<varlistentry><term><parameter>error</parameter>&#160;:</term>
<listitem><simpara>         location to store the error occuring, or <link linkend="NULL--CAPS"><literal>NULL</literal></link> to ignore
                errors. Any of the errors in <link linkend="GConvertError"><type>GConvertError</type></link> may occur.
</simpara></listitem></varlistentry>
<varlistentry><term><emphasis>Returns</emphasis>&#160;:</term><listitem><simpara> The converted string, or <link linkend="NULL--CAPS"><literal>NULL</literal></link> on an error.
</simpara></listitem></varlistentry>
</variablelist></refsect2>
<refsect2 id="g-filename-from-uri" role="function">
<title>g_filename_from_uri ()</title>
<indexterm zone="g-filename-from-uri"><primary sortas="filename_from_uri">g_filename_from_uri</primary></indexterm><programlisting><link linkend="gchar">gchar</link> *             g_filename_from_uri                 (const <link linkend="gchar">gchar</link> *uri,
                                                         <link linkend="gchar">gchar</link> **hostname,
                                                         <link linkend="GError">GError</link> **error);</programlisting>
<para>
Converts an escaped ASCII-encoded URI to a local filename in the
encoding used for filenames.</para>
<para>
</para><variablelist role="params">
<varlistentry><term><parameter>uri</parameter>&#160;:</term>
<listitem><simpara> a uri describing a filename (escaped, encoded in ASCII).
</simpara></listitem></varlistentry>
<varlistentry><term><parameter>hostname</parameter>&#160;:</term>
<listitem><simpara> Location to store hostname for the URI, or <link linkend="NULL--CAPS"><literal>NULL</literal></link>.
           If there is no hostname in the URI, <link linkend="NULL--CAPS"><literal>NULL</literal></link> will be
           stored in this location.
</simpara></listitem></varlistentry>
<varlistentry><term><parameter>error</parameter>&#160;:</term>
<listitem><simpara> location to store the error occuring, or <link linkend="NULL--CAPS"><literal>NULL</literal></link> to ignore
        errors. Any of the errors in <link linkend="GConvertError"><type>GConvertError</type></link> may occur.
</simpara></listitem></varlistentry>
<varlistentry><term><emphasis>Returns</emphasis>&#160;:</term><listitem><simpara> a newly-allocated string holding the resulting
              filename, or <link linkend="NULL--CAPS"><literal>NULL</literal></link> on an error.
</simpara></listitem></varlistentry>
</variablelist></refsect2>
<refsect2 id="g-filename-to-uri" role="function">
<title>g_filename_to_uri ()</title>
<indexterm zone="g-filename-to-uri"><primary sortas="filename_to_uri">g_filename_to_uri</primary></indexterm><programlisting><link linkend="gchar">gchar</link> *             g_filename_to_uri                   (const <link linkend="gchar">gchar</link> *filename,
                                                         const <link linkend="gchar">gchar</link> *hostname,
                                                         <link linkend="GError">GError</link> **error);</programlisting>
<para>
Converts an absolute filename to an escaped ASCII-encoded URI, with the path
component following Section 3.3. of RFC 2396.</para>
<para>
</para><variablelist role="params">
<varlistentry><term><parameter>filename</parameter>&#160;:</term>
<listitem><simpara> an absolute filename specified in the GLib file name encoding,
           which is the on-disk file name bytes on Unix, and UTF-8 on 
           Windows
</simpara></listitem></varlistentry>
<varlistentry><term><parameter>hostname</parameter>&#160;:</term>
<listitem><simpara> A UTF-8 encoded hostname, or <link linkend="NULL--CAPS"><literal>NULL</literal></link> for none.
</simpara></listitem></varlistentry>
<varlistentry><term><parameter>error</parameter>&#160;:</term>
<listitem><simpara> location to store the error occuring, or <link linkend="NULL--CAPS"><literal>NULL</literal></link> to ignore
        errors. Any of the errors in <link linkend="GConvertError"><type>GConvertError</type></link> may occur.
</simpara></listitem></varlistentry>
<varlistentry><term><emphasis>Returns</emphasis>&#160;:</term><listitem><simpara> a newly-allocated string holding the resulting
              URI, or <link linkend="NULL--CAPS"><literal>NULL</literal></link> on an error.
</simpara></listitem></varlistentry>
</variablelist></refsect2>
<refsect2 id="g-get-filename-charsets" role="function" condition="since:2.6">
<title>g_get_filename_charsets ()</title>
<indexterm zone="g-get-filename-charsets" role="2.6"><primary sortas="get_filename_charsets">g_get_filename_charsets</primary></indexterm><programlisting><link linkend="gboolean">gboolean</link>            g_get_filename_charsets             (G_CONST_RETURN <link linkend="gchar">gchar</link> ***charsets);</programlisting>
<para>
Determines the preferred character sets used for filenames.
The first character set from the <parameter>charsets</parameter> is the filename encoding, the
subsequent character sets are used when trying to generate a displayable
representation of a filename, see <link linkend="g-filename-display-name"><function>g_filename_display_name()</function></link>.
</para>
<para>
On Unix, the character sets are determined by consulting the
environment variables <envar>G_FILENAME_ENCODING</envar> and
<envar>G_BROKEN_FILENAMES</envar>. On Windows, the character set
used in the GLib API is always UTF-8 and said environment variables
have no effect.
</para>
<para>
<envar>G_FILENAME_ENCODING</envar> may be set to a comma-separated list 
of character set names. The special token "&commat;locale" is taken to 
mean the character set for the <link linkend="setlocale">current 
locale</link>. If <envar>G_FILENAME_ENCODING</envar> is not set, but 
<envar>G_BROKEN_FILENAMES</envar> is, the character set of the current 
locale is taken as the filename encoding. If neither environment variable 
is set, UTF-8 is taken as the filename encoding, but the character
set of the current locale is also put in the list of encodings.
</para>
<para>
The returned <parameter>charsets</parameter> belong to GLib and must not be freed.
</para>
<para>
Note that on Unix, regardless of the locale character set or
<envar>G_FILENAME_ENCODING</envar> value, the actual file names present 
on a system might be in any random encoding or just gibberish.</para>
<para>
</para><variablelist role="params">
<varlistentry><term><parameter>charsets</parameter>&#160;:</term>
<listitem><simpara> return location for the <link linkend="NULL--CAPS"><literal>NULL</literal></link>-terminated list of encoding names
</simpara></listitem></varlistentry>
<varlistentry><term><emphasis>Returns</emphasis>&#160;:</term><listitem><simpara> <link linkend="TRUE--CAPS"><literal>TRUE</literal></link> if the filename encoding is UTF-8.

</simpara></listitem></varlistentry>
</variablelist><para role="since">Since 2.6</para></refsect2>
<refsect2 id="g-filename-display-name" role="function" condition="since:2.6">
<title>g_filename_display_name ()</title>
<indexterm zone="g-filename-display-name" role="2.6"><primary sortas="filename_display_name">g_filename_display_name</primary></indexterm><programlisting><link linkend="gchar">gchar</link> *             g_filename_display_name             (const <link linkend="gchar">gchar</link> *filename);</programlisting>
<para>
Converts a filename into a valid UTF-8 string. The conversion is 
not necessarily reversible, so you should keep the original around 
and use the return value of this function only for display purposes.
Unlike <link linkend="g-filename-to-utf8"><function>g_filename_to_utf8()</function></link>, the result is guaranteed to be non-<link linkend="NULL--CAPS"><literal>NULL</literal></link> 
even if the filename actually isn't in the GLib file name encoding.
</para>
<para>
If GLib can not make sense of the encoding of <parameter>filename</parameter>, as a last resort it 
replaces unknown characters with U+FFFD, the Unicode replacement character.
You can search the result for the UTF-8 encoding of this character (which is
"\357\277\275" in octal notation) to find out if <parameter>filename</parameter> was in an invalid
encoding.
</para>
<para>
If you know the whole pathname of the file you should use
<link linkend="g-filename-display-basename"><function>g_filename_display_basename()</function></link>, since that allows location-based
translation of filenames.</para>
<para>
</para><variablelist role="params">
<varlistentry><term><parameter>filename</parameter>&#160;:</term>
<listitem><simpara> a pathname hopefully in the GLib file name encoding
</simpara></listitem></varlistentry>
<varlistentry><term><emphasis>Returns</emphasis>&#160;:</term><listitem><simpara> a newly allocated string containing
  a rendition of the filename in valid UTF-8

</simpara></listitem></varlistentry>
</variablelist><para role="since">Since 2.6</para></refsect2>
<refsect2 id="g-filename-display-basename" role="function" condition="since:2.6">
<title>g_filename_display_basename ()</title>
<indexterm zone="g-filename-display-basename" role="2.6"><primary sortas="filename_display_basename">g_filename_display_basename</primary></indexterm><programlisting><link linkend="gchar">gchar</link> *             g_filename_display_basename         (const <link linkend="gchar">gchar</link> *filename);</programlisting>
<para>
Returns the display basename for the particular filename, guaranteed
to be valid UTF-8. The display name might not be identical to the filename,
for instance there might be problems converting it to UTF-8, and some files
can be translated in the display.
</para>
<para>
If GLib can not make sense of the encoding of <parameter>filename</parameter>, as a last resort it 
replaces unknown characters with U+FFFD, the Unicode replacement character.
You can search the result for the UTF-8 encoding of this character (which is
"\357\277\275" in octal notation) to find out if <parameter>filename</parameter> was in an invalid
encoding.
</para>
<para>
You must pass the whole absolute pathname to this functions so that
translation of well known locations can be done.
</para>
<para>
This function is preferred over <link linkend="g-filename-display-name"><function>g_filename_display_name()</function></link> if you know the
whole path, as it allows translation.</para>
<para>
</para><variablelist role="params">
<varlistentry><term><parameter>filename</parameter>&#160;:</term>
<listitem><simpara> an absolute pathname in the GLib file name encoding
</simpara></listitem></varlistentry>
<varlistentry><term><emphasis>Returns</emphasis>&#160;:</term><listitem><simpara> a newly allocated string containing
  a rendition of the basename of the filename in valid UTF-8

</simpara></listitem></varlistentry>
</variablelist><para role="since">Since 2.6</para></refsect2>
<refsect2 id="g-locale-from-utf8" role="function">
<title>g_locale_from_utf8 ()</title>
<indexterm zone="g-locale-from-utf8"><primary sortas="locale_from_utf8">g_locale_from_utf8</primary></indexterm><programlisting><link linkend="gchar">gchar</link>*              g_locale_from_utf8                  (const <link linkend="gchar">gchar</link> *utf8string,
                                                         <link linkend="gssize">gssize</link> len,
                                                         <link linkend="gsize">gsize</link> *bytes_read,
                                                         <link linkend="gsize">gsize</link> *bytes_written,
                                                         <link linkend="GError">GError</link> **error);</programlisting>
<para>
Converts a string from UTF-8 to the encoding used for strings by
the C runtime (usually the same as that used by the operating
system) in the <link linkend="setlocale">current locale</link>. On
Windows this means the system codepage.</para>
<para>
</para><variablelist role="params">
<varlistentry><term><parameter>utf8string</parameter>&#160;:</term>
<listitem><simpara>    a UTF-8 encoded string 
</simpara></listitem></varlistentry>
<varlistentry><term><parameter>len</parameter>&#160;:</term>
<listitem><simpara>           the length of the string, or -1 if the string is
                nul-terminated<footnoteref linkend="nul-unsafe"/>. 
</simpara></listitem></varlistentry>
<varlistentry><term><parameter>bytes_read</parameter>&#160;:</term>
<listitem><simpara>    location to store the number of bytes in the
                input string that were successfully converted, or <link linkend="NULL--CAPS"><literal>NULL</literal></link>.
                Even if the conversion was successful, this may be 
                less than <parameter>len</parameter> if there were partial characters
                at the end of the input. If the error
                <link linkend="G-CONVERT-ERROR-ILLEGAL-SEQUENCE--CAPS"><type>G_CONVERT_ERROR_ILLEGAL_SEQUENCE</type></link> occurs, the value
                stored will the byte offset after the last valid
                input sequence.
</simpara></listitem></varlistentry>
<varlistentry><term><parameter>bytes_written</parameter>&#160;:</term>
<listitem><simpara> the number of bytes stored in the output buffer (not 
                including the terminating nul).
</simpara></listitem></varlistentry>
<varlistentry><term><parameter>error</parameter>&#160;:</term>
<listitem><simpara>         location to store the error occuring, or <link linkend="NULL--CAPS"><literal>NULL</literal></link> to ignore
                errors. Any of the errors in <link linkend="GConvertError"><type>GConvertError</type></link> may occur.
</simpara></listitem></varlistentry>
<varlistentry><term><emphasis>Returns</emphasis>&#160;:</term><listitem><simpara> The converted string, or <link linkend="NULL--CAPS"><literal>NULL</literal></link> on an error.
</simpara></listitem></varlistentry>
</variablelist></refsect2>
<refsect2 id="GConvertError" role="enum">
<title>enum GConvertError</title>
<indexterm zone="GConvertError"><primary sortas="ConvertError">GConvertError</primary></indexterm><programlisting>typedef enum 
{
  G_CONVERT_ERROR_NO_CONVERSION,
  G_CONVERT_ERROR_ILLEGAL_SEQUENCE,
  G_CONVERT_ERROR_FAILED,
  G_CONVERT_ERROR_PARTIAL_INPUT,
  G_CONVERT_ERROR_BAD_URI,
  G_CONVERT_ERROR_NOT_ABSOLUTE_PATH
} GConvertError;
</programlisting>
<para>
Error codes returned by character set conversion routines.
</para><variablelist role="enum">
<varlistentry id="G-CONVERT-ERROR-NO-CONVERSION--CAPS" role="constant">
<term><literal>G_CONVERT_ERROR_NO_CONVERSION</literal></term>
<listitem><simpara>Conversion between the requested character sets
is not supported.
</simpara></listitem>
</varlistentry>
<varlistentry id="G-CONVERT-ERROR-ILLEGAL-SEQUENCE--CAPS" role="constant">
<term><literal>G_CONVERT_ERROR_ILLEGAL_SEQUENCE</literal></term>
<listitem><simpara>Invalid byte sequence in conversion input.
</simpara></listitem>
</varlistentry>
<varlistentry id="G-CONVERT-ERROR-FAILED--CAPS" role="constant">
<term><literal>G_CONVERT_ERROR_FAILED</literal></term>
<listitem><simpara>Conversion failed for some reason.
</simpara></listitem>
</varlistentry>
<varlistentry id="G-CONVERT-ERROR-PARTIAL-INPUT--CAPS" role="constant">
<term><literal>G_CONVERT_ERROR_PARTIAL_INPUT</literal></term>
<listitem><simpara>Partial character sequence at end of input.
</simpara></listitem>
</varlistentry>
<varlistentry id="G-CONVERT-ERROR-BAD-URI--CAPS" role="constant">
<term><literal>G_CONVERT_ERROR_BAD_URI</literal></term>
<listitem><simpara>URI is invalid.
</simpara></listitem>
</varlistentry>
<varlistentry id="G-CONVERT-ERROR-NOT-ABSOLUTE-PATH--CAPS" role="constant">
<term><literal>G_CONVERT_ERROR_NOT_ABSOLUTE_PATH</literal></term>
<listitem><simpara>Pathname is not an absolute path.
</simpara></listitem>
</varlistentry>
</variablelist></refsect2>
<refsect2 id="g-get-charset" role="function">
<title>g_get_charset ()</title>
<indexterm zone="g-get-charset"><primary sortas="get_charset">g_get_charset</primary></indexterm><programlisting><link linkend="gboolean">gboolean</link>            g_get_charset                       (G_CONST_RETURN <link linkend="char">char</link> **charset);</programlisting>
<para>
Obtains the character set for the <link linkend="setlocale">current 
locale</link>; you might use this character set as an argument to 
<link linkend="g-convert"><function>g_convert()</function></link>, to convert from the current locale's encoding to some 
other encoding. (Frequently <link linkend="g-locale-to-utf8"><function>g_locale_to_utf8()</function></link> and <link linkend="g-locale-from-utf8"><function>g_locale_from_utf8()</function></link>
are nice shortcuts, though.)
</para>
<para>
On Windows the character set returned by this function is the
so-called system default ANSI code-page. That is the character set
used by the "narrow" versions of C library and Win32 functions that
handle file names. It might be different from the character set
used by the C library's current locale.
</para>
<para>
The return value is <link linkend="TRUE--CAPS"><literal>TRUE</literal></link> if the locale's encoding is UTF-8, in that
case you can perhaps avoid calling <link linkend="g-convert"><function>g_convert()</function></link>.
</para>
<para>
The string returned in <parameter>charset</parameter> is not allocated, and should not be
freed.</para>
<para>
</para><variablelist role="params">
<varlistentry><term><parameter>charset</parameter>&#160;:</term>
<listitem><simpara> return location for character set name
</simpara></listitem></varlistentry>
<varlistentry><term><emphasis>Returns</emphasis>&#160;:</term><listitem><simpara> <link linkend="TRUE--CAPS"><literal>TRUE</literal></link> if the returned charset is UTF-8
</simpara></listitem></varlistentry>
</variablelist></refsect2>

</refsect1>




</refentry>
