1997-02-15 04:31:36 +00:00
|
|
|
/* Duplicate handle for selection of locales.
|
2019-01-01 00:11:28 +00:00
|
|
|
Copyright (C) 1997-2019 Free Software Foundation, Inc.
|
1997-02-15 04:31:36 +00:00
|
|
|
This file is part of the GNU C Library.
|
|
|
|
Contributed by Ulrich Drepper <drepper@cygnus.com>, 1997.
|
|
|
|
|
|
|
|
The GNU C Library is free software; you can redistribute it and/or
|
2001-07-06 04:58:11 +00:00
|
|
|
modify it under the terms of the GNU Lesser General Public
|
|
|
|
License as published by the Free Software Foundation; either
|
|
|
|
version 2.1 of the License, or (at your option) any later version.
|
1997-02-15 04:31:36 +00:00
|
|
|
|
|
|
|
The GNU C Library 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
|
2001-07-06 04:58:11 +00:00
|
|
|
Lesser General Public License for more details.
|
1997-02-15 04:31:36 +00:00
|
|
|
|
2001-07-06 04:58:11 +00:00
|
|
|
You should have received a copy of the GNU Lesser General Public
|
2012-02-09 23:18:22 +00:00
|
|
|
License along with the GNU C Library; if not, see
|
|
|
|
<http://www.gnu.org/licenses/>. */
|
1997-02-15 04:31:36 +00:00
|
|
|
|
|
|
|
#include <locale.h>
|
2015-09-08 21:11:03 +00:00
|
|
|
#include <libc-lock.h>
|
1997-02-15 04:31:36 +00:00
|
|
|
#include <stdlib.h>
|
2002-08-30 22:07:28 +00:00
|
|
|
#include <string.h>
|
1997-02-15 04:31:36 +00:00
|
|
|
|
|
|
|
#include <localeinfo.h>
|
|
|
|
|
|
|
|
|
|
|
|
/* Lock for protecting global data. */
|
2008-03-31 00:38:06 +00:00
|
|
|
__libc_rwlock_define (extern , __libc_setlocale_lock attribute_hidden)
|
1997-02-15 04:31:36 +00:00
|
|
|
|
|
|
|
|
Use locale_t, not __locale_t, throughout glibc
<locale.h> is specified to define locale_t in POSIX.1-2008, and so are
all of the headers that define functions that take locale_t arguments.
Under _GNU_SOURCE, the additional headers that define such functions
have also always defined locale_t. Therefore, there is no need to use
__locale_t in public function prototypes, nor in any internal code.
* ctype/ctype-c99_l.c, ctype/ctype.h, ctype/ctype_l.c
* include/monetary.h, include/stdlib.h, include/time.h
* include/wchar.h, locale/duplocale.c, locale/freelocale.c
* locale/global-locale.c, locale/langinfo.h, locale/locale.h
* locale/localeinfo.h, locale/newlocale.c
* locale/nl_langinfo_l.c, locale/uselocale.c
* localedata/bug-usesetlocale.c, localedata/tst-xlocale2.c
* stdio-common/vfscanf.c, stdlib/monetary.h, stdlib/stdlib.h
* stdlib/strfmon_l.c, stdlib/strtod_l.c, stdlib/strtof_l.c
* stdlib/strtol.c, stdlib/strtol_l.c, stdlib/strtold_l.c
* stdlib/strtoll_l.c, stdlib/strtoul_l.c, stdlib/strtoull_l.c
* string/strcasecmp.c, string/strcoll_l.c, string/string.h
* string/strings.h, string/strncase.c, string/strxfrm_l.c
* sysdeps/ieee754/float128/strtof128_l.c
* sysdeps/ieee754/float128/wcstof128.c
* sysdeps/ieee754/float128/wcstof128_l.c
* sysdeps/ieee754/ldbl-128ibm/strtold_l.c
* sysdeps/ieee754/ldbl-64-128/strtold_l.c
* sysdeps/ieee754/ldbl-opt/nldbl-compat.c
* sysdeps/ieee754/ldbl-opt/nldbl-strfmon_l.c
* sysdeps/ieee754/ldbl-opt/nldbl-strtold_l.c
* sysdeps/ieee754/ldbl-opt/nldbl-wcstold_l.c
* sysdeps/powerpc/powerpc32/power7/strcasecmp.S
* sysdeps/powerpc/powerpc64/power7/strcasecmp.S
* sysdeps/x86_64/strcasecmp_l-nonascii.c
* sysdeps/x86_64/strncase_l-nonascii.c, time/strftime_l.c
* time/strptime_l.c, time/time.h, wcsmbs/mbsrtowcs_l.c
* wcsmbs/wchar.h, wcsmbs/wcscasecmp.c, wcsmbs/wcsncase.c
* wcsmbs/wcstod.c, wcsmbs/wcstod_l.c, wcsmbs/wcstof.c
* wcsmbs/wcstof_l.c, wcsmbs/wcstol_l.c, wcsmbs/wcstold.c
* wcsmbs/wcstold_l.c, wcsmbs/wcstoll_l.c, wcsmbs/wcstoul_l.c
* wcsmbs/wcstoull_l.c, wctype/iswctype_l.c
* wctype/towctrans_l.c, wctype/wcfuncs_l.c
* wctype/wctrans_l.c, wctype/wctype.h, wctype/wctype_l.c:
Change all uses of __locale_t to locale_t.
2017-06-20 13:26:43 +00:00
|
|
|
locale_t
|
|
|
|
__duplocale (locale_t dataset)
|
1997-02-15 04:31:36 +00:00
|
|
|
{
|
2002-10-11 07:22:18 +00:00
|
|
|
/* This static object is returned for newlocale (LC_ALL_MASK, "C"). */
|
2005-12-21 07:28:33 +00:00
|
|
|
if (dataset == _nl_C_locobj_ptr)
|
2002-10-11 07:22:18 +00:00
|
|
|
return dataset;
|
|
|
|
|
2009-11-17 17:37:31 +00:00
|
|
|
/* Handle a special value. */
|
|
|
|
if (dataset == LC_GLOBAL_LOCALE)
|
|
|
|
dataset = &_nl_global_locale;
|
|
|
|
|
Use locale_t, not __locale_t, throughout glibc
<locale.h> is specified to define locale_t in POSIX.1-2008, and so are
all of the headers that define functions that take locale_t arguments.
Under _GNU_SOURCE, the additional headers that define such functions
have also always defined locale_t. Therefore, there is no need to use
__locale_t in public function prototypes, nor in any internal code.
* ctype/ctype-c99_l.c, ctype/ctype.h, ctype/ctype_l.c
* include/monetary.h, include/stdlib.h, include/time.h
* include/wchar.h, locale/duplocale.c, locale/freelocale.c
* locale/global-locale.c, locale/langinfo.h, locale/locale.h
* locale/localeinfo.h, locale/newlocale.c
* locale/nl_langinfo_l.c, locale/uselocale.c
* localedata/bug-usesetlocale.c, localedata/tst-xlocale2.c
* stdio-common/vfscanf.c, stdlib/monetary.h, stdlib/stdlib.h
* stdlib/strfmon_l.c, stdlib/strtod_l.c, stdlib/strtof_l.c
* stdlib/strtol.c, stdlib/strtol_l.c, stdlib/strtold_l.c
* stdlib/strtoll_l.c, stdlib/strtoul_l.c, stdlib/strtoull_l.c
* string/strcasecmp.c, string/strcoll_l.c, string/string.h
* string/strings.h, string/strncase.c, string/strxfrm_l.c
* sysdeps/ieee754/float128/strtof128_l.c
* sysdeps/ieee754/float128/wcstof128.c
* sysdeps/ieee754/float128/wcstof128_l.c
* sysdeps/ieee754/ldbl-128ibm/strtold_l.c
* sysdeps/ieee754/ldbl-64-128/strtold_l.c
* sysdeps/ieee754/ldbl-opt/nldbl-compat.c
* sysdeps/ieee754/ldbl-opt/nldbl-strfmon_l.c
* sysdeps/ieee754/ldbl-opt/nldbl-strtold_l.c
* sysdeps/ieee754/ldbl-opt/nldbl-wcstold_l.c
* sysdeps/powerpc/powerpc32/power7/strcasecmp.S
* sysdeps/powerpc/powerpc64/power7/strcasecmp.S
* sysdeps/x86_64/strcasecmp_l-nonascii.c
* sysdeps/x86_64/strncase_l-nonascii.c, time/strftime_l.c
* time/strptime_l.c, time/time.h, wcsmbs/mbsrtowcs_l.c
* wcsmbs/wchar.h, wcsmbs/wcscasecmp.c, wcsmbs/wcsncase.c
* wcsmbs/wcstod.c, wcsmbs/wcstod_l.c, wcsmbs/wcstof.c
* wcsmbs/wcstof_l.c, wcsmbs/wcstol_l.c, wcsmbs/wcstold.c
* wcsmbs/wcstold_l.c, wcsmbs/wcstoll_l.c, wcsmbs/wcstoul_l.c
* wcsmbs/wcstoull_l.c, wctype/iswctype_l.c
* wctype/towctrans_l.c, wctype/wcfuncs_l.c
* wctype/wctrans_l.c, wctype/wctype.h, wctype/wctype_l.c:
Change all uses of __locale_t to locale_t.
2017-06-20 13:26:43 +00:00
|
|
|
locale_t result;
|
2002-08-30 10:36:44 +00:00
|
|
|
int cnt;
|
2002-08-31 20:08:18 +00:00
|
|
|
size_t names_len = 0;
|
1997-02-15 04:31:36 +00:00
|
|
|
|
2002-08-31 20:08:18 +00:00
|
|
|
/* Calculate the total space we need to store all the names. */
|
|
|
|
for (cnt = 0; cnt < __LC_LAST; ++cnt)
|
|
|
|
if (cnt != LC_ALL && dataset->__names[cnt] != _nl_C_name)
|
|
|
|
names_len += strlen (dataset->__names[cnt]) + 1;
|
1997-02-15 04:31:36 +00:00
|
|
|
|
|
|
|
/* Get memory. */
|
2002-08-31 20:08:18 +00:00
|
|
|
result = malloc (sizeof (struct __locale_struct) + names_len);
|
2002-08-30 10:36:44 +00:00
|
|
|
|
1997-02-15 04:31:36 +00:00
|
|
|
if (result != NULL)
|
|
|
|
{
|
2002-08-31 20:08:18 +00:00
|
|
|
char *namep = (char *) (result + 1);
|
|
|
|
|
|
|
|
/* We modify global data (the usage counts). */
|
2008-03-31 00:38:06 +00:00
|
|
|
__libc_rwlock_wrlock (__libc_setlocale_lock);
|
2002-08-31 20:08:18 +00:00
|
|
|
|
Update.
2000-07-24 Jakub Jelinek <jakub@redhat.com>
* libio/wfiledoalloc.c (_IO_wfile_doallocate): Measure size
in wide characters, not bytes.
* libio/tst_putwc.c (do_test): Add test for writing lots of data
into file.
2000-07-22 Bruno Haible <haible@clisp.cons.org>
* locale/nl_langinfo.c (nl_langinfo): Accept items belonging to the
new categories LC_PAPER, LC_NAME, LC_ADDRESS, LC_TELEPHONE,
LC_MEASUREMENT, LC_IDENTIFICATION.
* locale/xlocale.h (struct __locale_struct): Increase size of
__locales array.
* locale/duplocale.c (__duplocale): Copy newly added categories as
well.
* locale/freelocale.c (__freelocale): Free newly added categories.
* locale/newlocale.c (__newlocale): Fix typo in sanity check.
If a base is given, use it, don't simply return it.
2000-07-22 Bruno Haible <haible@clisp.cons.org>
* crypt/md5-crypt.c (__md5_crypt_r): Avoid gcc warnings: Use pointer
variables, copied_key and copied_salt, instead of boolean variables.
2000-07-24 21:03:16 +00:00
|
|
|
for (cnt = 0; cnt < __LC_LAST; ++cnt)
|
|
|
|
if (cnt != LC_ALL)
|
|
|
|
{
|
|
|
|
result->__locales[cnt] = dataset->__locales[cnt];
|
|
|
|
if (result->__locales[cnt]->usage_count < MAX_USAGE_COUNT)
|
|
|
|
++result->__locales[cnt]->usage_count;
|
2002-08-31 20:08:18 +00:00
|
|
|
|
|
|
|
if (dataset->__names[cnt] == _nl_C_name)
|
|
|
|
result->__names[cnt] = _nl_C_name;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
result->__names[cnt] = namep;
|
|
|
|
namep = __stpcpy (namep, dataset->__names[cnt]) + 1;
|
|
|
|
}
|
Update.
2000-07-24 Jakub Jelinek <jakub@redhat.com>
* libio/wfiledoalloc.c (_IO_wfile_doallocate): Measure size
in wide characters, not bytes.
* libio/tst_putwc.c (do_test): Add test for writing lots of data
into file.
2000-07-22 Bruno Haible <haible@clisp.cons.org>
* locale/nl_langinfo.c (nl_langinfo): Accept items belonging to the
new categories LC_PAPER, LC_NAME, LC_ADDRESS, LC_TELEPHONE,
LC_MEASUREMENT, LC_IDENTIFICATION.
* locale/xlocale.h (struct __locale_struct): Increase size of
__locales array.
* locale/duplocale.c (__duplocale): Copy newly added categories as
well.
* locale/freelocale.c (__freelocale): Free newly added categories.
* locale/newlocale.c (__newlocale): Fix typo in sanity check.
If a base is given, use it, don't simply return it.
2000-07-22 Bruno Haible <haible@clisp.cons.org>
* crypt/md5-crypt.c (__md5_crypt_r): Avoid gcc warnings: Use pointer
variables, copied_key and copied_salt, instead of boolean variables.
2000-07-24 21:03:16 +00:00
|
|
|
}
|
1997-02-15 04:31:36 +00:00
|
|
|
|
2002-05-04 17:12:37 +00:00
|
|
|
/* Update the special members. */
|
|
|
|
result->__ctype_b = dataset->__ctype_b;
|
|
|
|
result->__ctype_tolower = dataset->__ctype_tolower;
|
|
|
|
result->__ctype_toupper = dataset->__ctype_toupper;
|
2001-08-18 02:46:36 +00:00
|
|
|
|
2002-08-31 20:08:18 +00:00
|
|
|
/* It's done. */
|
2008-03-31 00:38:06 +00:00
|
|
|
__libc_rwlock_unlock (__libc_setlocale_lock);
|
2002-08-31 20:08:18 +00:00
|
|
|
}
|
1997-02-19 04:43:53 +00:00
|
|
|
|
|
|
|
return result;
|
1997-02-15 04:31:36 +00:00
|
|
|
}
|
* locale/setlocale.c (_nl_current_names): Variable moved ...
* locale/localename.c (_nl_current_names): ... here, new file.
Make it global, with attribute_hidden.
* locale/localeinfo.h: Declare it.
* locale/Makefile (aux): Add localename.
* locale/localename.c (__current_locale_name): New function.
* include/locale.h (__current_locale_name): Declare it.
* intl/dcigettext.c (guess_category_value): Use that instead of
calling setlocale.
* locale/locale.h [__USE_GNU] (locale_t): New type alias of __locale_t.
[__USE_GNU] (newlocale, duplocale, freelocale, uselocale): New decls.
[__USE_GNU] (LC_GLOBAL_LOCALE): New macro.
* locale/newlocale.c: Add alias to __ name.
* locale/duplocale.c: Likewise.
* locale/freelocale.c: Likewise.
* locale/uselocale.c: New file.
* locale/Makefile (routines): Add it.
* locale/Versions (libc: GLIBC_2.3): New set.
Add newlocale, duplocale, freelocale, uselocale.
(libc: GLIBC_PRIVATE): Add __uselocale.
* locale/localeinfo.h [SHARED]
(_NL_CURRENT_LOCALE): New macro, defined to fetch a tsd value.
(_NL_CURRENT_DATA): Define using that.
(_NL_CURRENT, _NL_CURRENT_WSTR, _NL_CURRENT_WORD): Define using that.
(_NL_CURRENT_DEFINE): Define to empty.
[! SHARED]: Decls of _nl_current_CATEGORY and _nl_current
conditionalized on this.
* locale/xlocale.c (NL_C_INTIIALIZER): New macro,
taking initializer of _nl_C_locobj.
[SHARED] (_nl_global_locale): New variable, using that initializer.
(_nl_C_locobj): Use new macro for initialzier.
* locale/setlocale.c [! SHARED] (_nl_current): Conditionalize on this.
[! SHARED] (CATEGORY_USED): New macro.
[SHARED] (CATEGORY_USED, _nl_C): New macros.
(setdata, setlocale): Use that macro instead of examining _nl_current.
(setdata): Set the slot in _nl_global_locale.
Conditionalize setting of _nl_current on [! SHARED].
* locale/findlocale.c [SHARED] (_nl_C): Define as a macro instead of
declaration as an extern.
* locale/newlocale.c (__newlocale): Use _nl_C_locobj instead of _nl_C.
* include/locale.h: Use libc_hidden_proto for setlocale.
* locale/setlocale.c: Add libc_hidden_def.
* locale/setlocale.c (free_mem): Use _NL_CURRENT_DATA.
2002-08-04 01:41:55 +00:00
|
|
|
weak_alias (__duplocale, duplocale)
|