1 #ifndef _LOCALE_IMPL_H 2 #define _LOCALE_IMPL_H 3 4 #include <locale.h> 5 #include <stdlib.h> 6 #include "libc.h" 7 #if defined(TRUSTY_USERSPACE) 8 #include "pthread_impl.h" 9 #else 10 #include <trusty/libc_state.h> 11 #endif 12 13 #define LOCALE_NAME_MAX 23 14 15 struct __locale_map { 16 const void *map; 17 size_t map_size; 18 char name[LOCALE_NAME_MAX+1]; 19 const struct __locale_map *next; 20 }; 21 22 extern hidden const struct __locale_map __c_dot_utf8; 23 extern hidden const struct __locale_struct __c_locale; 24 extern hidden const struct __locale_struct __c_dot_utf8_locale; 25 26 hidden const struct __locale_map *__get_locale(int, const char *); 27 hidden const char *__mo_lookup(const void *, size_t, const char *); 28 hidden const char *__lctrans(const char *, const struct __locale_map *); 29 hidden const char *__lctrans_cur(const char *); 30 hidden const char *__lctrans_impl(const char *, const struct __locale_map *); 31 hidden int __loc_is_allocated(locale_t); 32 hidden char *__gettextdomain(void); 33 34 #define LOC_MAP_FAILED ((const struct __locale_map *)-1) 35 36 #define LCTRANS(msg, lc, loc) __lctrans(msg, (loc)->cat[(lc)]) 37 #define LCTRANS_CUR(msg) __lctrans_cur(msg) 38 39 #define C_LOCALE ((locale_t)&__c_locale) 40 #define UTF8_LOCALE ((locale_t)&__c_dot_utf8_locale) 41 42 #if defined(TRUSTY_USERSPACE) 43 #define CURRENT_LOCALE (__pthread_self()->locale) 44 #else 45 #define CURRENT_LOCALE (current_thread_libc_state()->locale) 46 #endif 47 48 #if defined(TRUSTY_USERSPACE) 49 #define CURRENT_UTF8 (!!__pthread_self()->locale->cat[LC_CTYPE]) 50 #else 51 #define CURRENT_UTF8 (!!C_LOCALE->cat[LC_CTYPE]) 52 #endif 53 54 #undef MB_CUR_MAX 55 #define MB_CUR_MAX (CURRENT_UTF8 ? 4 : 1) 56 57 #endif 58