/* Returns: a "conversion descriptor", or (GIConv)-1 if opening the converter failed.  */
GIConv g_iconv_open(const gchar *to_codeset, const gchar *from_codeset)
/* Returns: a "conversion descriptor", or (GIConv)-1 if opening the converter failed.  */
GIConv g_iconv_open(const gchar *to_codeset, const gchar *from_codeset)
{
  iconv_t cd;
  if (!try_conversion (to_codeset, from_codeset, &cd))
    {
      const char **to_aliases = _g_charset_get_aliases (to_codeset);
      const char **from_aliases = _g_charset_get_aliases (from_codeset);
      if (from_aliases)
	{
	  const char **p = from_aliases;
	  while (*p)
	    {
	      if (try_conversion (to_codeset, *p, &cd))
		goto out;
	      if (try_to_aliases (to_aliases, *p, &cd))
		goto out;
	      p++;
	    }
	}
      if (try_to_aliases (to_aliases, from_codeset, &cd))
	goto out;
    }
 out:
  return (cd == (iconv_t)-1) ? (GIConv)-1 : (GIConv)cd;
}