Blame intl/localcharset.c

Packit Service a721b1
/* Determine a canonical name for the current locale's character encoding.
Packit Service a721b1
Packit Service a721b1
   Copyright (C) 2000-2006 Free Software Foundation, Inc.
Packit Service a721b1
Packit Service a721b1
   This program is free software; you can redistribute it and/or modify it
Packit Service a721b1
   under the terms of the GNU Library General Public License as published
Packit Service a721b1
   by the Free Software Foundation; either version 2, or (at your option)
Packit Service a721b1
   any later version.
Packit Service a721b1
Packit Service a721b1
   This program is distributed in the hope that it will be useful,
Packit Service a721b1
   but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit Service a721b1
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit Service a721b1
   Library General Public License for more details.
Packit Service a721b1
Packit Service a721b1
   You should have received a copy of the GNU Library General Public
Packit Service a721b1
   License along with this program; if not, write to the Free Software
Packit Service a721b1
   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
Packit Service a721b1
   USA.  */
Packit Service a721b1
Packit Service a721b1
/* Written by Bruno Haible <bruno@clisp.org>.  */
Packit Service a721b1
Packit Service a721b1
#include <config.h>
Packit Service a721b1
Packit Service a721b1
/* Specification.  */
Packit Service a721b1
#include "localcharset.h"
Packit Service a721b1
Packit Service a721b1
#include <stddef.h>
Packit Service a721b1
#include <stdio.h>
Packit Service a721b1
#include <string.h>
Packit Service a721b1
#include <stdlib.h>
Packit Service a721b1
Packit Service a721b1
#if defined _WIN32 || defined __WIN32__
Packit Service a721b1
# define WIN32_NATIVE
Packit Service a721b1
#endif
Packit Service a721b1
Packit Service a721b1
#if defined __EMX__
Packit Service a721b1
/* Assume EMX program runs on OS/2, even if compiled under DOS.  */
Packit Service a721b1
# define OS2
Packit Service a721b1
#endif
Packit Service a721b1
Packit Service a721b1
#if !defined WIN32_NATIVE
Packit Service a721b1
# if HAVE_LANGINFO_CODESET
Packit Service a721b1
#  include <langinfo.h>
Packit Service a721b1
# else
Packit Service a721b1
#  if 0 /* see comment below */
Packit Service a721b1
#   include <locale.h>
Packit Service a721b1
#  endif
Packit Service a721b1
# endif
Packit Service a721b1
# ifdef __CYGWIN__
Packit Service a721b1
#  define WIN32_LEAN_AND_MEAN
Packit Service a721b1
#  include <windows.h>
Packit Service a721b1
# endif
Packit Service a721b1
#elif defined WIN32_NATIVE
Packit Service a721b1
# define WIN32_LEAN_AND_MEAN
Packit Service a721b1
# include <windows.h>
Packit Service a721b1
#endif
Packit Service a721b1
#if defined OS2
Packit Service a721b1
# define INCL_DOS
Packit Service a721b1
# include <os2.h>
Packit Service a721b1
#endif
Packit Service a721b1
Packit Service a721b1
#if ENABLE_RELOCATABLE
Packit Service a721b1
# include "relocatable.h"
Packit Service a721b1
#else
Packit Service a721b1
# define relocate(pathname) (pathname)
Packit Service a721b1
#endif
Packit Service a721b1
Packit Service a721b1
/* Get LIBDIR.  */
Packit Service a721b1
#ifndef LIBDIR
Packit Service a721b1
# include "configmake.h"
Packit Service a721b1
#endif
Packit Service a721b1
Packit Service a721b1
#if defined _WIN32 || defined __WIN32__ || defined __CYGWIN__ || defined __EMX__ || defined __DJGPP__
Packit Service a721b1
  /* Win32, Cygwin, OS/2, DOS */
Packit Service a721b1
# define ISSLASH(C) ((C) == '/' || (C) == '\\')
Packit Service a721b1
#endif
Packit Service a721b1
Packit Service a721b1
#ifndef DIRECTORY_SEPARATOR
Packit Service a721b1
# define DIRECTORY_SEPARATOR '/'
Packit Service a721b1
#endif
Packit Service a721b1
Packit Service a721b1
#ifndef ISSLASH
Packit Service a721b1
# define ISSLASH(C) ((C) == DIRECTORY_SEPARATOR)
Packit Service a721b1
#endif
Packit Service a721b1
Packit Service a721b1
#if HAVE_DECL_GETC_UNLOCKED
Packit Service a721b1
# undef getc
Packit Service a721b1
# define getc getc_unlocked
Packit Service a721b1
#endif
Packit Service a721b1
Packit Service a721b1
/* The following static variable is declared 'volatile' to avoid a
Packit Service a721b1
   possible multithread problem in the function get_charset_aliases. If we
Packit Service a721b1
   are running in a threaded environment, and if two threads initialize
Packit Service a721b1
   'charset_aliases' simultaneously, both will produce the same value,
Packit Service a721b1
   and everything will be ok if the two assignments to 'charset_aliases'
Packit Service a721b1
   are atomic. But I don't know what will happen if the two assignments mix.  */
Packit Service a721b1
#if __STDC__ != 1
Packit Service a721b1
# define volatile /* empty */
Packit Service a721b1
#endif
Packit Service a721b1
/* Pointer to the contents of the charset.alias file, if it has already been
Packit Service a721b1
   read, else NULL.  Its format is:
Packit Service a721b1
   ALIAS_1 '\0' CANONICAL_1 '\0' ... ALIAS_n '\0' CANONICAL_n '\0' '\0'  */
Packit Service a721b1
static const char * volatile charset_aliases;
Packit Service a721b1
Packit Service a721b1
/* Return a pointer to the contents of the charset.alias file.  */
Packit Service a721b1
static const char *
Packit Service a721b1
get_charset_aliases (void)
Packit Service a721b1
{
Packit Service a721b1
  const char *cp;
Packit Service a721b1
Packit Service a721b1
  cp = charset_aliases;
Packit Service a721b1
  if (cp == NULL)
Packit Service a721b1
    {
Packit Service a721b1
#if !(defined VMS || defined WIN32_NATIVE || defined __CYGWIN__)
Packit Service a721b1
      FILE *fp;
Packit Service a721b1
      const char *dir;
Packit Service a721b1
      const char *base = "charset.alias";
Packit Service a721b1
      char *file_name;
Packit Service a721b1
Packit Service a721b1
      /* Make it possible to override the charset.alias location.  This is
Packit Service a721b1
	 necessary for running the testsuite before "make install".  */
Packit Service a721b1
      dir = getenv ("CHARSETALIASDIR");
Packit Service a721b1
      if (dir == NULL || dir[0] == '\0')
Packit Service a721b1
	dir = relocate (LIBDIR);
Packit Service a721b1
Packit Service a721b1
      /* Concatenate dir and base into freshly allocated file_name.  */
Packit Service a721b1
      {
Packit Service a721b1
	size_t dir_len = strlen (dir);
Packit Service a721b1
	size_t base_len = strlen (base);
Packit Service a721b1
	int add_slash = (dir_len > 0 && !ISSLASH (dir[dir_len - 1]));
Packit Service a721b1
	file_name = (char *) malloc (dir_len + add_slash + base_len + 1);
Packit Service a721b1
	if (file_name != NULL)
Packit Service a721b1
	  {
Packit Service a721b1
	    memcpy (file_name, dir, dir_len);
Packit Service a721b1
	    if (add_slash)
Packit Service a721b1
	      file_name[dir_len] = DIRECTORY_SEPARATOR;
Packit Service a721b1
	    memcpy (file_name + dir_len + add_slash, base, base_len + 1);
Packit Service a721b1
	  }
Packit Service a721b1
      }
Packit Service a721b1
Packit Service a721b1
      if (file_name == NULL || (fp = fopen (file_name, "r")) == NULL)
Packit Service a721b1
	/* Out of memory or file not found, treat it as empty.  */
Packit Service a721b1
	cp = "";
Packit Service a721b1
      else
Packit Service a721b1
	{
Packit Service a721b1
	  /* Parse the file's contents.  */
Packit Service a721b1
	  char *res_ptr = NULL;
Packit Service a721b1
	  size_t res_size = 0;
Packit Service a721b1
Packit Service a721b1
	  for (;;)
Packit Service a721b1
	    {
Packit Service a721b1
	      int c;
Packit Service a721b1
	      char buf1[50+1];
Packit Service a721b1
	      char buf2[50+1];
Packit Service a721b1
	      size_t l1, l2;
Packit Service a721b1
	      char *old_res_ptr;
Packit Service a721b1
Packit Service a721b1
	      c = getc (fp);
Packit Service a721b1
	      if (c == EOF)
Packit Service a721b1
		break;
Packit Service a721b1
	      if (c == '\n' || c == ' ' || c == '\t')
Packit Service a721b1
		continue;
Packit Service a721b1
	      if (c == '#')
Packit Service a721b1
		{
Packit Service a721b1
		  /* Skip comment, to end of line.  */
Packit Service a721b1
		  do
Packit Service a721b1
		    c = getc (fp);
Packit Service a721b1
		  while (!(c == EOF || c == '\n'));
Packit Service a721b1
		  if (c == EOF)
Packit Service a721b1
		    break;
Packit Service a721b1
		  continue;
Packit Service a721b1
		}
Packit Service a721b1
	      ungetc (c, fp);
Packit Service a721b1
	      if (fscanf (fp, "%50s %50s", buf1, buf2) < 2)
Packit Service a721b1
		break;
Packit Service a721b1
	      l1 = strlen (buf1);
Packit Service a721b1
	      l2 = strlen (buf2);
Packit Service a721b1
	      old_res_ptr = res_ptr;
Packit Service a721b1
	      if (res_size == 0)
Packit Service a721b1
		{
Packit Service a721b1
		  res_size = l1 + 1 + l2 + 1;
Packit Service a721b1
		  res_ptr = (char *) malloc (res_size + 1);
Packit Service a721b1
		}
Packit Service a721b1
	      else
Packit Service a721b1
		{
Packit Service a721b1
		  res_size += l1 + 1 + l2 + 1;
Packit Service a721b1
		  res_ptr = (char *) realloc (res_ptr, res_size + 1);
Packit Service a721b1
		}
Packit Service a721b1
	      if (res_ptr == NULL)
Packit Service a721b1
		{
Packit Service a721b1
		  /* Out of memory. */
Packit Service a721b1
		  res_size = 0;
Packit Service a721b1
		  if (old_res_ptr != NULL)
Packit Service a721b1
		    free (old_res_ptr);
Packit Service a721b1
		  break;
Packit Service a721b1
		}
Packit Service a721b1
	      strcpy (res_ptr + res_size - (l2 + 1) - (l1 + 1), buf1);
Packit Service a721b1
	      strcpy (res_ptr + res_size - (l2 + 1), buf2);
Packit Service a721b1
	    }
Packit Service a721b1
	  fclose (fp);
Packit Service a721b1
	  if (res_size == 0)
Packit Service a721b1
	    cp = "";
Packit Service a721b1
	  else
Packit Service a721b1
	    {
Packit Service a721b1
	      *(res_ptr + res_size) = '\0';
Packit Service a721b1
	      cp = res_ptr;
Packit Service a721b1
	    }
Packit Service a721b1
	}
Packit Service a721b1
Packit Service a721b1
      if (file_name != NULL)
Packit Service a721b1
	free (file_name);
Packit Service a721b1
Packit Service a721b1
#else
Packit Service a721b1
Packit Service a721b1
# if defined VMS
Packit Service a721b1
      /* To avoid the troubles of an extra file charset.alias_vms in the
Packit Service a721b1
	 sources of many GNU packages, simply inline the aliases here.  */
Packit Service a721b1
      /* The list of encodings is taken from the OpenVMS 7.3-1 documentation
Packit Service a721b1
	 "Compaq C Run-Time Library Reference Manual for OpenVMS systems"
Packit Service a721b1
	 section 10.7 "Handling Different Character Sets".  */
Packit Service a721b1
      cp = "ISO8859-1" "\0" "ISO-8859-1" "\0"
Packit Service a721b1
	   "ISO8859-2" "\0" "ISO-8859-2" "\0"
Packit Service a721b1
	   "ISO8859-5" "\0" "ISO-8859-5" "\0"
Packit Service a721b1
	   "ISO8859-7" "\0" "ISO-8859-7" "\0"
Packit Service a721b1
	   "ISO8859-8" "\0" "ISO-8859-8" "\0"
Packit Service a721b1
	   "ISO8859-9" "\0" "ISO-8859-9" "\0"
Packit Service a721b1
	   /* Japanese */
Packit Service a721b1
	   "eucJP" "\0" "EUC-JP" "\0"
Packit Service a721b1
	   "SJIS" "\0" "SHIFT_JIS" "\0"
Packit Service a721b1
	   "DECKANJI" "\0" "DEC-KANJI" "\0"
Packit Service a721b1
	   "SDECKANJI" "\0" "EUC-JP" "\0"
Packit Service a721b1
	   /* Chinese */
Packit Service a721b1
	   "eucTW" "\0" "EUC-TW" "\0"
Packit Service a721b1
	   "DECHANYU" "\0" "DEC-HANYU" "\0"
Packit Service a721b1
	   "DECHANZI" "\0" "GB2312" "\0"
Packit Service a721b1
	   /* Korean */
Packit Service a721b1
	   "DECKOREAN" "\0" "EUC-KR" "\0";
Packit Service a721b1
# endif
Packit Service a721b1
Packit Service a721b1
# if defined WIN32_NATIVE || defined __CYGWIN__
Packit Service a721b1
      /* To avoid the troubles of installing a separate file in the same
Packit Service a721b1
	 directory as the DLL and of retrieving the DLL's directory at
Packit Service a721b1
	 runtime, simply inline the aliases here.  */
Packit Service a721b1
Packit Service a721b1
      cp = "CP936" "\0" "GBK" "\0"
Packit Service a721b1
	   "CP1361" "\0" "JOHAB" "\0"
Packit Service a721b1
	   "CP20127" "\0" "ASCII" "\0"
Packit Service a721b1
	   "CP20866" "\0" "KOI8-R" "\0"
Packit Service a721b1
	   "CP20936" "\0" "GB2312" "\0"
Packit Service a721b1
	   "CP21866" "\0" "KOI8-RU" "\0"
Packit Service a721b1
	   "CP28591" "\0" "ISO-8859-1" "\0"
Packit Service a721b1
	   "CP28592" "\0" "ISO-8859-2" "\0"
Packit Service a721b1
	   "CP28593" "\0" "ISO-8859-3" "\0"
Packit Service a721b1
	   "CP28594" "\0" "ISO-8859-4" "\0"
Packit Service a721b1
	   "CP28595" "\0" "ISO-8859-5" "\0"
Packit Service a721b1
	   "CP28596" "\0" "ISO-8859-6" "\0"
Packit Service a721b1
	   "CP28597" "\0" "ISO-8859-7" "\0"
Packit Service a721b1
	   "CP28598" "\0" "ISO-8859-8" "\0"
Packit Service a721b1
	   "CP28599" "\0" "ISO-8859-9" "\0"
Packit Service a721b1
	   "CP28605" "\0" "ISO-8859-15" "\0"
Packit Service a721b1
	   "CP38598" "\0" "ISO-8859-8" "\0"
Packit Service a721b1
	   "CP51932" "\0" "EUC-JP" "\0"
Packit Service a721b1
	   "CP51936" "\0" "GB2312" "\0"
Packit Service a721b1
	   "CP51949" "\0" "EUC-KR" "\0"
Packit Service a721b1
	   "CP51950" "\0" "EUC-TW" "\0"
Packit Service a721b1
	   "CP54936" "\0" "GB18030" "\0"
Packit Service a721b1
	   "CP65001" "\0" "UTF-8" "\0";
Packit Service a721b1
# endif
Packit Service a721b1
#endif
Packit Service a721b1
Packit Service a721b1
      charset_aliases = cp;
Packit Service a721b1
    }
Packit Service a721b1
Packit Service a721b1
  return cp;
Packit Service a721b1
}
Packit Service a721b1
Packit Service a721b1
/* Determine the current locale's character encoding, and canonicalize it
Packit Service a721b1
   into one of the canonical names listed in config.charset.
Packit Service a721b1
   The result must not be freed; it is statically allocated.
Packit Service a721b1
   If the canonical name cannot be determined, the result is a non-canonical
Packit Service a721b1
   name.  */
Packit Service a721b1
Packit Service a721b1
#ifdef STATIC
Packit Service a721b1
STATIC
Packit Service a721b1
#endif
Packit Service a721b1
const char *
Packit Service a721b1
locale_charset (void)
Packit Service a721b1
{
Packit Service a721b1
  const char *codeset;
Packit Service a721b1
  const char *aliases;
Packit Service a721b1
Packit Service a721b1
#if !(defined WIN32_NATIVE || defined OS2)
Packit Service a721b1
Packit Service a721b1
# if HAVE_LANGINFO_CODESET
Packit Service a721b1
Packit Service a721b1
  /* Most systems support nl_langinfo (CODESET) nowadays.  */
Packit Service a721b1
  codeset = nl_langinfo (CODESET);
Packit Service a721b1
Packit Service a721b1
#  ifdef __CYGWIN__
Packit Service a721b1
  /* Cygwin 2006 does not have locales.  nl_langinfo (CODESET) always
Packit Service a721b1
     returns "US-ASCII".  As long as this is not fixed, return the suffix
Packit Service a721b1
     of the locale name from the environment variables (if present) or
Packit Service a721b1
     the codepage as a number.  */
Packit Service a721b1
  if (codeset != NULL && strcmp (codeset, "US-ASCII") == 0)
Packit Service a721b1
    {
Packit Service a721b1
      const char *locale;
Packit Service a721b1
      static char buf[2 + 10 + 1];
Packit Service a721b1
Packit Service a721b1
      locale = getenv ("LC_ALL");
Packit Service a721b1
      if (locale == NULL || locale[0] == '\0')
Packit Service a721b1
	{
Packit Service a721b1
	  locale = getenv ("LC_CTYPE");
Packit Service a721b1
	  if (locale == NULL || locale[0] == '\0')
Packit Service a721b1
	    locale = getenv ("LANG");
Packit Service a721b1
	}
Packit Service a721b1
      if (locale != NULL && locale[0] != '\0')
Packit Service a721b1
	{
Packit Service a721b1
	  /* If the locale name contains an encoding after the dot, return
Packit Service a721b1
	     it.  */
Packit Service a721b1
	  const char *dot = strchr (locale, '.');
Packit Service a721b1
Packit Service a721b1
	  if (dot != NULL)
Packit Service a721b1
	    {
Packit Service a721b1
	      const char *modifier;
Packit Service a721b1
Packit Service a721b1
	      dot++;
Packit Service a721b1
	      /* Look for the possible @... trailer and remove it, if any.  */
Packit Service a721b1
	      modifier = strchr (dot, '@');
Packit Service a721b1
	      if (modifier == NULL)
Packit Service a721b1
		return dot;
Packit Service a721b1
	      if (modifier - dot < sizeof (buf))
Packit Service a721b1
		{
Packit Service a721b1
		  memcpy (buf, dot, modifier - dot);
Packit Service a721b1
		  buf [modifier - dot] = '\0';
Packit Service a721b1
		  return buf;
Packit Service a721b1
		}
Packit Service a721b1
	    }
Packit Service a721b1
	}
Packit Service a721b1
Packit Service a721b1
      /* Woe32 has a function returning the locale's codepage as a number.  */
Packit Service a721b1
      sprintf (buf, "CP%u", GetACP ());
Packit Service a721b1
      codeset = buf;
Packit Service a721b1
    }
Packit Service a721b1
#  endif
Packit Service a721b1
Packit Service a721b1
# else
Packit Service a721b1
Packit Service a721b1
  /* On old systems which lack it, use setlocale or getenv.  */
Packit Service a721b1
  const char *locale = NULL;
Packit Service a721b1
Packit Service a721b1
  /* But most old systems don't have a complete set of locales.  Some
Packit Service a721b1
     (like SunOS 4 or DJGPP) have only the C locale.  Therefore we don't
Packit Service a721b1
     use setlocale here; it would return "C" when it doesn't support the
Packit Service a721b1
     locale name the user has set.  */
Packit Service a721b1
#  if 0
Packit Service a721b1
  locale = setlocale (LC_CTYPE, NULL);
Packit Service a721b1
#  endif
Packit Service a721b1
  if (locale == NULL || locale[0] == '\0')
Packit Service a721b1
    {
Packit Service a721b1
      locale = getenv ("LC_ALL");
Packit Service a721b1
      if (locale == NULL || locale[0] == '\0')
Packit Service a721b1
	{
Packit Service a721b1
	  locale = getenv ("LC_CTYPE");
Packit Service a721b1
	  if (locale == NULL || locale[0] == '\0')
Packit Service a721b1
	    locale = getenv ("LANG");
Packit Service a721b1
	}
Packit Service a721b1
    }
Packit Service a721b1
Packit Service a721b1
  /* On some old systems, one used to set locale = "iso8859_1". On others,
Packit Service a721b1
     you set it to "language_COUNTRY.charset". In any case, we resolve it
Packit Service a721b1
     through the charset.alias file.  */
Packit Service a721b1
  codeset = locale;
Packit Service a721b1
Packit Service a721b1
# endif
Packit Service a721b1
Packit Service a721b1
#elif defined WIN32_NATIVE
Packit Service a721b1
Packit Service a721b1
  static char buf[2 + 10 + 1];
Packit Service a721b1
Packit Service a721b1
  /* Woe32 has a function returning the locale's codepage as a number.  */
Packit Service a721b1
  sprintf (buf, "CP%u", GetACP ());
Packit Service a721b1
  codeset = buf;
Packit Service a721b1
Packit Service a721b1
#elif defined OS2
Packit Service a721b1
Packit Service a721b1
  const char *locale;
Packit Service a721b1
  static char buf[2 + 10 + 1];
Packit Service a721b1
  ULONG cp[3];
Packit Service a721b1
  ULONG cplen;
Packit Service a721b1
Packit Service a721b1
  /* Allow user to override the codeset, as set in the operating system,
Packit Service a721b1
     with standard language environment variables.  */
Packit Service a721b1
  locale = getenv ("LC_ALL");
Packit Service a721b1
  if (locale == NULL || locale[0] == '\0')
Packit Service a721b1
    {
Packit Service a721b1
      locale = getenv ("LC_CTYPE");
Packit Service a721b1
      if (locale == NULL || locale[0] == '\0')
Packit Service a721b1
	locale = getenv ("LANG");
Packit Service a721b1
    }
Packit Service a721b1
  if (locale != NULL && locale[0] != '\0')
Packit Service a721b1
    {
Packit Service a721b1
      /* If the locale name contains an encoding after the dot, return it.  */
Packit Service a721b1
      const char *dot = strchr (locale, '.');
Packit Service a721b1
Packit Service a721b1
      if (dot != NULL)
Packit Service a721b1
	{
Packit Service a721b1
	  const char *modifier;
Packit Service a721b1
Packit Service a721b1
	  dot++;
Packit Service a721b1
	  /* Look for the possible @... trailer and remove it, if any.  */
Packit Service a721b1
	  modifier = strchr (dot, '@');
Packit Service a721b1
	  if (modifier == NULL)
Packit Service a721b1
	    return dot;
Packit Service a721b1
	  if (modifier - dot < sizeof (buf))
Packit Service a721b1
	    {
Packit Service a721b1
	      memcpy (buf, dot, modifier - dot);
Packit Service a721b1
	      buf [modifier - dot] = '\0';
Packit Service a721b1
	      return buf;
Packit Service a721b1
	    }
Packit Service a721b1
	}
Packit Service a721b1
Packit Service a721b1
      /* Resolve through the charset.alias file.  */
Packit Service a721b1
      codeset = locale;
Packit Service a721b1
    }
Packit Service a721b1
  else
Packit Service a721b1
    {
Packit Service a721b1
      /* OS/2 has a function returning the locale's codepage as a number.  */
Packit Service a721b1
      if (DosQueryCp (sizeof (cp), cp, &cplen))
Packit Service a721b1
	codeset = "";
Packit Service a721b1
      else
Packit Service a721b1
	{
Packit Service a721b1
	  sprintf (buf, "CP%u", cp[0]);
Packit Service a721b1
	  codeset = buf;
Packit Service a721b1
	}
Packit Service a721b1
    }
Packit Service a721b1
Packit Service a721b1
#endif
Packit Service a721b1
Packit Service a721b1
  if (codeset == NULL)
Packit Service a721b1
    /* The canonical name cannot be determined.  */
Packit Service a721b1
    codeset = "";
Packit Service a721b1
Packit Service a721b1
  /* Resolve alias. */
Packit Service a721b1
  for (aliases = get_charset_aliases ();
Packit Service a721b1
       *aliases != '\0';
Packit Service a721b1
       aliases += strlen (aliases) + 1, aliases += strlen (aliases) + 1)
Packit Service a721b1
    if (strcmp (codeset, aliases) == 0
Packit Service a721b1
	|| (aliases[0] == '*' && aliases[1] == '\0'))
Packit Service a721b1
      {
Packit Service a721b1
	codeset = aliases + strlen (aliases) + 1;
Packit Service a721b1
	break;
Packit Service a721b1
      }
Packit Service a721b1
Packit Service a721b1
  /* Don't return an empty string.  GNU libc and GNU libiconv interpret
Packit Service a721b1
     the empty string as denoting "the locale's character encoding",
Packit Service a721b1
     thus GNU libiconv would call this function a second time.  */
Packit Service a721b1
  if (codeset[0] == '\0')
Packit Service a721b1
    codeset = "ASCII";
Packit Service a721b1
Packit Service a721b1
  return codeset;
Packit Service a721b1
}