Update from gnulib.
diff --git a/libcharset/lib/ChangeLog b/libcharset/lib/ChangeLog
index ab7196b..6dd0455 100644
--- a/libcharset/lib/ChangeLog
+++ b/libcharset/lib/ChangeLog
@@ -1,3 +1,41 @@
+2016-12-02  Bruno Haible  <bruno@clisp.org>
+
+	* config.charset: Update from gnulib.
+	2015-01-07  KO Myung-Hun  <komh@chollian.net>
+		* config.charset: Don't output aliases if "$os" is os2*.
+	2012-06-22  Bruno Haible  <bruno@clisp.org>
+		* connfig.charset: Write "Mac OS X" instead of "MacOS X".
+
+	* localcharset.c: Update from gnulib.
+	2016-12-02  Bruno Haible  <bruno@clisp.org>
+		* localcharset.c (locale_charset) [WINDOWS_NATIVE]: Don't use
+		the return value from setlocale if it would lead to a buffer
+		overrun.
+	2015-01-07  KO Myung-Hun  <komh@chollian.net>
+		* localcharset.c (get_charset_aliases) [OS2]: Hardcode the
+		result for OS/2.
+		(locale_charset) [OS2]: Use system codepage if codeset is
+		omitted from the locale name which is neither "C" nor "POSIX".
+	2014-07-15  Eli Zaretskii  <eliz@gnu.org>
+		* localcharset.c (locale_charset) [WINDOWS_NATIVE]: Before
+		falling back on the default system codepage, try extracting
+		the codepage from what 'setlocale' returns.  This allows to
+		take into account changes of the codeset due to non-default
+		locale set by a previous call to 'setlocale'.
+	2013-07-20  Daiki Ueno  <ueno@gnu.org>
+		* localcharset.c (locale_charset) [DARWIN7]: Use MB_CUR_MAX_L
+		instead of MB_CUR_MAX.
+	2012-09-16  Paul Eggert  <eggert@cs.ucla.edu>
+		* localcharset.c (locale_charset) [DARWIN7]:
+		Return "ASCII" if the system reports "UTF-8" and
+		MB_CUR_MAX <= 1, as these two values are incompatible.  Problem
+		reported by Max Horn. For more discussion, please see
+		<http://lists.gnu.org/archive/html/bug-gnulib/2012-09/msg00061.html>.
+	2012-06-22  Bruno Haible  <bruno@clisp.org>
+		* localcharset.c: Write "Mac OS X" instead of "MacOS X".
+
+	* relocatable.c: Update from gnulib.
+
 2016-11-22  Bruno Haible  <bruno@clisp.org>
 
 	Update support for building with MSVC.
diff --git a/libcharset/lib/config.charset b/libcharset/lib/config.charset
index fae71f3..594e8ed 100644
--- a/libcharset/lib/config.charset
+++ b/libcharset/lib/config.charset
@@ -29,7 +29,7 @@
 # The current list of GNU canonical charset names is as follows.
 #
 #       name              MIME?             used by which systems
-#                                    (darwin = MacOS X, woe32 = native Windows)
+#                                    (darwin = Mac OS X, woe32 = native Windows)
 #
 #   ASCII, ANSI_X3.4-1968       glibc solaris freebsd netbsd darwin cygwin
 #   ISO-8859-1              Y   glibc aix hpux irix osf solaris freebsd netbsd openbsd darwin cygwin
@@ -348,12 +348,10 @@
     #echo "sun_eu_greek ?" # what is this?
     echo "UTF-8 UTF-8"
     ;;
-  freebsd* | os2*)
+  freebsd*)
     # FreeBSD 4.2 doesn't have nl_langinfo(CODESET); therefore
     # localcharset.c falls back to using the full locale name
     # from the environment variables.
-    # Likewise for OS/2. OS/2 has XFree86 just like FreeBSD. Just
-    # reuse FreeBSD's locale data for OS/2.
     echo "C ASCII"
     echo "US-ASCII ASCII"
     for l in la_LN lt_LN; do
diff --git a/libcharset/lib/localcharset.c b/libcharset/lib/localcharset.c
index 1756d5d..f3d7f27 100644
--- a/libcharset/lib/localcharset.c
+++ b/libcharset/lib/localcharset.c
@@ -29,11 +29,12 @@
 #include <stdlib.h>
 
 #if defined __APPLE__ && defined __MACH__ && HAVE_LANGINFO_CODESET
-# define DARWIN7 /* Darwin 7 or newer, i.e. MacOS X 10.3 or newer */
+# define DARWIN7 /* Darwin 7 or newer, i.e. Mac OS X 10.3 or newer */
 #endif
 
 #if defined _WIN32 || defined __WIN32__
 # define WINDOWS_NATIVE
+# include <locale.h>
 #endif
 
 #if defined __EMX__
@@ -65,6 +66,11 @@
 # include <os2.h>
 #endif
 
+/* For MB_CUR_MAX_L */
+#if defined DARWIN7
+# include <xlocale.h>
+#endif
+
 #if ENABLE_RELOCATABLE
 # include "relocatable.h"
 #else
@@ -122,7 +128,7 @@
   cp = charset_aliases;
   if (cp == NULL)
     {
-#if !(defined DARWIN7 || defined VMS || defined WINDOWS_NATIVE || defined __CYGWIN__)
+#if !(defined DARWIN7 || defined VMS || defined WINDOWS_NATIVE || defined __CYGWIN__ || defined OS2)
       const char *dir;
       const char *base = "charset.alias";
       char *file_name;
@@ -336,6 +342,36 @@
            "CP54936" "\0" "GB18030" "\0"
            "CP65001" "\0" "UTF-8" "\0";
 # endif
+# if defined OS2
+      /* To avoid the troubles of installing a separate file in the same
+         directory as the DLL and of retrieving the DLL's directory at
+         runtime, simply inline the aliases here.  */
+
+      /* The list of encodings is taken from "List of OS/2 Codepages"
+         by Alex Taylor:
+         <http://altsan.org/os2/toolkits/uls/index.html#codepages>.
+         See also "IBM Globalization - Code page identifiers":
+         <http://www-01.ibm.com/software/globalization/cp/cp_cpgid.html>.  */
+      cp = "CP813" "\0" "ISO-8859-7" "\0"
+           "CP878" "\0" "KOI8-R" "\0"
+           "CP819" "\0" "ISO-8859-1" "\0"
+           "CP912" "\0" "ISO-8859-2" "\0"
+           "CP913" "\0" "ISO-8859-3" "\0"
+           "CP914" "\0" "ISO-8859-4" "\0"
+           "CP915" "\0" "ISO-8859-5" "\0"
+           "CP916" "\0" "ISO-8859-8" "\0"
+           "CP920" "\0" "ISO-8859-9" "\0"
+           "CP921" "\0" "ISO-8859-13" "\0"
+           "CP923" "\0" "ISO-8859-15" "\0"
+           "CP954" "\0" "EUC-JP" "\0"
+           "CP964" "\0" "EUC-TW" "\0"
+           "CP970" "\0" "EUC-KR" "\0"
+           "CP1089" "\0" "ISO-8859-6" "\0"
+           "CP1208" "\0" "UTF-8" "\0"
+           "CP1381" "\0" "GB2312" "\0"
+           "CP1386" "\0" "GBK" "\0"
+           "CP3372" "\0" "EUC-JP" "\0";
+# endif
 #endif
 
       charset_aliases = cp;
@@ -456,14 +492,34 @@
 
   static char buf[2 + 10 + 1];
 
-  /* The Windows API has a function returning the locale's codepage as a
-     number: GetACP().
-     When the output goes to a console window, it needs to be provided in
-     GetOEMCP() encoding if the console is using a raster font, or in
-     GetConsoleOutputCP() encoding if it is using a TrueType font.
-     But in GUI programs and for output sent to files and pipes, GetACP()
-     encoding is the best bet.  */
-  sprintf (buf, "CP%u", GetACP ());
+  /* The Windows API has a function returning the locale's codepage as
+     a number, but the value doesn't change according to what the
+     'setlocale' call specified.  So we use it as a last resort, in
+     case the string returned by 'setlocale' doesn't specify the
+     codepage.  */
+  char *current_locale = setlocale (LC_ALL, NULL);
+  char *pdot;
+
+  /* If they set different locales for different categories,
+     'setlocale' will return a semi-colon separated list of locale
+     values.  To make sure we use the correct one, we choose LC_CTYPE.  */
+  if (strchr (current_locale, ';'))
+    current_locale = setlocale (LC_CTYPE, NULL);
+
+  pdot = strrchr (current_locale, '.');
+  if (pdot && 2 + strlen (pdot + 1) + 1 <= sizeof (buf))
+    sprintf (buf, "CP%s", pdot + 1);
+  else
+    {
+      /* The Windows API has a function returning the locale's codepage as a
+        number: GetACP().
+        When the output goes to a console window, it needs to be provided in
+        GetOEMCP() encoding if the console is using a raster font, or in
+        GetConsoleOutputCP() encoding if it is using a TrueType font.
+        But in GUI programs and for output sent to files and pipes, GetACP()
+        encoding is the best bet.  */
+      sprintf (buf, "CP%u", GetACP ());
+    }
   codeset = buf;
 
 #elif defined OS2
@@ -473,6 +529,8 @@
   ULONG cp[3];
   ULONG cplen;
 
+  codeset = NULL;
+
   /* Allow user to override the codeset, as set in the operating system,
      with standard language environment variables.  */
   locale = getenv ("LC_ALL");
@@ -504,10 +562,12 @@
             }
         }
 
-      /* Resolve through the charset.alias file.  */
-      codeset = locale;
+      /* For the POSIX locale, don't use the system's codepage.  */
+      if (strcmp (locale, "C") == 0 || strcmp (locale, "POSIX") == 0)
+        codeset = "";
     }
-  else
+
+  if (codeset == NULL)
     {
       /* OS/2 has a function returning the locale's codepage as a number.  */
       if (DosQueryCp (sizeof (cp), cp, &cplen))
@@ -542,5 +602,12 @@
   if (codeset[0] == '\0')
     codeset = "ASCII";
 
+#ifdef DARWIN7
+  /* Mac OS X sets MB_CUR_MAX to 1 when LC_ALL=C, and "UTF-8"
+     (the default codeset) does not work when MB_CUR_MAX is 1.  */
+  if (strcmp (codeset, "UTF-8") == 0 && MB_CUR_MAX_L (uselocale (NULL)) <= 1)
+    codeset = "ASCII";
+#endif
+
   return codeset;
 }
diff --git a/libcharset/lib/relocatable.c b/libcharset/lib/relocatable.c
index 1b48ab2..6d3658f 100644
--- a/libcharset/lib/relocatable.c
+++ b/libcharset/lib/relocatable.c
@@ -47,6 +47,14 @@
 # include <windows.h>
 #endif
 
+#ifdef __EMX__
+# define INCL_DOS
+# include <os2.h>
+
+# define strcmp  stricmp
+# define strncmp strnicmp
+#endif
+
 #if DEPENDS_ON_LIBCHARSET
 # include <libcharset.h>
 #endif
@@ -335,6 +343,45 @@
   return TRUE;
 }
 
+#elif defined __EMX__
+
+extern int  _CRT_init (void);
+extern void _CRT_term (void);
+extern void __ctordtorInit (void);
+extern void __ctordtorTerm (void);
+
+unsigned long _System
+_DLL_InitTerm (unsigned long hModule, unsigned long ulFlag)
+{
+  static char location[CCHMAXPATH];
+
+  switch (ulFlag)
+    {
+      case 0:
+        if (_CRT_init () == -1)
+          return 0;
+
+        __ctordtorInit();
+
+        /* See http://cyberkinetica.homeunix.net/os2tk45/cp1/1247_L2H_DosQueryModuleNameSy.html
+           for specification of DosQueryModuleName(). */
+        if (DosQueryModuleName (hModule, sizeof (location), location))
+          return 0;
+
+        _fnslashify (location);
+        shared_library_fullname = strdup (location);
+        break;
+
+      case 1:
+        __ctordtorTerm();
+
+        _CRT_term ();
+        break;
+    }
+
+  return 1;
+}
+
 #else /* Unix */
 
 static void
@@ -390,15 +437,16 @@
 #endif
 }
 
-#endif /* Native Windows / Unix */
+#endif /* Native Windows / EMX / Unix */
 
 /* Return the full pathname of the current shared library.
    Return NULL if unknown.
-   Guaranteed to work only on Linux, Cygwin, and native Windows.  */
+   Guaranteed to work only on Linux, EMX, Cygwin, and native Windows.  */
 static char *
 get_shared_library_fullname ()
 {
-#if !((defined _WIN32 || defined __WIN32__) && !defined __CYGWIN__)
+#if (!((defined _WIN32 || defined __WIN32__) && !defined __CYGWIN__) \
+     && !defined __EMX__)
   static bool tried_find_shared_library_fullname;
   if (!tried_find_shared_library_fullname)
     {
@@ -489,6 +537,39 @@
             }
         }
     }
+
+#ifdef __EMX__
+# ifdef __KLIBC__
+#  undef strncmp
+
+  if (pathname && strncmp (pathname, "/@unixroot", 10) == 0
+      && (pathname[10] == '\0' || pathname[10] == '/' || pathname[10] == '\\'))
+    {
+      /* kLIBC itself processes /@unixroot prefix */
+
+      return pathname;
+    }
+  else
+# endif
+  if (pathname && ISSLASH (pathname[0]))
+    {
+      const char *unixroot = getenv ("UNIXROOT");
+
+      if (unixroot && HAS_DEVICE (unixroot) && !unixroot[2])
+        {
+          char *result = (char *) xmalloc (2 + strlen (pathname) + 1);
+#ifdef NO_XMALLOC
+          if (result != NULL)
+#endif
+            {
+              strcpy (result, unixroot);
+              strcpy (result + 2, pathname);
+              return result;
+            }
+        }
+    }
+#endif
+
   /* Nothing to relocate.  */
   return pathname;
 }