_ctype_ is used in ctype.h header in order to define inline functions for determining character class: isalnum(3), isalpha(3), ...
The character class comes from lc_ctype. Switch _ctype_ from global variable to function in order to retrieve the current locale state (global or per-thread). -- Sebastien Marie Index: b/include/ctype.h =================================================================== --- a/include/ctype.h 2015-07-05 06:50:41.963279015 +0200 +++ b/include/ctype.h 2015-07-05 06:52:28.894297063 +0200 @@ -53,7 +53,7 @@ __BEGIN_DECLS -extern const char *_ctype_; +extern const char *_ctype_(void); extern const short *_tolower_tab_; extern const short *_toupper_tab_; @@ -90,57 +90,68 @@ __only_inline int isalnum(int _c) { - return (_c == -1 ? 0 : ((_ctype_ + 1)[(unsigned char)_c] & (_U|_L|_N))); + return (_c == -1 ? + 0 : ((_ctype_() + 1)[(unsigned char)_c] & (_U|_L|_N))); } __only_inline int isalpha(int _c) { - return (_c == -1 ? 0 : ((_ctype_ + 1)[(unsigned char)_c] & (_U|_L))); + return (_c == -1 ? + 0 : ((_ctype_() + 1)[(unsigned char)_c] & (_U|_L))); } __only_inline int iscntrl(int _c) { - return (_c == -1 ? 0 : ((_ctype_ + 1)[(unsigned char)_c] & _C)); + return (_c == -1 ? + 0 : ((_ctype_() + 1)[(unsigned char)_c] & _C)); } __only_inline int isdigit(int _c) { - return (_c == -1 ? 0 : ((_ctype_ + 1)[(unsigned char)_c] & _N)); + return (_c == -1 ? + 0 : ((_ctype_() + 1)[(unsigned char)_c] & _N)); } __only_inline int isgraph(int _c) { - return (_c == -1 ? 0 : ((_ctype_ + 1)[(unsigned char)_c] & (_P|_U|_L|_N))); + return (_c == -1 ? + 0 : ((_ctype_() + 1)[(unsigned char)_c] & (_P|_U|_L|_N))); } __only_inline int islower(int _c) { - return (_c == -1 ? 0 : ((_ctype_ + 1)[(unsigned char)_c] & _L)); + return (_c == -1 ? + 0 : ((_ctype_() + 1)[(unsigned char)_c] & _L)); } __only_inline int isprint(int _c) { - return (_c == -1 ? 0 : ((_ctype_ + 1)[(unsigned char)_c] & (_P|_U|_L|_N|_B))); + return (_c == -1 ? + 0 : ((_ctype_() + 1)[(unsigned char)_c] & (_P|_U|_L|_N|_B))); } __only_inline int ispunct(int _c) { - return (_c == -1 ? 0 : ((_ctype_ + 1)[(unsigned char)_c] & _P)); + return (_c == -1 ? + 0 : ((_ctype_() + 1)[(unsigned char)_c] & _P)); } __only_inline int isspace(int _c) { - return (_c == -1 ? 0 : ((_ctype_ + 1)[(unsigned char)_c] & _S)); + return (_c == -1 ? + 0 : ((_ctype_() + 1)[(unsigned char)_c] & _S)); } __only_inline int isupper(int _c) { - return (_c == -1 ? 0 : ((_ctype_ + 1)[(unsigned char)_c] & _U)); + return (_c == -1 ? + 0 : ((_ctype_() + 1)[(unsigned char)_c] & _U)); } __only_inline int isxdigit(int _c) { - return (_c == -1 ? 0 : ((_ctype_ + 1)[(unsigned char)_c] & (_N|_X))); + return (_c == -1 ? + 0 : ((_ctype_() + 1)[(unsigned char)_c] & (_N|_X))); } __only_inline int tolower(int _c) Index: b/lib/libc/gen/ctype_.c =================================================================== --- a/lib/libc/gen/ctype_.c 2015-07-05 06:50:41.963279015 +0200 +++ b/lib/libc/gen/ctype_.c 2015-07-05 06:52:28.894297063 +0200 @@ -72,5 +72,3 @@ 0, 0, 0, 0, 0, 0, 0, 0, /* F0 */ 0, 0, 0, 0, 0, 0, 0, 0 /* F8 */ }; - -const char *_ctype_ = _C_ctype_; Index: b/lib/libc/gen/isctype.c =================================================================== --- a/lib/libc/gen/isctype.c 2015-07-05 06:50:41.963279015 +0200 +++ b/lib/libc/gen/isctype.c 2015-07-05 06:52:28.934295987 +0200 @@ -41,14 +41,16 @@ int isalnum(int c) { - return (c == EOF ? 0 : ((_ctype_ + 1)[(unsigned char)c] & (_U|_L|_N))); + return (c == EOF ? + 0 : ((_ctype_() + 1)[(unsigned char)c] & (_U|_L|_N))); } #undef isalpha int isalpha(int c) { - return (c == EOF ? 0 : ((_ctype_ + 1)[(unsigned char)c] & (_U|_L))); + return (c == EOF ? + 0 : ((_ctype_() + 1)[(unsigned char)c] & (_U|_L))); } #undef isblank @@ -62,63 +64,72 @@ int iscntrl(int c) { - return (c == EOF ? 0 : ((_ctype_ + 1)[(unsigned char)c] & _C)); + return (c == EOF ? + 0 : ((_ctype_() + 1)[(unsigned char)c] & _C)); } #undef isdigit int isdigit(int c) { - return (c == EOF ? 0 : ((_ctype_ + 1)[(unsigned char)c] & _N)); + return (c == EOF ? + 0 : ((_ctype_() + 1)[(unsigned char)c] & _N)); } #undef isgraph int isgraph(int c) { - return (c == EOF ? 0 : ((_ctype_ + 1)[(unsigned char)c] & (_P|_U|_L|_N))); + return (c == EOF ? + 0 : ((_ctype_() + 1)[(unsigned char)c] & (_P|_U|_L|_N))); } #undef islower int islower(int c) { - return (c == EOF ? 0 : ((_ctype_ + 1)[(unsigned char)c] & _L)); + return (c == EOF ? + 0 : ((_ctype_() + 1)[(unsigned char)c] & _L)); } #undef isprint int isprint(int c) { - return (c == EOF ? 0 : ((_ctype_ + 1)[(unsigned char)c] & (_P|_U|_L|_N|_B))); + return (c == EOF ? + 0 : ((_ctype_() + 1)[(unsigned char)c] & (_P|_U|_L|_N|_B))); } #undef ispunct int ispunct(int c) { - return (c == EOF ? 0 : ((_ctype_ + 1)[(unsigned char)c] & _P)); + return (c == EOF ? + 0 : ((_ctype_() + 1)[(unsigned char)c] & _P)); } #undef isspace int isspace(int c) { - return (c == EOF ? 0 : ((_ctype_ + 1)[(unsigned char)c] & _S)); + return (c == EOF ? + 0 : ((_ctype_() + 1)[(unsigned char)c] & _S)); } #undef isupper int isupper(int c) { - return (c == EOF ? 0 : ((_ctype_ + 1)[(unsigned char)c] & _U)); + return (c == EOF ? + 0 : ((_ctype_() + 1)[(unsigned char)c] & _U)); } #undef isxdigit int isxdigit(int c) { - return (c == EOF ? 0 : ((_ctype_ + 1)[(unsigned char)c] & (_N|_X))); + return (c == EOF ? + 0 : ((_ctype_() + 1)[(unsigned char)c] & (_N|_X))); } #undef isascii Index: b/lib/libc/locale/runeglue.c =================================================================== --- a/lib/libc/locale/runeglue.c 2015-07-05 06:52:21.704209858 +0200 +++ b/lib/libc/locale/runeglue.c 2015-07-05 06:52:28.934295987 +0200 @@ -119,16 +119,12 @@ { if (locale->lc_ctype->rl_tabs != NULL) { /* LINTED const cast */ - _ctype_ = (const unsigned char *) - &(locale->lc_ctype->rl_tabs->ctype_tab); - /* LINTED const cast */ _toupper_tab_ = (const short *) &(locale->lc_ctype->rl_tabs->toupper_tab); /* LINTED const cast */ _tolower_tab_ = (const short *) &(locale->lc_ctype->rl_tabs->tolower_tab); } else { - _ctype_ = _C_ctype_; _toupper_tab_ = _C_toupper_; _tolower_tab_ = _C_tolower_; } Index: b/lib/libc/locale/xlocale.c =================================================================== --- a/lib/libc/locale/xlocale.c 2015-07-05 06:52:21.694210301 +0200 +++ b/lib/libc/locale/xlocale.c 2015-07-05 06:52:28.944296242 +0200 @@ -73,3 +73,16 @@ } else return (NULL); } + + +/* exported via ctype.h */ +const char * +_ctype_(void) +{ + locale_t loc = _current_locale(); + + if (loc->lc_ctype->rl_tabs != NULL) + return (loc->lc_ctype->rl_tabs->ctype_tab); + else + return (_C_ctype_); +}