binutils-gdb/gnulib/import/localcharset.c
Christian Biesinger c0c3707ff4 Update Gnulib to the latest git version
This patch allows us to remove a workaround in common-defs.h due to
the gnulib fix in:
https://lists.gnu.org/archive/html/bug-gnulib/2019-11/msg00024.html

All of GDB's local Gnulib patches were already fixed upstream per their
descriptions, so this patch removes them all.

The problem listed here:
https://sourceware.org/ml/gdb-patches/2019-08/msg00553.html
was probably partially fixed by moving gnulib to the toplevel;
for the remainder, I am setting MAKEOVERRIDES to empty in
gnulib/Makefile.am.  See also the comment there (it fixes an issue
with compilers that don't use C99/C11 by default such as GCC 4.8.5,
the default on Centos 7).

gdb/ChangeLog:

2019-12-16  Christian Biesinger  <cbiesinger@google.com>

	* gdbsupport/common-defs.h: Remove workaround for a gnulib bug
	(we no longer need to include time.h before pathmax.h)

gnulib/ChangeLog:

2019-12-16  Christian Biesinger  <cbiesinger@google.com>

	* Makefile.am: Set MAKEOVERRIDES.
	* Makefile.in: Regenerate.
	* aclocal.m4: Regenerate.
	* config.in: Regenerate.
	* configure: Regenerate.
	* import/Makefile.am: Update.
	* import/Makefile.in: Regenerate.
	* import/_Noreturn.h: New file.
	* import/alloca.c (i00afunc): Update.
	* import/alloca.in.h (if): Update.
	* import/arg-nonnull.h: Rename from import/extra/snippet/arg-nonnull.h.
	* import/arpa_inet.in.h (if): Update.
	* import/assure.h: Update.
	* import/at-func.c: Update.
	* import/basename-lgpl.c: Update.
	* import/canonicalize-lgpl.c (if): Update.
	* import/c++defs.h: Rename from import/extra/snippet/c++defs.h.
	* import/cdefs.h: New file.
	* import/chdir-long.c: Update.
	* import/chdir-long.h: Update.
	* import/cloexec.c: Update.
	* import/cloexec.h: Update.
	* import/close.c: Update.
	* import/closedir.c: Update.
	* import/config.charset: Remove.
	* import/dirent-private.h: Update.
	* import/dirent.in.h: Update.
	* import/dirfd.c: Update.
	* import/dirname-lgpl.c: Update.
	* import/dirname.h (base_name): Update.
	* import/dosname.h (if): Update.
	* import/dup-safer-flag.c: New file.
	* import/dup-safer.c: Update.
	* import/dup.c: Update.
	* import/dup2.c (if): Update.
	(dup2_nothrow): Update.
	(ms_windows_dup2): Update.
	* import/errno.in.h (if): Update.
	(elif): Update.
	* import/error.c (if): Update.
	(strerror_r): Update.
	(program_name): Update.
	(error): Update.
	(error_at_line): Update.
	* import/error.h: Update.
	* import/exitfail.c: Update.
	* import/exitfail.h: Update.
	* import/extra/config.rpath: Update.
	* import/extra/snippet/_Noreturn.h: Remove.
	* import/extra/update-copyright: Update.
	* import/fchdir.c: Update.
	* import/fcntl.c (rpl_fcntl): Update.
	(INCL_DOS): Update.
	(if): Update.
	(rpl_fcntl_DUPFD): Update.
	(rpl_fcntl_DUPFD_CLOEXEC): Update.
	(klibc_fcntl): Update.
	(fcntl): Update.
	(have_dupfd_cloexec): Update.
	* import/fcntl.in.h (if): Update.
	(creat): Update.
	(_GL_FUNCDECL_RPL): Update.
	(_GL_CXXALIAS_RPL): Update.
	(_GL_CXXALIAS_SYS): Update.
	(_GL_CXXALIASWARN): Update.
	(_GL_WARN_ON_USE): Update.
	(O_CLOEXEC): Update.
	(GNULIB_defined_O_CLOEXEC): Update.
	* import/fd-hook.c: Update.
	* import/fd-hook.h: Update.
	* import/fd-safer-flag.c: New file.
	* import/fd-safer.c: Update.
	* import/fdopendir.c: Update.
	* import/filename.h: Update.
	* import/filenamecat-lgpl.c (longest_relative_suffix): Update.
	(mfile_name_concat): Update.
	* import/filenamecat.h: Update.
	* import/flexmember.h: Update.
	* import/float+.h: Update.
	* import/float.c: Update.
	* import/float.in.h (LDBL_MIN): Update.
	* import/fnmatch.c (__builtin_expect): Update.
	(FALLTHROUGH): Update.
	* import/fnmatch.in.h (_FNMATCH_H): Update.
	(_): Update.
	(fnmatch): Update.
	(_GL_FUNCDECL_RPL): Update.
	(_GL_CXXALIAS_RPL): Update.
	(_GL_FUNCDECL_SYS): Update.
	(_GL_CXXALIAS_SYS): Update.
	(_GL_CXXALIASWARN): Update.
	(_GL_WARN_ON_USE): Update.
	* import/fnmatch_loop.c (FCT): Update.
	(EXT): Update.
	* import/fpucw.h (GET_FPUCW): Update.
	(SET_FPUCW): Update.
	* import/frexp.c: Update.
	* import/frexpl.c: Update.
	* import/fstat.c (stat): Update.
	(fstat): Update.
	(WINDOWS_NATIVE): Update.
	(fstat_nothrow): Update.
	(WIN32_LEAN_AND_MEAN): Update.
	* import/fstatat.c (normal_fstatat): Update.
	(rpl_fstatat): Update.
	* import/getcwd-lgpl.c (rpl_getcwd): Update.
	* import/getcwd.c (getcwd_nothrow): Update.
	(getcwd_system): Update.
	(__getcwd): Update.
	* import/getdtablesize.c (if): Update.
	(_setmaxstdio): Update.
	(_setmaxstdio_nothrow): Update.
	(getdtablesize): Update.
	* import/getlogin_r.c (if): Update.
	(getlogin_r): Update.
	* import/getprogname.c (getprogname): Update.
	* import/getprogname.h: Update.
	* import/gettext.h (if): Update.
	* import/gettimeofday.c (WINDOWS_NATIVE): Update.
	(localtime): Update.
	(GetProcAddress): Update.
	(gmtime): Update.
	(void): Update.
	(struct tm): Update.
	(rpl_localtime): Update.
	(initialize): Update.
	(rpl_gmtime): Update.
	(tzset): Update.
	(rpl_tzset): Update.
	* import/glob-libc.h (_Restrict_): Update.
	(__size_t): Update.
	(__need_size_t): Update.
	(glob): Update.
	(globfree): Update.
	(__REDIRECT_NTH): Update.
	(glob64): Update.
	(globfree64): Update.
	(glob_pattern_p): Update.
	* import/glob.c (POSIX): Update.
	(if): Update.
	(__set_errno): Update.
	(getpwnam_r): Update.
	(__lstat64): Update.
	(FLEXIBLE_ARRAY_MEMBER): Update.
	(__glob_pattern_p): Update.
	(GETPW_R_SIZE_MAX): Update.
	(GET_LOGIN_NAME_MAX): Update.
	(DT_UNKNOWN): Update.
	(DT_DIR): Update.
	(DT_LNK): Update.
	(D_TYPE_TO_RESULT): Update.
	(readdir_result_might_be_symlink): Update.
	(readdir_result_might_be_dir): Update.
	(readdir_result_type): Update.
	(D_INO_TO_RESULT): Update.
	(READDIR_RESULT_INITIALIZER): Update.
	(attribute_hidden): Update.
	(__attribute_noinline__): Update.
	(__builtin_expect): Update.
	(__glibc_unlikely): Update.
	(__has_builtin): Update.
	(__glob_pattern_type): Update.
	(is_dir): Update.
	(glob): Update.
	(globfree): Update.
	(libc_hidden_def): Update.
	(DIRSEP_CHAR): Update.
	(prefix_array): Update.
	(weak_alias): Update.
	(link_exists2_p): Update.
	(link_exists_p): Update.
	(glob_in_dir): Update.
	(GLOBNAMES_MEMBERS): Update.
	* import/glob.in.h (_GL_GLOB_H): Update.
	(_): Update.
	(__BEGIN_DECLS): Update.
	(__END_DECLS): Update.
	(_Restrict_): Update.
	(__THROW): Update.
	(__THROWNL): Update.
	(__size_t): Update.
	(__USE_GNU): Update.
	(glob): Update.
	(globfree): Update.
	(glob_pattern_p): Update.
	(__glob_pattern_p): Update.
	(__GLOB_GNULIB): Update.
	(_GL_FUNCDECL_RPL): Update.
	(_GL_CXXALIAS_RPL): Update.
	(_GL_FUNCDECL_SYS): Update.
	(_GL_CXXALIAS_SYS): Update.
	(_GL_WARN_ON_USE): Update.
	* import/glob_internal.h: New file.
	* import/glob_pattern_p.c: New file.
	* import/globfree.c: New file.
	* import/glthread/lock.c (glthread_rwlock_init_for_glibc): Update.
	(glthread_rwlock_rdlock_multithreaded): Update.
	(glthread_once_call): Update.
	(glthread_once_multithreaded): Update.
	(glthread_once_singlethreaded): Update.
	(glthread_recursive_lock_init_multithreaded): Update.
	(glthread_recursive_lock_lock_multithreaded): Update.
	(glthread_recursive_lock_unlock_multithreaded): Update.
	(glthread_recursive_lock_destroy_multithreaded): Update.
	(glthread_lock_init_func): Update.
	(glthread_lock_lock_func): Update.
	(glthread_lock_unlock_func): Update.
	(glthread_lock_destroy_func): Update.
	(gl_waitqueue_t): Update.
	(gl_waitqueue_init): Update.
	(gl_waitqueue_add): Update.
	(gl_waitqueue_notify_first): Update.
	(gl_waitqueue_notify_all): Update.
	(glthread_rwlock_init_func): Update.
	(glthread_rwlock_rdlock_func): Update.
	(glthread_rwlock_wrlock_func): Update.
	(glthread_rwlock_unlock_func): Update.
	(glthread_rwlock_destroy_func): Update.
	(glthread_recursive_lock_init_func): Update.
	(glthread_recursive_lock_lock_func): Update.
	(glthread_recursive_lock_unlock_func): Update.
	(glthread_recursive_lock_destroy_func): Update.
	(glthread_once_func): Update.
	* import/glthread/lock.h (c11_threads_in_use): Update.
	(pthread_in_use): Update.
	(gl_rwlock_initializer): Update.
	(glthread_rwlock_init): Update.
	(glthread_rwlock_init_for_glibc): Update.
	(pth_in_use): Update.
	(gl_lock_define): Update.
	(gl_lock_define_initialized): Update.
	(gl_lock_initializer): Update.
	(glthread_lock_init): Update.
	(glthread_lock_lock): Update.
	(glthread_lock_unlock): Update.
	(glthread_lock_destroy): Update.
	(gl_rwlock_define): Update.
	(gl_rwlock_define_initialized): Update.
	(glthread_rwlock_rdlock): Update.
	(glthread_rwlock_wrlock): Update.
	(glthread_rwlock_unlock): Update.
	(glthread_rwlock_destroy): Update.
	(gl_recursive_lock_define): Update.
	(gl_recursive_lock_define_initialized): Update.
	(gl_recursive_lock_initializer): Update.
	(glthread_recursive_lock_init): Update.
	(glthread_recursive_lock_lock): Update.
	(glthread_recursive_lock_unlock): Update.
	(glthread_recursive_lock_destroy): Update.
	(gl_once_define): Update.
	(glthread_once): Update.
	(glthread_once_multithreaded): Update.
	(glthread_once_singlethreaded): Update.
	(thread_in_use): Update.
	(glthread_recursive_lock_init_multithreaded): Update.
	(glthread_recursive_lock_lock_multithreaded): Update.
	(glthread_recursive_lock_unlock_multithreaded): Update.
	(glthread_recursive_lock_destroy_multithreaded): Update.
	(glthread_lock_init_func): Update.
	(glthread_lock_lock_func): Update.
	(glthread_lock_unlock_func): Update.
	(glthread_lock_destroy_func): Update.
	(glthread_rwlock_init_func): Update.
	(glthread_rwlock_rdlock_func): Update.
	(glthread_rwlock_wrlock_func): Update.
	(glthread_rwlock_unlock_func): Update.
	(glthread_rwlock_destroy_func): Update.
	(glthread_recursive_lock_init_func): Update.
	(glthread_recursive_lock_lock_func): Update.
	(glthread_recursive_lock_unlock_func): Update.
	(glthread_recursive_lock_destroy_func): Update.
	(glthread_once_func): Update.
	* import/glthread/threadlib.c: Update.
	* import/hard-locale.c: Update.
	* import/hard-locale.h: Update.
	* import/inet_ntop.c: Update.
	* import/intprops.h (__has_builtin): Update.
	(_GL_INT_CONVERT): Update.
	(_GL_INT_NEGATE_CONVERT): Update.
	(verify): Update.
	(_GL_HAS_BUILTIN_OVERFLOW): Update.
	(_GL_HAS_BUILTIN_ADD_OVERFLOW): Update.
	(_GL_HAS_BUILTIN_OVERFLOW_P): Update.
	(_GL_HAS_BUILTIN_MUL_OVERFLOW): Update.
	(_GL_BINARY_OP_OVERFLOW): Update.
	(INT_ADD_WRAPV): Update.
	(INT_SUBTRACT_WRAPV): Update.
	(INT_MULTIPLY_WRAPV): Update.
	(_GL_INT_OP_WRAPV): Update.
	(_GL_INT_OP_WRAPV_SMALLISH): Update.
	(_GL_INT_OP_WRAPV_LONGISH): Update.
	(_GL_INT_OP_CALC): Update.
	(_GL_INT_OP_CALC1): Update.
	(_GL_INT_OP_WRAPV_VIA_UNSIGNED): Update.
	(_GL_INT_ADD_RANGE_OVERFLOW): Update.
	(_GL_INT_SUBTRACT_RANGE_OVERFLOW): Update.
	(_GL_INT_MULTIPLY_RANGE_OVERFLOW): Update.
	* import/inttypes.in.h (if): Update.
	* import/isnan.c: Update.
	* import/isnand-nolibm.h: Update.
	* import/isnand.c: Update.
	* import/isnanl-nolibm.h: Update.
	* import/isnanl.c: Update.
	* import/itold.c: Update.
	* import/libc-config.h: New file.
	* import/limits.in.h (LLONG_MIN): Update.
	(LLONG_MAX): Update.
	(ULLONG_MAX): Update.
	(WORD_BIT): Update.
	(LONG_BIT): Update.
	* import/localcharset.c (setlocale): Update.
	(relocate): Update.
	(O_NOFOLLOW): Update.
	(ISSLASH): Update.
	(DIRECTORY_SEPARATOR): Update.
	(getc): Update.
	(volatile): Update.
	(get_charset_aliases): Update.
	(struct table_entry): Update.
	(alias_table_defined): Update.
	(locale_table_defined): Update.
	(locale_charset): Update.
	(if): Update.
	* import/localcharset.h: Update.
	* import/localtime-buffer.c: New file.
	* import/localtime-buffer.h: New file.
	* import/lstat.c (rpl_lstat): Update.
	* import/m4/00gnulib.m4: Update.
	* import/m4/__inline.m4: New file.
	* import/m4/absolute-header.m4: Update.
	* import/m4/alloca.m4: Update.
	* import/m4/arpa_inet_h.m4: Update.
	* import/m4/builtin-expect.m4: New file.
	* import/m4/canonicalize.m4: Update.
	* import/m4/chdir-long.m4: Update.
	* import/m4/close.m4: Update.
	* import/m4/closedir.m4: Update.
	* import/m4/codeset.m4: Update.
	* import/m4/configmake.m4: Remove.
	* import/m4/d-ino.m4: Update.
	* import/m4/d-type.m4: Update.
	* import/m4/dirent_h.m4: Update.
	* import/m4/dirfd.m4: Update.
	* import/m4/dirname.m4: Update.
	* import/m4/double-slash-root.m4: Update.
	* import/m4/dup.m4: Update.
	* import/m4/dup2.m4: Update.
	* import/m4/eealloc.m4: Update.
	* import/m4/environ.m4: Update.
	* import/m4/errno_h.m4: Update.
	* import/m4/error.m4: Update.
	* import/m4/exponentd.m4: Update.
	* import/m4/exponentl.m4: Update.
	* import/m4/extensions.m4: Update.
	* import/m4/extern-inline.m4: Update.
	* import/m4/fchdir.m4: Update.
	* import/m4/fcntl-o.m4: Update.
	* import/m4/fcntl.m4: Update.
	* import/m4/fcntl_h.m4: Update.
	* import/m4/fdopendir.m4: Update.
	* import/m4/filenamecat.m4: Update.
	* import/m4/flexmember.m4: Update.
	* import/m4/float_h.m4: Update.
	* import/m4/fnmatch.m4: Update.
	* import/m4/fnmatch_h.m4: New file.
	* import/m4/fpieee.m4: Update.
	* import/m4/frexp.m4: Update.
	* import/m4/frexpl.m4: Update.
	* import/m4/fstat.m4: Update.
	* import/m4/fstatat.m4: Update.
	* import/m4/getcwd-abort-bug.m4: Update.
	* import/m4/getcwd-path-max.m4: Update.
	* import/m4/getcwd.m4: Update.
	* import/m4/getdtablesize.m4: Update.
	* import/m4/getlogin.m4: New file.
	* import/m4/getlogin_r.m4: Update.
	* import/m4/getpagesize.m4: New file.
	* import/m4/getprogname.m4: Update.
	* import/m4/gettimeofday.m4: Update.
	* import/m4/glibc21.m4: Remove.
	* import/m4/glob.m4: Update.
	* import/m4/glob_h.m4: New file.
	* import/m4/gnulib-cache.m4: Update.
	* import/m4/gnulib-common.m4: Update.
	* import/m4/gnulib-comp.m4: Update.
	* import/m4/gnulib-tool.m4: Update.
	* import/m4/hard-locale.m4: Remove.
	* import/m4/host-cpu-c-abi.m4: New file.
	* import/m4/include_next.m4: Update.
	* import/m4/inet_ntop.m4: Update.
	* import/m4/inttypes-pri.m4: Update.
	* import/m4/inttypes.m4: Update.
	* import/m4/isnand.m4: Update.
	* import/m4/isnanl.m4: Update.
	* import/m4/largefile.m4: Update.
	* import/m4/lib-ld.m4: Update.
	* import/m4/lib-link.m4: Update.
	* import/m4/lib-prefix.m4: Update.
	* import/m4/limits-h.m4: Update.
	* import/m4/localcharset.m4: Update.
	* import/m4/locale-fr.m4: Update.
	* import/m4/locale-ja.m4: Update.
	* import/m4/locale-zh.m4: Update.
	* import/m4/localtime-buffer.m4: New file.
	* import/m4/lock.m4: Update.
	* import/m4/longlong.m4: Update.
	* import/m4/lstat.m4: Update.
	* import/m4/malloc.m4: Update.
	* import/m4/malloca.m4: Update.
	* import/m4/math_h.m4: Update.
	* import/m4/mbrtowc.m4: Update.
	* import/m4/mbsinit.m4: Update.
	* import/m4/mbsrtowcs.m4: Update.
	* import/m4/mbstate_t.m4: Update.
	* import/m4/memchr.m4: Update.
	* import/m4/memmem.m4: Update.
	* import/m4/mempcpy.m4: Update.
	* import/m4/memrchr.m4: Update.
	* import/m4/mkdir.m4: Update.
	* import/m4/mkdtemp.m4: Update.
	* import/m4/mkostemp.m4: Update.
	* import/m4/mmap-anon.m4: Update.
	* import/m4/mode_t.m4: Update.
	* import/m4/msvc-inval.m4: Update.
	* import/m4/msvc-nothrow.m4: Update.
	* import/m4/multiarch.m4: Update.
	* import/m4/netinet_in_h.m4: Update.
	* import/m4/nocrash.m4: Update.
	* import/m4/off_t.m4: Update.
	* import/m4/onceonly.m4: Remove.
	* import/m4/open-cloexec.m4: New file.
	* import/m4/open-slash.m4: New file.
	* import/m4/open.m4: Update.
	* import/m4/openat.m4: Update.
	* import/m4/opendir.m4: Update.
	* import/m4/pathmax.m4: Update.
	* import/m4/pthread_rwlock_rdlock.m4: New file.
	* import/m4/rawmemchr.m4: Update.
	* import/m4/readdir.m4: Update.
	* import/m4/readlink.m4: Update.
	* import/m4/realloc.m4: Update.
	* import/m4/rename.m4: Update.
	* import/m4/rewinddir.m4: Update.
	* import/m4/rmdir.m4: Update.
	* import/m4/save-cwd.m4: Update.
	* import/m4/secure_getenv.m4: Remove.
	* import/m4/setenv.m4: Update.
	* import/m4/signal_h.m4: Update.
	* import/m4/socklen.m4: Update.
	* import/m4/sockpfaf.m4: Update.
	* import/m4/ssize_t.m4: Update.
	* import/m4/stat-time.m4: New file.
	* import/m4/stat.m4: Update.
	* import/m4/std-gnu11.m4: New file.
	* import/m4/stdalign.m4: Update.
	* import/m4/stdbool.m4: Update.
	* import/m4/stddef_h.m4: Update.
	* import/m4/stdint.m4: Update.
	* import/m4/stdio_h.m4: Update.
	* import/m4/stdlib_h.m4: Update.
	* import/m4/strchrnul.m4: Update.
	* import/m4/strdup.m4: Update.
	* import/m4/strerror.m4: Update.
	* import/m4/strerror_r.m4: Update.
	* import/m4/string_h.m4: Update.
	* import/m4/strstr.m4: Update.
	* import/m4/strtok_r.m4: Update.
	* import/m4/sys_socket_h.m4: Update.
	* import/m4/sys_stat_h.m4: Update.
	* import/m4/sys_time_h.m4: Update.
	* import/m4/sys_types_h.m4: Update.
	* import/m4/sys_uio_h.m4: Update.
	* import/m4/tempname.m4: Update.
	* import/m4/threadlib.m4: Update.
	* import/m4/time_h.m4: Update.
	* import/m4/time_r.m4: Update.
	* import/m4/unistd-safer.m4: Update.
	* import/m4/unistd_h.m4: Update.
	* import/m4/warn-on-use.m4: Update.
	* import/m4/wchar_h.m4: Update.
	* import/m4/wchar_t.m4: Update.
	* import/m4/wctype_h.m4: Update.
	* import/m4/wint_t.m4: Update.
	* import/malloc.c: Update.
	* import/malloc/scratch_buffer.h: New file.
	* import/malloc/scratch_buffer_grow.c: New file.
	* import/malloc/scratch_buffer_grow_preserve.c: New file.
	* import/malloc/scratch_buffer_set_array_size.c: New file.
	* import/malloca.c (MAGIC_NUMBER): Update.
	(MAGIC_SIZE): Update.
	(struct preliminary_header): Update.
	(HEADER_SIZE): Update.
	(union header): Update.
	(verify): Update.
	(HASH_TABLE_SIZE): Update.
	(freea): Update.
	* import/malloca.h (malloca): Update.
	(nmalloca): Update.
	* import/malloca.valgrind: Remove.
	* import/math.in.h (_GL_MATH_CXX_REAL_FLOATING_DECL_2): Update.
	(func): Update.
	(rpl_func): Update.
	(f): Update.
	(d): Update.
	(l): Update.
	(_GL_WARN_ON_USE): Update.
	(_GL_WARN_ON_USE_ATTRIBUTE): Update.
	(FP_ILOGB0): Update.
	(FP_ILOGBNAN): Update.
	(acosf): Update.
	(_GL_FUNCDECL_RPL): Update.
	(_GL_CXXALIAS_RPL): Update.
	(asinf): Update.
	(atanf): Update.
	(atan2f): Update.
	(cosf): Update.
	(coshf): Update.
	(expf): Update.
	(expl): Update.
	(expm1l): Update.
	(ilogbl): Update.
	(rintl): Update.
	(sinf): Update.
	(sinhf): Update.
	(sqrtf): Update.
	(tanf): Update.
	(tanhf): Update.
	(isfinite): Update.
	(isinf): Update.
	(isnan): Update.
	(GNULIB_defined_signbit): Update.
	(signbit): Update.
	* import/mbrtowc.c (FALLTHROUGH): Update.
	(locale_enc): Update.
	(locale_enc_cached): Update.
	(gl_lock_define_initialized): Update.
	(mbrtowc): Update.
	* import/mbsinit.c (if): Update.
	(mbsinit): Update.
	* import/mbsrtowcs-impl.h: Update.
	* import/mbsrtowcs-state.c: Update.
	* import/mbsrtowcs.c: Update.
	* import/memchr.c: Update.
	* import/memchr.valgrind: Update.
	* import/memmem.c (__builtin_expect): Update.
	* import/mempcpy.c: Update.
	* import/memrchr.c (__memrchr): Update.
	* import/mkdir.c (if): Update.
	* import/mkdtemp.c: Update.
	* import/mkostemp.c: Update.
	* import/msvc-inval.c: Update.
	* import/msvc-inval.h: Update.
	* import/msvc-nothrow.c: Update.
	* import/msvc-nothrow.h (if): Update.
	* import/netinet_in.in.h: Update.
	* import/open.c (open): Update.
	(if): Update.
	* import/openat-die.c: Update.
	* import/openat-priv.h: Update.
	* import/openat-proc.c: Update.
	* import/openat.c (rpl_openat): Update.
	* import/openat.h: Update.
	* import/opendir.c: Update.
	* import/pathmax.h (if): Update.
	* import/pipe-safer.c: Update.
	* import/rawmemchr.c: Update.
	* import/rawmemchr.valgrind: Update.
	* import/readdir.c (readdir): Update.
	* import/readlink.c: Update.
	* import/realloc.c: Update.
	* import/ref-add.sin: Remove.
	* import/ref-del.sin: Remove.
	* import/rename.c (if): Update.
	* import/rewinddir.c: Update.
	* import/rmdir.c: Update.
	* import/same-inode.h (SAME_INODE): Update.
	* import/save-cwd.c (save_cwd): Update.
	* import/save-cwd.h: Update.
	* import/scratch_buffer.h: New file.
	* import/secure_getenv.c: Remove.
	* import/setenv.c: Update.
	* import/signal.in.h: Update.
	* import/stat-time.c: New file.
	* import/stat-time.h: New file.
	* import/stat-w32.c: New file.
	* import/stat-w32.h: New file.
	* import/stat.c (if): Update.
	(stat): Update.
	(REPLACE_FUNC_STAT_DIR): Update.
	(WINDOWS_NATIVE): Update.
	(WIN32_LEAN_AND_MEAN): Update.
	(is_unc_root): Update.
	(rpl_stat): Update.
	* import/stdalign.in.h (elif): Update.
	* import/stdbool.in.h: Update.
	* import/stddef.in.h (_GL_STDDEF_ALIGNAS): Update.
	(max_align_t): Update.
	(GNULIB_defined_max_align_t): Update.
	* import/stdint.in.h (WINT_MIN): Update.
	(WINT_MAX): Update.
	(_STDINT_MIN): Update.
	(_STDINT_UNSIGNED_MIN): Update.
	(_STDINT_SIGNED_MIN): Update.
	(PTRDIFF_MIN): Update.
	(SIG_ATOMIC_MIN): Update.
	(WCHAR_MIN): Update.
	* import/stdio.in.h (if): Update.
	* import/stdlib.in.h (if): Update.
	(_GL_WARN_ON_USE): Update.
	(_GL_FUNCDECL_SYS): Update.
	(random): Update.
	(_GL_FUNCDECL_RPL): Update.
	(_GL_CXXALIAS_RPL): Update.
	(srandom): Update.
	(initstate): Update.
	(setstate): Update.
	(_GL_CXXALIAS_SYS): Update.
	(_GL_CXXALIASWARN): Update.
	(GNULIB_defined_strtod_function): Update.
	(strtold): Update.
	(GNULIB_defined_strtold_function): Update.
	* import/str-two-way.h: Update.
	* import/strchrnul.c: Update.
	* import/strchrnul.valgrind: Update.
	* import/strdup.c: Update.
	* import/streq.h: Update.
	* import/strerror-override.c: Update.
	* import/strerror-override.h: Update.
	* import/strerror.c (strerror): Update.
	* import/strerror_r.c (safe_copy): Update.
	* import/string.in.h (_GL_FUNCDECL_SYS): Update.
	(_GL_CXXALIAS_SYS): Update.
	(_GL_CXXALIASWARN): Update.
	(_GL_WARN_ON_USE): Update.
	* import/stripslash.c: Update.
	* import/strnlen1.c: Update.
	* import/strnlen1.h: Update.
	* import/strstr.c (__builtin_expect): Update.
	* import/strtok_r.c: Update.
	* import/sys_socket.in.h (CMSG_SPACE): Update.
	(CMSG_LEN): Update.
	(struct sockaddr_storage): Update.
	(SO_REUSEPORT): Update.
	(_GL_WARN_ON_USE): Update.
	* import/sys_stat.in.h (if): Update.
	(stat): Update.
	(struct stat): Update.
	(st_atime): Update.
	(st_mtime): Update.
	(st_ctime): Update.
	(_GL_WINDOWS_STAT_TIMESPEC): Update.
	(GNULIB_defined_struct_stat): Update.
	(_S_IFBLK): Update.
	(_S_IFLNK): Update.
	(_S_IFSOCK): Update.
	(fstat): Update.
	(fstatat): Update.
	(lstat): Update.
	(stat64): Update.
	(_stat64): Update.
	(_stat32i64): Update.
	(_stati64): Update.
	(_stat32): Update.
	(_stat64i32): Update.
	* import/sys_time.in.h: Update.
	* import/sys_types.in.h (dev_t): Update.
	(GNULIB_defined_dev_t): Update.
	(ino_t): Update.
	(GNULIB_defined_ino_t): Update.
	(_GL_WINDOWS_STAT_INODES): Update.
	(if): Update.
	* import/sys_uio.in.h: Update.
	* import/tempname.c (__secure_getenv): Update.
	(try_nocreate): Update.
	* import/tempname.h: Update.
	* import/time.in.h (tzset): Update.
	(_GL_FUNCDECL_RPL): Update.
	(_GL_CXXALIAS_RPL): Update.
	(_GL_FUNCDECL_SYS): Update.
	(_GL_CXXALIAS_SYS): Update.
	(_GL_CXXALIASWARN): Update.
	(ctime): Update.
	(strftime): Update.
	* import/time_r.c: Update.
	* import/unistd--.h: Update.
	* import/unistd-safer.h: Update.
	* import/unistd.in.h (if): Update.
	(elif): Update.
	(__need_getopt): Update.
	(access): Update.
	(_GL_FUNCDECL_RPL): Update.
	(_GL_CXXALIAS_RPL): Update.
	(_GL_CXXALIAS_SYS): Update.
	(_GL_CXXALIASWARN): Update.
	(_GL_WARN_ON_USE): Update.
	(_GL_FUNCDECL_SYS): Update.
	(__declspec): Update.
	(_GL_WARN_ON_USE_ATTRIBUTE): Update.
	(faccessat): Update.
	(getpass): Update.
	(truncate): Update.
	* import/unsetenv.c: Update.
	* import/verify.h (if): Update.
	(_GL_HAVE__STATIC_ASSERT): Update.
	(_GL_HAVE_STATIC_ASSERT): Update.
	(_GL_HAVE__STATIC_ASSERT1): Update.
	(_GL_HAVE_STATIC_ASSERT1): Update.
	(_GL_VERIFY): Update.
	(_Static_assert): Update.
	(_GL_HAS_BUILTIN_TRAP): Update.
	(_GL_HAS_BUILTIN_UNREACHABLE): Update.
	(verify_true): Update.
	(verify): Update.
	(__has_builtin): Update.
	(elif): Update.
	(assume): Update.
	* import/warn-on-use.h: Rename from import/extra/snippet/warn-on-use.h.
	* import/wchar.in.h (if): Update.
	(wcsftime): Update.
	(_GL_FUNCDECL_RPL): Update.
	(_GL_CXXALIAS_RPL): Update.
	(_GL_FUNCDECL_SYS): Update.
	(_GL_CXXALIAS_SYS): Update.
	(_GL_CXXALIASWARN): Update.
	(_GL_WARN_ON_USE): Update.
	* import/wctype.in.h (rpl_iswalnum): Update.
	(rpl_iswalpha): Update.
	(rpl_iswblank): Update.
	(rpl_iswcntrl): Update.
	(rpl_iswdigit): Update.
	(rpl_iswgraph): Update.
	(rpl_iswlower): Update.
	(rpl_iswprint): Update.
	(rpl_iswpunct): Update.
	(rpl_iswspace): Update.
	(rpl_iswupper): Update.
	(rpl_iswxdigit): Update.
	(rpl_towlower): Update.
	(rpl_towupper): Update.
	(iswalnum): Update.
	(iswalpha): Update.
	(iswblank): Update.
	(iswcntrl): Update.
	(iswdigit): Update.
	(iswgraph): Update.
	(iswlower): Update.
	(iswprint): Update.
	(iswpunct): Update.
	(iswspace): Update.
	(iswupper): Update.
	(iswxdigit): Update.
	(towlower): Update.
	(towupper): Update.
	* import/windows-initguard.h: New file.
	* import/windows-mutex.c: New file.
	* import/windows-mutex.h: New file.
	* import/windows-once.c: New file.
	* import/windows-once.h: New file.
	* import/windows-recmutex.c: New file.
	* import/windows-recmutex.h: New file.
	* import/windows-rwlock.c: New file.
	* import/windows-rwlock.h: New file.
	* import/xalloc-oversized.h: New file.
	* patches/0001-Fix-PR-gdb-23558-Use-system-s-getcwd-when-cross-comp.patch: Remove.
	* patches/0002-mkostemp-mkostemps-Fix-compilation-error-in-C-mode-o.patch: Remove.
	* patches/0003-Fix-glob-c-Coverity-issues.patch: Remove.
	* update-gnulib.sh: Update to latest gnulib and don't apply patches
	anymore.  Also updates the patch -p flag to the current directory structure in
	case patches are needed again in the future.

Change-Id: I9c2b07a3046baecfb664e21b2644353ea888dbfa
2019-12-16 12:20:50 -06:00

1139 lines
38 KiB
C

/* Determine a canonical name for the current locale's character encoding.
Copyright (C) 2000-2006, 2008-2019 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3, or (at your option)
any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, see <https://www.gnu.org/licenses/>. */
/* Written by Bruno Haible <bruno@clisp.org>. */
#include <config.h>
/* Specification. */
#include "localcharset.h"
#include <stddef.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#if defined __APPLE__ && defined __MACH__ && HAVE_LANGINFO_CODESET
# define DARWIN7 /* Darwin 7 or newer, i.e. Mac OS X 10.3 or newer */
#endif
#if defined _WIN32 && !defined __CYGWIN__
# define WINDOWS_NATIVE
# include <locale.h>
#endif
#if defined __EMX__
/* Assume EMX program runs on OS/2, even if compiled under DOS. */
# ifndef OS2
# define OS2
# endif
#endif
#if !defined WINDOWS_NATIVE
# if HAVE_LANGINFO_CODESET
# include <langinfo.h>
# else
# if 0 /* see comment regarding use of setlocale(), below */
# include <locale.h>
# endif
# endif
# ifdef __CYGWIN__
# define WIN32_LEAN_AND_MEAN
# include <windows.h>
# endif
#elif defined WINDOWS_NATIVE
# define WIN32_LEAN_AND_MEAN
# include <windows.h>
#endif
#if defined OS2
# define INCL_DOS
# include <os2.h>
#endif
/* For MB_CUR_MAX_L */
#if defined DARWIN7
# include <xlocale.h>
#endif
#if HAVE_LANGINFO_CODESET || defined WINDOWS_NATIVE || defined OS2
/* On these platforms, we use a mapping from non-canonical encoding name
to GNU canonical encoding name. */
/* With glibc-2.1 or newer, we don't need any canonicalization,
because glibc has iconv and both glibc and libiconv support all
GNU canonical names directly. */
# if !((defined __GNU_LIBRARY__ && __GLIBC__ >= 2) || defined __UCLIBC__)
struct table_entry
{
const char alias[11+1];
const char canonical[11+1];
};
/* Table of platform-dependent mappings, sorted in ascending order. */
static const struct table_entry alias_table[] =
{
# if defined __FreeBSD__ /* FreeBSD */
/*{ "ARMSCII-8", "ARMSCII-8" },*/
{ "Big5", "BIG5" },
{ "C", "ASCII" },
/*{ "CP1131", "CP1131" },*/
/*{ "CP1251", "CP1251" },*/
/*{ "CP866", "CP866" },*/
/*{ "GB18030", "GB18030" },*/
/*{ "GB2312", "GB2312" },*/
/*{ "GBK", "GBK" },*/
/*{ "ISCII-DEV", "?" },*/
{ "ISO8859-1", "ISO-8859-1" },
{ "ISO8859-13", "ISO-8859-13" },
{ "ISO8859-15", "ISO-8859-15" },
{ "ISO8859-2", "ISO-8859-2" },
{ "ISO8859-5", "ISO-8859-5" },
{ "ISO8859-7", "ISO-8859-7" },
{ "ISO8859-9", "ISO-8859-9" },
/*{ "KOI8-R", "KOI8-R" },*/
/*{ "KOI8-U", "KOI8-U" },*/
{ "SJIS", "SHIFT_JIS" },
{ "US-ASCII", "ASCII" },
{ "eucCN", "GB2312" },
{ "eucJP", "EUC-JP" },
{ "eucKR", "EUC-KR" }
# define alias_table_defined
# endif
# if defined __NetBSD__ /* NetBSD */
{ "646", "ASCII" },
/*{ "ARMSCII-8", "ARMSCII-8" },*/
/*{ "BIG5", "BIG5" },*/
{ "Big5-HKSCS", "BIG5-HKSCS" },
/*{ "CP1251", "CP1251" },*/
/*{ "CP866", "CP866" },*/
/*{ "GB18030", "GB18030" },*/
/*{ "GB2312", "GB2312" },*/
{ "ISO8859-1", "ISO-8859-1" },
{ "ISO8859-13", "ISO-8859-13" },
{ "ISO8859-15", "ISO-8859-15" },
{ "ISO8859-2", "ISO-8859-2" },
{ "ISO8859-4", "ISO-8859-4" },
{ "ISO8859-5", "ISO-8859-5" },
{ "ISO8859-7", "ISO-8859-7" },
/*{ "KOI8-R", "KOI8-R" },*/
/*{ "KOI8-U", "KOI8-U" },*/
/*{ "PT154", "PT154" },*/
{ "SJIS", "SHIFT_JIS" },
{ "eucCN", "GB2312" },
{ "eucJP", "EUC-JP" },
{ "eucKR", "EUC-KR" },
{ "eucTW", "EUC-TW" }
# define alias_table_defined
# endif
# if defined __OpenBSD__ /* OpenBSD */
{ "646", "ASCII" },
{ "ISO8859-1", "ISO-8859-1" },
{ "ISO8859-13", "ISO-8859-13" },
{ "ISO8859-15", "ISO-8859-15" },
{ "ISO8859-2", "ISO-8859-2" },
{ "ISO8859-4", "ISO-8859-4" },
{ "ISO8859-5", "ISO-8859-5" },
{ "ISO8859-7", "ISO-8859-7" }
# define alias_table_defined
# endif
# if defined __APPLE__ && defined __MACH__ /* Mac OS X */
/* Darwin 7.5 has nl_langinfo(CODESET), but sometimes its value is
useless:
- It returns the empty string when LANG is set to a locale of the
form ll_CC, although ll_CC/LC_CTYPE is a symlink to an UTF-8
LC_CTYPE file.
- The environment variables LANG, LC_CTYPE, LC_ALL are not set by
the system; nl_langinfo(CODESET) returns "US-ASCII" in this case.
- The documentation says:
"... all code that calls BSD system routines should ensure
that the const *char parameters of these routines are in UTF-8
encoding. All BSD system functions expect their string
parameters to be in UTF-8 encoding and nothing else."
It also says
"An additional caveat is that string parameters for files,
paths, and other file-system entities must be in canonical
UTF-8. In a canonical UTF-8 Unicode string, all decomposable
characters are decomposed ..."
but this is not true: You can pass non-decomposed UTF-8 strings
to file system functions, and it is the OS which will convert
them to decomposed UTF-8 before accessing the file system.
- The Apple Terminal application displays UTF-8 by default.
- However, other applications are free to use different encodings:
- xterm uses ISO-8859-1 by default.
- TextEdit uses MacRoman by default.
We prefer UTF-8 over decomposed UTF-8-MAC because one should
minimize the use of decomposed Unicode. Unfortunately, through the
Darwin file system, decomposed UTF-8 strings are leaked into user
space nevertheless.
Then there are also the locales with encodings other than US-ASCII
and UTF-8. These locales can be occasionally useful to users (e.g.
when grepping through ISO-8859-1 encoded text files), when all their
file names are in US-ASCII.
*/
{ "ARMSCII-8", "ARMSCII-8" },
{ "Big5", "BIG5" },
{ "Big5HKSCS", "BIG5-HKSCS" },
{ "CP1131", "CP1131" },
{ "CP1251", "CP1251" },
{ "CP866", "CP866" },
{ "CP949", "CP949" },
{ "GB18030", "GB18030" },
{ "GB2312", "GB2312" },
{ "GBK", "GBK" },
/*{ "ISCII-DEV", "?" },*/
{ "ISO8859-1", "ISO-8859-1" },
{ "ISO8859-13", "ISO-8859-13" },
{ "ISO8859-15", "ISO-8859-15" },
{ "ISO8859-2", "ISO-8859-2" },
{ "ISO8859-4", "ISO-8859-4" },
{ "ISO8859-5", "ISO-8859-5" },
{ "ISO8859-7", "ISO-8859-7" },
{ "ISO8859-9", "ISO-8859-9" },
{ "KOI8-R", "KOI8-R" },
{ "KOI8-U", "KOI8-U" },
{ "PT154", "PT154" },
{ "SJIS", "SHIFT_JIS" },
{ "eucCN", "GB2312" },
{ "eucJP", "EUC-JP" },
{ "eucKR", "EUC-KR" }
# define alias_table_defined
# endif
# if defined _AIX /* AIX */
/*{ "GBK", "GBK" },*/
{ "IBM-1046", "CP1046" },
{ "IBM-1124", "CP1124" },
{ "IBM-1129", "CP1129" },
{ "IBM-1252", "CP1252" },
{ "IBM-850", "CP850" },
{ "IBM-856", "CP856" },
{ "IBM-921", "ISO-8859-13" },
{ "IBM-922", "CP922" },
{ "IBM-932", "CP932" },
{ "IBM-943", "CP943" },
{ "IBM-eucCN", "GB2312" },
{ "IBM-eucJP", "EUC-JP" },
{ "IBM-eucKR", "EUC-KR" },
{ "IBM-eucTW", "EUC-TW" },
{ "ISO8859-1", "ISO-8859-1" },
{ "ISO8859-15", "ISO-8859-15" },
{ "ISO8859-2", "ISO-8859-2" },
{ "ISO8859-5", "ISO-8859-5" },
{ "ISO8859-6", "ISO-8859-6" },
{ "ISO8859-7", "ISO-8859-7" },
{ "ISO8859-8", "ISO-8859-8" },
{ "ISO8859-9", "ISO-8859-9" },
{ "TIS-620", "TIS-620" },
/*{ "UTF-8", "UTF-8" },*/
{ "big5", "BIG5" }
# define alias_table_defined
# endif
# if defined __hpux /* HP-UX */
{ "SJIS", "SHIFT_JIS" },
{ "arabic8", "HP-ARABIC8" },
{ "big5", "BIG5" },
{ "cp1251", "CP1251" },
{ "eucJP", "EUC-JP" },
{ "eucKR", "EUC-KR" },
{ "eucTW", "EUC-TW" },
{ "gb18030", "GB18030" },
{ "greek8", "HP-GREEK8" },
{ "hebrew8", "HP-HEBREW8" },
{ "hkbig5", "BIG5-HKSCS" },
{ "hp15CN", "GB2312" },
{ "iso88591", "ISO-8859-1" },
{ "iso885913", "ISO-8859-13" },
{ "iso885915", "ISO-8859-15" },
{ "iso88592", "ISO-8859-2" },
{ "iso88594", "ISO-8859-4" },
{ "iso88595", "ISO-8859-5" },
{ "iso88596", "ISO-8859-6" },
{ "iso88597", "ISO-8859-7" },
{ "iso88598", "ISO-8859-8" },
{ "iso88599", "ISO-8859-9" },
{ "kana8", "HP-KANA8" },
{ "koi8r", "KOI8-R" },
{ "roman8", "HP-ROMAN8" },
{ "tis620", "TIS-620" },
{ "turkish8", "HP-TURKISH8" },
{ "utf8", "UTF-8" }
# define alias_table_defined
# endif
# if defined __sgi /* IRIX */
{ "ISO8859-1", "ISO-8859-1" },
{ "ISO8859-15", "ISO-8859-15" },
{ "ISO8859-2", "ISO-8859-2" },
{ "ISO8859-5", "ISO-8859-5" },
{ "ISO8859-7", "ISO-8859-7" },
{ "ISO8859-9", "ISO-8859-9" },
{ "eucCN", "GB2312" },
{ "eucJP", "EUC-JP" },
{ "eucKR", "EUC-KR" },
{ "eucTW", "EUC-TW" }
# define alias_table_defined
# endif
# if defined __osf__ /* OSF/1 */
/*{ "GBK", "GBK" },*/
{ "ISO8859-1", "ISO-8859-1" },
{ "ISO8859-15", "ISO-8859-15" },
{ "ISO8859-2", "ISO-8859-2" },
{ "ISO8859-4", "ISO-8859-4" },
{ "ISO8859-5", "ISO-8859-5" },
{ "ISO8859-7", "ISO-8859-7" },
{ "ISO8859-8", "ISO-8859-8" },
{ "ISO8859-9", "ISO-8859-9" },
{ "KSC5601", "CP949" },
{ "SJIS", "SHIFT_JIS" },
{ "TACTIS", "TIS-620" },
/*{ "UTF-8", "UTF-8" },*/
{ "big5", "BIG5" },
{ "cp850", "CP850" },
{ "dechanyu", "DEC-HANYU" },
{ "dechanzi", "GB2312" },
{ "deckanji", "DEC-KANJI" },
{ "deckorean", "EUC-KR" },
{ "eucJP", "EUC-JP" },
{ "eucKR", "EUC-KR" },
{ "eucTW", "EUC-TW" },
{ "sdeckanji", "EUC-JP" }
# define alias_table_defined
# endif
# if defined __sun /* Solaris */
{ "5601", "EUC-KR" },
{ "646", "ASCII" },
/*{ "BIG5", "BIG5" },*/
{ "Big5-HKSCS", "BIG5-HKSCS" },
{ "GB18030", "GB18030" },
/*{ "GBK", "GBK" },*/
{ "ISO8859-1", "ISO-8859-1" },
{ "ISO8859-11", "TIS-620" },
{ "ISO8859-13", "ISO-8859-13" },
{ "ISO8859-15", "ISO-8859-15" },
{ "ISO8859-2", "ISO-8859-2" },
{ "ISO8859-3", "ISO-8859-3" },
{ "ISO8859-4", "ISO-8859-4" },
{ "ISO8859-5", "ISO-8859-5" },
{ "ISO8859-6", "ISO-8859-6" },
{ "ISO8859-7", "ISO-8859-7" },
{ "ISO8859-8", "ISO-8859-8" },
{ "ISO8859-9", "ISO-8859-9" },
{ "PCK", "SHIFT_JIS" },
{ "TIS620.2533", "TIS-620" },
/*{ "UTF-8", "UTF-8" },*/
{ "ansi-1251", "CP1251" },
{ "cns11643", "EUC-TW" },
{ "eucJP", "EUC-JP" },
{ "gb2312", "GB2312" },
{ "koi8-r", "KOI8-R" }
# define alias_table_defined
# endif
# if defined __minix /* Minix */
{ "646", "ASCII" }
# define alias_table_defined
# endif
# if defined WINDOWS_NATIVE || defined __CYGWIN__ /* Windows */
{ "CP1361", "JOHAB" },
{ "CP20127", "ASCII" },
{ "CP20866", "KOI8-R" },
{ "CP20936", "GB2312" },
{ "CP21866", "KOI8-RU" },
{ "CP28591", "ISO-8859-1" },
{ "CP28592", "ISO-8859-2" },
{ "CP28593", "ISO-8859-3" },
{ "CP28594", "ISO-8859-4" },
{ "CP28595", "ISO-8859-5" },
{ "CP28596", "ISO-8859-6" },
{ "CP28597", "ISO-8859-7" },
{ "CP28598", "ISO-8859-8" },
{ "CP28599", "ISO-8859-9" },
{ "CP28605", "ISO-8859-15" },
{ "CP38598", "ISO-8859-8" },
{ "CP51932", "EUC-JP" },
{ "CP51936", "GB2312" },
{ "CP51949", "EUC-KR" },
{ "CP51950", "EUC-TW" },
{ "CP54936", "GB18030" },
{ "CP65001", "UTF-8" },
{ "CP936", "GBK" }
# define alias_table_defined
# endif
# if defined OS2 /* OS/2 */
/* 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 "__convcp() of kLIBC":
<https://github.com/bitwiseworks/libc/blob/master/src/emx/src/lib/locale/__convcp.c>. */
{ "CP1004", "CP1252" },
/*{ "CP1041", "CP943" },*/
/*{ "CP1088", "CP949" },*/
{ "CP1089", "ISO-8859-6" },
/*{ "CP1114", "CP950" },*/
/*{ "CP1115", "GB2312" },*/
{ "CP1208", "UTF-8" },
/*{ "CP1380", "GB2312" },*/
{ "CP1381", "GB2312" },
{ "CP1383", "GB2312" },
{ "CP1386", "GBK" },
/*{ "CP301", "CP943" },*/
{ "CP3372", "EUC-JP" },
{ "CP4946", "CP850" },
/*{ "CP5048", "JIS_X0208-1990" },*/
/*{ "CP5049", "JIS_X0212-1990" },*/
/*{ "CP5067", "KS_C_5601-1987" },*/
{ "CP813", "ISO-8859-7" },
{ "CP819", "ISO-8859-1" },
{ "CP878", "KOI8-R" },
/*{ "CP897", "CP943" },*/
{ "CP912", "ISO-8859-2" },
{ "CP913", "ISO-8859-3" },
{ "CP914", "ISO-8859-4" },
{ "CP915", "ISO-8859-5" },
{ "CP916", "ISO-8859-8" },
{ "CP920", "ISO-8859-9" },
{ "CP921", "ISO-8859-13" },
{ "CP923", "ISO-8859-15" },
/*{ "CP941", "CP943" },*/
/*{ "CP947", "CP950" },*/
/*{ "CP951", "CP949" },*/
/*{ "CP952", "JIS_X0208-1990" },*/
/*{ "CP953", "JIS_X0212-1990" },*/
{ "CP954", "EUC-JP" },
{ "CP964", "EUC-TW" },
{ "CP970", "EUC-KR" },
/*{ "CP971", "KS_C_5601-1987" },*/
{ "IBM-1004", "CP1252" },
/*{ "IBM-1006", "?" },*/
/*{ "IBM-1008", "?" },*/
/*{ "IBM-1041", "CP943" },*/
/*{ "IBM-1051", "?" },*/
/*{ "IBM-1088", "CP949" },*/
{ "IBM-1089", "ISO-8859-6" },
/*{ "IBM-1098", "?" },*/
/*{ "IBM-1114", "CP950" },*/
/*{ "IBM-1115", "GB2312" },*/
/*{ "IBM-1116", "?" },*/
/*{ "IBM-1117", "?" },*/
/*{ "IBM-1118", "?" },*/
/*{ "IBM-1119", "?" },*/
{ "IBM-1124", "CP1124" },
{ "IBM-1125", "CP1125" },
{ "IBM-1131", "CP1131" },
{ "IBM-1208", "UTF-8" },
{ "IBM-1250", "CP1250" },
{ "IBM-1251", "CP1251" },
{ "IBM-1252", "CP1252" },
{ "IBM-1253", "CP1253" },
{ "IBM-1254", "CP1254" },
{ "IBM-1255", "CP1255" },
{ "IBM-1256", "CP1256" },
{ "IBM-1257", "CP1257" },
/*{ "IBM-1275", "?" },*/
/*{ "IBM-1276", "?" },*/
/*{ "IBM-1277", "?" },*/
/*{ "IBM-1280", "?" },*/
/*{ "IBM-1281", "?" },*/
/*{ "IBM-1282", "?" },*/
/*{ "IBM-1283", "?" },*/
/*{ "IBM-1380", "GB2312" },*/
{ "IBM-1381", "GB2312" },
{ "IBM-1383", "GB2312" },
{ "IBM-1386", "GBK" },
/*{ "IBM-301", "CP943" },*/
{ "IBM-3372", "EUC-JP" },
{ "IBM-367", "ASCII" },
{ "IBM-437", "CP437" },
{ "IBM-4946", "CP850" },
/*{ "IBM-5048", "JIS_X0208-1990" },*/
/*{ "IBM-5049", "JIS_X0212-1990" },*/
/*{ "IBM-5067", "KS_C_5601-1987" },*/
{ "IBM-813", "ISO-8859-7" },
{ "IBM-819", "ISO-8859-1" },
{ "IBM-850", "CP850" },
/*{ "IBM-851", "?" },*/
{ "IBM-852", "CP852" },
{ "IBM-855", "CP855" },
{ "IBM-856", "CP856" },
{ "IBM-857", "CP857" },
/*{ "IBM-859", "?" },*/
{ "IBM-860", "CP860" },
{ "IBM-861", "CP861" },
{ "IBM-862", "CP862" },
{ "IBM-863", "CP863" },
{ "IBM-864", "CP864" },
{ "IBM-865", "CP865" },
{ "IBM-866", "CP866" },
/*{ "IBM-868", "?" },*/
{ "IBM-869", "CP869" },
{ "IBM-874", "CP874" },
{ "IBM-878", "KOI8-R" },
/*{ "IBM-895", "?" },*/
/*{ "IBM-897", "CP943" },*/
/*{ "IBM-907", "?" },*/
/*{ "IBM-909", "?" },*/
{ "IBM-912", "ISO-8859-2" },
{ "IBM-913", "ISO-8859-3" },
{ "IBM-914", "ISO-8859-4" },
{ "IBM-915", "ISO-8859-5" },
{ "IBM-916", "ISO-8859-8" },
{ "IBM-920", "ISO-8859-9" },
{ "IBM-921", "ISO-8859-13" },
{ "IBM-922", "CP922" },
{ "IBM-923", "ISO-8859-15" },
{ "IBM-932", "CP932" },
/*{ "IBM-941", "CP943" },*/
/*{ "IBM-942", "?" },*/
{ "IBM-943", "CP943" },
/*{ "IBM-947", "CP950" },*/
{ "IBM-949", "CP949" },
{ "IBM-950", "CP950" },
/*{ "IBM-951", "CP949" },*/
/*{ "IBM-952", "JIS_X0208-1990" },*/
/*{ "IBM-953", "JIS_X0212-1990" },*/
{ "IBM-954", "EUC-JP" },
/*{ "IBM-955", "?" },*/
{ "IBM-964", "EUC-TW" },
{ "IBM-970", "EUC-KR" },
/*{ "IBM-971", "KS_C_5601-1987" },*/
{ "IBM-eucCN", "GB2312" },
{ "IBM-eucJP", "EUC-JP" },
{ "IBM-eucKR", "EUC-KR" },
{ "IBM-eucTW", "EUC-TW" },
{ "IBM33722", "EUC-JP" },
{ "ISO8859-1", "ISO-8859-1" },
{ "ISO8859-2", "ISO-8859-2" },
{ "ISO8859-3", "ISO-8859-3" },
{ "ISO8859-4", "ISO-8859-4" },
{ "ISO8859-5", "ISO-8859-5" },
{ "ISO8859-6", "ISO-8859-6" },
{ "ISO8859-7", "ISO-8859-7" },
{ "ISO8859-8", "ISO-8859-8" },
{ "ISO8859-9", "ISO-8859-9" },
/*{ "JISX0201-1976", "JISX0201-1976" },*/
/*{ "JISX0208-1978", "?" },*/
/*{ "JISX0208-1983", "JIS_X0208-1983" },*/
/*{ "JISX0208-1990", "JIS_X0208-1990" },*/
/*{ "JISX0212-1990", "JIS_X0212-1990" },*/
/*{ "KSC5601-1987", "KS_C_5601-1987" },*/
{ "SJIS-1", "CP943" },
{ "SJIS-2", "CP943" },
{ "eucJP", "EUC-JP" },
{ "eucKR", "EUC-KR" },
{ "eucTW-1993", "EUC-TW" }
# define alias_table_defined
# endif
# if defined VMS /* OpenVMS */
/* The list of encodings is taken from the OpenVMS 7.3-1 documentation
"Compaq C Run-Time Library Reference Manual for OpenVMS systems"
section 10.7 "Handling Different Character Sets". */
{ "DECHANYU", "DEC-HANYU" },
{ "DECHANZI", "GB2312" },
{ "DECKANJI", "DEC-KANJI" },
{ "DECKOREAN", "EUC-KR" },
{ "ISO8859-1", "ISO-8859-1" },
{ "ISO8859-2", "ISO-8859-2" },
{ "ISO8859-5", "ISO-8859-5" },
{ "ISO8859-7", "ISO-8859-7" },
{ "ISO8859-8", "ISO-8859-8" },
{ "ISO8859-9", "ISO-8859-9" },
{ "SDECKANJI", "EUC-JP" },
{ "SJIS", "SHIFT_JIS" },
{ "eucJP", "EUC-JP" },
{ "eucTW", "EUC-TW" }
# define alias_table_defined
# endif
# ifndef alias_table_defined
/* Just a dummy entry, to avoid a C syntax error. */
{ "", "" }
# endif
};
# endif
#else
/* On these platforms, we use a mapping from locale name to GNU canonical
encoding name. */
struct table_entry
{
const char locale[17+1];
const char canonical[11+1];
};
/* Table of platform-dependent mappings, sorted in ascending order. */
static const struct table_entry locale_table[] =
{
# if defined __FreeBSD__ /* FreeBSD 4.2 */
{ "cs_CZ.ISO_8859-2", "ISO-8859-2" },
{ "da_DK.DIS_8859-15", "ISO-8859-15" },
{ "da_DK.ISO_8859-1", "ISO-8859-1" },
{ "de_AT.DIS_8859-15", "ISO-8859-15" },
{ "de_AT.ISO_8859-1", "ISO-8859-1" },
{ "de_CH.DIS_8859-15", "ISO-8859-15" },
{ "de_CH.ISO_8859-1", "ISO-8859-1" },
{ "de_DE.DIS_8859-15", "ISO-8859-15" },
{ "de_DE.ISO_8859-1", "ISO-8859-1" },
{ "en_AU.DIS_8859-15", "ISO-8859-15" },
{ "en_AU.ISO_8859-1", "ISO-8859-1" },
{ "en_CA.DIS_8859-15", "ISO-8859-15" },
{ "en_CA.ISO_8859-1", "ISO-8859-1" },
{ "en_GB.DIS_8859-15", "ISO-8859-15" },
{ "en_GB.ISO_8859-1", "ISO-8859-1" },
{ "en_US.DIS_8859-15", "ISO-8859-15" },
{ "en_US.ISO_8859-1", "ISO-8859-1" },
{ "es_ES.DIS_8859-15", "ISO-8859-15" },
{ "es_ES.ISO_8859-1", "ISO-8859-1" },
{ "fi_FI.DIS_8859-15", "ISO-8859-15" },
{ "fi_FI.ISO_8859-1", "ISO-8859-1" },
{ "fr_BE.DIS_8859-15", "ISO-8859-15" },
{ "fr_BE.ISO_8859-1", "ISO-8859-1" },
{ "fr_CA.DIS_8859-15", "ISO-8859-15" },
{ "fr_CA.ISO_8859-1", "ISO-8859-1" },
{ "fr_CH.DIS_8859-15", "ISO-8859-15" },
{ "fr_CH.ISO_8859-1", "ISO-8859-1" },
{ "fr_FR.DIS_8859-15", "ISO-8859-15" },
{ "fr_FR.ISO_8859-1", "ISO-8859-1" },
{ "hr_HR.ISO_8859-2", "ISO-8859-2" },
{ "hu_HU.ISO_8859-2", "ISO-8859-2" },
{ "is_IS.DIS_8859-15", "ISO-8859-15" },
{ "is_IS.ISO_8859-1", "ISO-8859-1" },
{ "it_CH.DIS_8859-15", "ISO-8859-15" },
{ "it_CH.ISO_8859-1", "ISO-8859-1" },
{ "it_IT.DIS_8859-15", "ISO-8859-15" },
{ "it_IT.ISO_8859-1", "ISO-8859-1" },
{ "ja_JP.EUC", "EUC-JP" },
{ "ja_JP.SJIS", "SHIFT_JIS" },
{ "ja_JP.Shift_JIS", "SHIFT_JIS" },
{ "ko_KR.EUC", "EUC-KR" },
{ "la_LN.ASCII", "ASCII" },
{ "la_LN.DIS_8859-15", "ISO-8859-15" },
{ "la_LN.ISO_8859-1", "ISO-8859-1" },
{ "la_LN.ISO_8859-2", "ISO-8859-2" },
{ "la_LN.ISO_8859-4", "ISO-8859-4" },
{ "lt_LN.ASCII", "ASCII" },
{ "lt_LN.DIS_8859-15", "ISO-8859-15" },
{ "lt_LN.ISO_8859-1", "ISO-8859-1" },
{ "lt_LN.ISO_8859-2", "ISO-8859-2" },
{ "lt_LT.ISO_8859-4", "ISO-8859-4" },
{ "nl_BE.DIS_8859-15", "ISO-8859-15" },
{ "nl_BE.ISO_8859-1", "ISO-8859-1" },
{ "nl_NL.DIS_8859-15", "ISO-8859-15" },
{ "nl_NL.ISO_8859-1", "ISO-8859-1" },
{ "no_NO.DIS_8859-15", "ISO-8859-15" },
{ "no_NO.ISO_8859-1", "ISO-8859-1" },
{ "pl_PL.ISO_8859-2", "ISO-8859-2" },
{ "pt_PT.DIS_8859-15", "ISO-8859-15" },
{ "pt_PT.ISO_8859-1", "ISO-8859-1" },
{ "ru_RU.CP866", "CP866" },
{ "ru_RU.ISO_8859-5", "ISO-8859-5" },
{ "ru_RU.KOI8-R", "KOI8-R" },
{ "ru_SU.CP866", "CP866" },
{ "ru_SU.ISO_8859-5", "ISO-8859-5" },
{ "ru_SU.KOI8-R", "KOI8-R" },
{ "sl_SI.ISO_8859-2", "ISO-8859-2" },
{ "sv_SE.DIS_8859-15", "ISO-8859-15" },
{ "sv_SE.ISO_8859-1", "ISO-8859-1" },
{ "uk_UA.KOI8-U", "KOI8-U" },
{ "zh_CN.EUC", "GB2312" },
{ "zh_TW.BIG5", "BIG5" },
{ "zh_TW.Big5", "BIG5" }
# define locale_table_defined
# endif
# if defined __DJGPP__ /* DOS / DJGPP 2.03 */
/* The encodings given here may not all be correct.
If you find that the encoding given for your language and
country is not the one your DOS machine actually uses, just
correct it in this file, and send a mail to
Juan Manuel Guerrero <juan.guerrero@gmx.de>
and <bug-gnulib@gnu.org>. */
{ "C", "ASCII" },
{ "ar", "CP864" },
{ "ar_AE", "CP864" },
{ "ar_DZ", "CP864" },
{ "ar_EG", "CP864" },
{ "ar_IQ", "CP864" },
{ "ar_IR", "CP864" },
{ "ar_JO", "CP864" },
{ "ar_KW", "CP864" },
{ "ar_MA", "CP864" },
{ "ar_OM", "CP864" },
{ "ar_QA", "CP864" },
{ "ar_SA", "CP864" },
{ "ar_SY", "CP864" },
{ "be", "CP866" },
{ "be_BE", "CP866" },
{ "bg", "CP866" }, /* not CP855 ?? */
{ "bg_BG", "CP866" }, /* not CP855 ?? */
{ "ca", "CP850" },
{ "ca_ES", "CP850" },
{ "cs", "CP852" },
{ "cs_CZ", "CP852" },
{ "da", "CP865" }, /* not CP850 ?? */
{ "da_DK", "CP865" }, /* not CP850 ?? */
{ "de", "CP850" },
{ "de_AT", "CP850" },
{ "de_CH", "CP850" },
{ "de_DE", "CP850" },
{ "el", "CP869" },
{ "el_GR", "CP869" },
{ "en", "CP850" },
{ "en_AU", "CP850" }, /* not CP437 ?? */
{ "en_CA", "CP850" },
{ "en_GB", "CP850" },
{ "en_NZ", "CP437" },
{ "en_US", "CP437" },
{ "en_ZA", "CP850" }, /* not CP437 ?? */
{ "eo", "CP850" },
{ "eo_EO", "CP850" },
{ "es", "CP850" },
{ "es_AR", "CP850" },
{ "es_BO", "CP850" },
{ "es_CL", "CP850" },
{ "es_CO", "CP850" },
{ "es_CR", "CP850" },
{ "es_CU", "CP850" },
{ "es_DO", "CP850" },
{ "es_EC", "CP850" },
{ "es_ES", "CP850" },
{ "es_GT", "CP850" },
{ "es_HN", "CP850" },
{ "es_MX", "CP850" },
{ "es_NI", "CP850" },
{ "es_PA", "CP850" },
{ "es_PE", "CP850" },
{ "es_PY", "CP850" },
{ "es_SV", "CP850" },
{ "es_UY", "CP850" },
{ "es_VE", "CP850" },
{ "et", "CP850" },
{ "et_EE", "CP850" },
{ "eu", "CP850" },
{ "eu_ES", "CP850" },
{ "fi", "CP850" },
{ "fi_FI", "CP850" },
{ "fr", "CP850" },
{ "fr_BE", "CP850" },
{ "fr_CA", "CP850" },
{ "fr_CH", "CP850" },
{ "fr_FR", "CP850" },
{ "ga", "CP850" },
{ "ga_IE", "CP850" },
{ "gd", "CP850" },
{ "gd_GB", "CP850" },
{ "gl", "CP850" },
{ "gl_ES", "CP850" },
{ "he", "CP862" },
{ "he_IL", "CP862" },
{ "hr", "CP852" },
{ "hr_HR", "CP852" },
{ "hu", "CP852" },
{ "hu_HU", "CP852" },
{ "id", "CP850" }, /* not CP437 ?? */
{ "id_ID", "CP850" }, /* not CP437 ?? */
{ "is", "CP861" }, /* not CP850 ?? */
{ "is_IS", "CP861" }, /* not CP850 ?? */
{ "it", "CP850" },
{ "it_CH", "CP850" },
{ "it_IT", "CP850" },
{ "ja", "CP932" },
{ "ja_JP", "CP932" },
{ "kr", "CP949" }, /* not CP934 ?? */
{ "kr_KR", "CP949" }, /* not CP934 ?? */
{ "lt", "CP775" },
{ "lt_LT", "CP775" },
{ "lv", "CP775" },
{ "lv_LV", "CP775" },
{ "mk", "CP866" }, /* not CP855 ?? */
{ "mk_MK", "CP866" }, /* not CP855 ?? */
{ "mt", "CP850" },
{ "mt_MT", "CP850" },
{ "nb", "CP865" }, /* not CP850 ?? */
{ "nb_NO", "CP865" }, /* not CP850 ?? */
{ "nl", "CP850" },
{ "nl_BE", "CP850" },
{ "nl_NL", "CP850" },
{ "nn", "CP865" }, /* not CP850 ?? */
{ "nn_NO", "CP865" }, /* not CP850 ?? */
{ "no", "CP865" }, /* not CP850 ?? */
{ "no_NO", "CP865" }, /* not CP850 ?? */
{ "pl", "CP852" },
{ "pl_PL", "CP852" },
{ "pt", "CP850" },
{ "pt_BR", "CP850" },
{ "pt_PT", "CP850" },
{ "ro", "CP852" },
{ "ro_RO", "CP852" },
{ "ru", "CP866" },
{ "ru_RU", "CP866" },
{ "sk", "CP852" },
{ "sk_SK", "CP852" },
{ "sl", "CP852" },
{ "sl_SI", "CP852" },
{ "sq", "CP852" },
{ "sq_AL", "CP852" },
{ "sr", "CP852" }, /* CP852 or CP866 or CP855 ?? */
{ "sr_CS", "CP852" }, /* CP852 or CP866 or CP855 ?? */
{ "sr_YU", "CP852" }, /* CP852 or CP866 or CP855 ?? */
{ "sv", "CP850" },
{ "sv_SE", "CP850" },
{ "th", "CP874" },
{ "th_TH", "CP874" },
{ "tr", "CP857" },
{ "tr_TR", "CP857" },
{ "uk", "CP1125" },
{ "uk_UA", "CP1125" },
{ "zh_CN", "GBK" },
{ "zh_TW", "CP950" } /* not CP938 ?? */
# define locale_table_defined
# endif
# ifndef locale_table_defined
/* Just a dummy entry, to avoid a C syntax error. */
{ "", "" }
# endif
};
#endif
/* Determine the current locale's character encoding, and canonicalize it
into one of the canonical names listed in localcharset.h.
The result must not be freed; it is statically allocated.
If the canonical name cannot be determined, the result is a non-canonical
name. */
#ifdef STATIC
STATIC
#endif
const char *
locale_charset (void)
{
const char *codeset;
#if HAVE_LANGINFO_CODESET || defined WINDOWS_NATIVE || defined OS2
# if HAVE_LANGINFO_CODESET
/* Most systems support nl_langinfo (CODESET) nowadays. */
codeset = nl_langinfo (CODESET);
# ifdef __CYGWIN__
/* Cygwin < 1.7 does not have locales. nl_langinfo (CODESET) always
returns "US-ASCII". Return the suffix of the locale name from the
environment variables (if present) or the codepage as a number. */
if (codeset != NULL && strcmp (codeset, "US-ASCII") == 0)
{
const char *locale;
static char buf[2 + 10 + 1];
locale = getenv ("LC_ALL");
if (locale == NULL || locale[0] == '\0')
{
locale = getenv ("LC_CTYPE");
if (locale == NULL || locale[0] == '\0')
locale = getenv ("LANG");
}
if (locale != NULL && locale[0] != '\0')
{
/* If the locale name contains an encoding after the dot, return
it. */
const char *dot = strchr (locale, '.');
if (dot != NULL)
{
const char *modifier;
dot++;
/* Look for the possible @... trailer and remove it, if any. */
modifier = strchr (dot, '@');
if (modifier == NULL)
return dot;
if (modifier - dot < sizeof (buf))
{
memcpy (buf, dot, modifier - dot);
buf [modifier - dot] = '\0';
return buf;
}
}
}
/* The Windows API has a function returning the locale's codepage as a
number: GetACP(). This encoding is used by Cygwin, unless the user
has set the environment variable CYGWIN=codepage:oem (which very few
people do).
Output directed to console windows needs to be converted (to
GetOEMCP() if the console is using a raster font, or to
GetConsoleOutputCP() if it is using a TrueType font). Cygwin does
this conversion transparently (see winsup/cygwin/fhandler_console.cc),
converting to GetConsoleOutputCP(). This leads to correct results,
except when SetConsoleOutputCP has been called and a raster font is
in use. */
sprintf (buf, "CP%u", GetACP ());
codeset = buf;
}
# endif
if (codeset == NULL)
/* The canonical name cannot be determined. */
codeset = "";
# elif defined WINDOWS_NATIVE
static char buf[2 + 10 + 1];
/* 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 ());
}
/* For a locale name such as "French_France.65001", in Windows 10,
setlocale now returns "French_France.utf8" instead. */
if (strcmp (buf + 2, "65001") == 0 || strcmp (buf + 2, "utf8") == 0)
codeset = "UTF-8";
else
codeset = buf;
# elif defined OS2
const char *locale;
static char buf[2 + 10 + 1];
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");
if (locale == NULL || locale[0] == '\0')
{
locale = getenv ("LC_CTYPE");
if (locale == NULL || locale[0] == '\0')
locale = getenv ("LANG");
}
if (locale != NULL && locale[0] != '\0')
{
/* If the locale name contains an encoding after the dot, return it. */
const char *dot = strchr (locale, '.');
if (dot != NULL)
{
const char *modifier;
dot++;
/* Look for the possible @... trailer and remove it, if any. */
modifier = strchr (dot, '@');
if (modifier == NULL)
return dot;
if (modifier - dot < sizeof (buf))
{
memcpy (buf, dot, modifier - dot);
buf [modifier - dot] = '\0';
return buf;
}
}
/* For the POSIX locale, don't use the system's codepage. */
if (strcmp (locale, "C") == 0 || strcmp (locale, "POSIX") == 0)
codeset = "";
}
if (codeset == NULL)
{
/* OS/2 has a function returning the locale's codepage as a number. */
if (DosQueryCp (sizeof (cp), cp, &cplen))
codeset = "";
else
{
sprintf (buf, "CP%u", cp[0]);
codeset = buf;
}
}
# else
# error "Add code for other platforms here."
# endif
/* Resolve alias. */
{
# ifdef alias_table_defined
/* On some platforms, UTF-8 locales are the most frequently used ones.
Speed up the common case and slow down the less common cases by
testing for this case first. */
# if defined __OpenBSD__ || (defined __APPLE__ && defined __MACH__) || defined __sun || defined __CYGWIN__
if (strcmp (codeset, "UTF-8") == 0)
goto done_table_lookup;
else
# endif
{
const struct table_entry * const table = alias_table;
size_t const table_size =
sizeof (alias_table) / sizeof (struct table_entry);
/* The table is sorted. Perform a binary search. */
size_t hi = table_size;
size_t lo = 0;
while (lo < hi)
{
/* Invariant:
for i < lo, strcmp (table[i].alias, codeset) < 0,
for i >= hi, strcmp (table[i].alias, codeset) > 0. */
size_t mid = (hi + lo) >> 1; /* >= lo, < hi */
int cmp = strcmp (table[mid].alias, codeset);
if (cmp < 0)
lo = mid + 1;
else if (cmp > 0)
hi = mid;
else
{
/* Found an i with
strcmp (table[i].alias, codeset) == 0. */
codeset = table[mid].canonical;
goto done_table_lookup;
}
}
}
if (0)
done_table_lookup: ;
else
# endif
{
/* Did not find it in the table. */
/* On Mac OS X, all modern locales use the UTF-8 encoding.
BeOS and Haiku have a single locale, and it has UTF-8 encoding. */
# if (defined __APPLE__ && defined __MACH__) || defined __BEOS__ || defined __HAIKU__
codeset = "UTF-8";
# else
/* Don't return an empty string. GNU libc and GNU libiconv interpret
the empty string as denoting "the locale's character encoding",
thus GNU libiconv would call this function a second time. */
if (codeset[0] == '\0')
codeset = "ASCII";
# endif
}
}
#else
/* On old systems which lack it, use setlocale or getenv. */
const char *locale = NULL;
/* But most old systems don't have a complete set of locales. Some
(like DJGPP) have only the C locale. Therefore we don't use setlocale
here; it would return "C" when it doesn't support the locale name the
user has set. */
# if 0
locale = setlocale (LC_CTYPE, NULL);
# endif
if (locale == NULL || locale[0] == '\0')
{
locale = getenv ("LC_ALL");
if (locale == NULL || locale[0] == '\0')
{
locale = getenv ("LC_CTYPE");
if (locale == NULL || locale[0] == '\0')
locale = getenv ("LANG");
if (locale == NULL)
locale = "";
}
}
/* Map locale name to canonical encoding name. */
{
# ifdef locale_table_defined
const struct table_entry * const table = locale_table;
size_t const table_size =
sizeof (locale_table) / sizeof (struct table_entry);
/* The table is sorted. Perform a binary search. */
size_t hi = table_size;
size_t lo = 0;
while (lo < hi)
{
/* Invariant:
for i < lo, strcmp (table[i].locale, locale) < 0,
for i >= hi, strcmp (table[i].locale, locale) > 0. */
size_t mid = (hi + lo) >> 1; /* >= lo, < hi */
int cmp = strcmp (table[mid].locale, locale);
if (cmp < 0)
lo = mid + 1;
else if (cmp > 0)
hi = mid;
else
{
/* Found an i with
strcmp (table[i].locale, locale) == 0. */
codeset = table[mid].canonical;
goto done_table_lookup;
}
}
if (0)
done_table_lookup: ;
else
# endif
{
/* Did not find it in the table. */
/* On Mac OS X, all modern locales use the UTF-8 encoding.
BeOS and Haiku have a single locale, and it has UTF-8 encoding. */
# if (defined __APPLE__ && defined __MACH__) || defined __BEOS__ || defined __HAIKU__
codeset = "UTF-8";
# else
/* The canonical name cannot be determined. */
/* Don't return an empty string. GNU libc and GNU libiconv interpret
the empty string as denoting "the locale's character encoding",
thus GNU libiconv would call this function a second time. */
codeset = "ASCII";
# endif
}
}
#endif
#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;
}