Back to index

glibc  2.9
global-locale.c
Go to the documentation of this file.
00001 /* Locale object representing the global locale controlled by setlocale.
00002    Copyright (C) 2002, 2006, 2008 Free Software Foundation, Inc.
00003    This file is part of the GNU C Library.
00004 
00005    The GNU C Library is free software; you can redistribute it and/or
00006    modify it under the terms of the GNU Lesser General Public
00007    License as published by the Free Software Foundation; either
00008    version 2.1 of the License, or (at your option) any later version.
00009 
00010    The GNU C Library is distributed in the hope that it will be useful,
00011    but WITHOUT ANY WARRANTY; without even the implied warranty of
00012    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013    Lesser General Public License for more details.
00014 
00015    You should have received a copy of the GNU Lesser General Public
00016    License along with the GNU C Library; if not, write to the Free
00017    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
00018    02111-1307 USA.  */
00019 
00020 #include <locale.h>
00021 #include "localeinfo.h"
00022 
00023 #define DEFINE_CATEGORY(category, category_name, items, a) \
00024 extern struct locale_data _nl_C_##category; weak_extern (_nl_C_##category)
00025 #include "categories.def"
00026 #undef DEFINE_CATEGORY
00027 
00028 /* Defined in locale/C-ctype.c.  */
00029 extern const char _nl_C_LC_CTYPE_class[] attribute_hidden;
00030 extern const char _nl_C_LC_CTYPE_toupper[] attribute_hidden;
00031 extern const char _nl_C_LC_CTYPE_tolower[] attribute_hidden;
00032 weak_extern (_nl_C_LC_CTYPE_class)
00033 weak_extern (_nl_C_LC_CTYPE_toupper)
00034 weak_extern (_nl_C_LC_CTYPE_tolower)
00035 
00036 /* Here we define the locale object maintained by setlocale.
00037    The references in the initializer are weak, so the parts of
00038    the structure that are never referred to will be zero.  */
00039 
00040 struct __locale_struct _nl_global_locale attribute_hidden =
00041   {
00042     .__locales =
00043     {
00044 #define DEFINE_CATEGORY(category, category_name, items, a) \
00045       [category] = &_nl_C_##category,
00046 #include "categories.def"
00047 #undef DEFINE_CATEGORY
00048     },
00049     .__names =
00050     {
00051       [LC_ALL] = _nl_C_name,
00052 #define DEFINE_CATEGORY(category, category_name, items, a) \
00053       [category] = _nl_C_name,
00054 #include "categories.def"
00055 #undef DEFINE_CATEGORY
00056     },
00057     .__ctype_b = (const unsigned short int *) _nl_C_LC_CTYPE_class + 128,
00058     .__ctype_tolower = (const int *) _nl_C_LC_CTYPE_tolower + 128,
00059     .__ctype_toupper = (const int *) _nl_C_LC_CTYPE_toupper + 128
00060   };
00061 
00062 #include <tls.h>
00063 #if HAVE___THREAD
00064 /* The tsd macros don't permit an initializer.  */
00065 __thread __locale_t __libc_tsd_LOCALE = &_nl_global_locale;
00066 #else
00067 __libc_tsd_define (, __locale_t, LOCALE)
00068 /* This is a bad kludge presuming the variable name used by the macros.
00069    Using typeof makes sure to barf if we do not match the macro definition.
00070    This ifndef is a further bad kludge for Hurd, where there is an explicit
00071    initialization.  */
00072 # ifndef _HURD_THREADVAR_H
00073 __typeof (__libc_tsd_LOCALE_data) __libc_tsd_LOCALE_data = &_nl_global_locale;
00074 # endif
00075 #endif