Print this page
Thread safety fixes.


  49 #include "lctype.h"
  50 #include "localeimpl.h"
  51 
  52 extern _RuneLocale      *_Read_RuneMagi(const char *);
  53 
  54 struct lc_ctype lc_ctype_posix = {
  55         .lc_mbrtowc = __mbrtowc_ascii,
  56         .lc_mbsinit = __mbsinit_ascii,
  57         .lc_mbsnrtowcs = __mbsnrtowcs_ascii,
  58         .lc_wcrtomb = __wcrtomb_ascii,
  59         .lc_wcsnrtombs = __wcsnrtombs_ascii,
  60         .lc_is_ascii = 1,
  61         .lc_max_mblen = 1,
  62         .lc_trans_upper = _DefaultRuneLocale.__mapupper,
  63         .lc_trans_lower = _DefaultRuneLocale.__maplower,
  64         .lc_ctype_mask = _DefaultRuneLocale.__runetype,
  65 };
  66 
  67 struct locdata __posix_ctype_locdata = {
  68         .l_lname = "C",
  69         .l_refcnt = (uint32_t)-1,
  70         .l_data = { &lc_ctype_posix, &_DefaultRuneLocale }
  71 };
  72 
  73 
  74 /*
  75  * Table of initializers for encodings.  When you add a new encoding type,
  76  * this table should be updated.
  77  */
  78 static struct {
  79         const char *e_name;
  80         void (*e_init)(struct lc_ctype *);
  81 } encodings[] = {
  82         { "NONE", _none_init },
  83         { "UTF-8",      _UTF8_init },
  84         { "EUC-CN",     _EUC_CN_init },
  85         { "EUC-JP",     _EUC_JP_init },
  86         { "EUC-KR",     _EUC_KR_init },
  87         { "EUC-TW",     _EUC_TW_init },
  88         { "GB18030",    _GB18030_init },
  89         { "GB2312",     _GB2312_init },


  97 struct locdata *
  98 __lc_ctype_load(const char *name)
  99 {
 100         struct locdata *ldata;
 101         struct lc_ctype *lct;
 102         _RuneLocale *rl;
 103         int i;
 104         char path[PATH_MAX];
 105 
 106         if ((ldata = __locdata_alloc(name, sizeof (*lct))) == NULL)
 107                 return (NULL);
 108         lct = ldata->l_data[0];
 109         /*
 110          * Slurp the locale file into the cache.
 111          */
 112 
 113         (void) snprintf(path, sizeof (path), "%s/%s/LC_CTYPE/LCL_DATA",
 114             _PathLocale, name);
 115 
 116         if ((rl = _Read_RuneMagi(path)) == NULL) {
 117                 __locdata_release(ldata);
 118                 errno = EINVAL;
 119                 return (NULL);
 120         }
 121         ldata->l_data[1] = rl;
 122 
 123         lct->lc_mbrtowc = NULL;
 124         lct->lc_mbsinit = NULL;
 125         lct->lc_mbsnrtowcs = NULL;
 126         lct->lc_wcrtomb = NULL;
 127         lct->lc_wcsnrtombs = NULL;
 128         lct->lc_ctype_mask = rl->__runetype;
 129         lct->lc_trans_upper = rl->__mapupper;
 130         lct->lc_trans_lower = rl->__maplower;
 131 
 132         /* set up the function pointers */
 133         for (i = 0; encodings[i].e_name != NULL; i++) {
 134                 int l = strlen(encodings[i].e_name);
 135                 if ((strncmp(rl->__encoding, encodings[i].e_name, l) == 0) &&
 136                     (rl->__encoding[l] == '\0' || rl->__encoding[l] == '@')) {
 137                         encodings[i].e_init(lct);
 138                         break;
 139                 }
 140         }
 141         if (encodings[i].e_name == NULL) {
 142                 __locdata_release(ldata);
 143                 errno = EINVAL;
 144                 return (NULL);
 145         }
 146 
 147 
 148         return (ldata);
 149 }


  49 #include "lctype.h"
  50 #include "localeimpl.h"
  51 
  52 extern _RuneLocale      *_Read_RuneMagi(const char *);
  53 
  54 struct lc_ctype lc_ctype_posix = {
  55         .lc_mbrtowc = __mbrtowc_ascii,
  56         .lc_mbsinit = __mbsinit_ascii,
  57         .lc_mbsnrtowcs = __mbsnrtowcs_ascii,
  58         .lc_wcrtomb = __wcrtomb_ascii,
  59         .lc_wcsnrtombs = __wcsnrtombs_ascii,
  60         .lc_is_ascii = 1,
  61         .lc_max_mblen = 1,
  62         .lc_trans_upper = _DefaultRuneLocale.__mapupper,
  63         .lc_trans_lower = _DefaultRuneLocale.__maplower,
  64         .lc_ctype_mask = _DefaultRuneLocale.__runetype,
  65 };
  66 
  67 struct locdata __posix_ctype_locdata = {
  68         .l_lname = "C",

  69         .l_data = { &lc_ctype_posix, &_DefaultRuneLocale }
  70 };
  71 
  72 
  73 /*
  74  * Table of initializers for encodings.  When you add a new encoding type,
  75  * this table should be updated.
  76  */
  77 static struct {
  78         const char *e_name;
  79         void (*e_init)(struct lc_ctype *);
  80 } encodings[] = {
  81         { "NONE", _none_init },
  82         { "UTF-8",      _UTF8_init },
  83         { "EUC-CN",     _EUC_CN_init },
  84         { "EUC-JP",     _EUC_JP_init },
  85         { "EUC-KR",     _EUC_KR_init },
  86         { "EUC-TW",     _EUC_TW_init },
  87         { "GB18030",    _GB18030_init },
  88         { "GB2312",     _GB2312_init },


  96 struct locdata *
  97 __lc_ctype_load(const char *name)
  98 {
  99         struct locdata *ldata;
 100         struct lc_ctype *lct;
 101         _RuneLocale *rl;
 102         int i;
 103         char path[PATH_MAX];
 104 
 105         if ((ldata = __locdata_alloc(name, sizeof (*lct))) == NULL)
 106                 return (NULL);
 107         lct = ldata->l_data[0];
 108         /*
 109          * Slurp the locale file into the cache.
 110          */
 111 
 112         (void) snprintf(path, sizeof (path), "%s/%s/LC_CTYPE/LCL_DATA",
 113             _PathLocale, name);
 114 
 115         if ((rl = _Read_RuneMagi(path)) == NULL) {
 116                 __locdata_free(ldata);
 117                 errno = EINVAL;
 118                 return (NULL);
 119         }
 120         ldata->l_data[1] = rl;
 121 
 122         lct->lc_mbrtowc = NULL;
 123         lct->lc_mbsinit = NULL;
 124         lct->lc_mbsnrtowcs = NULL;
 125         lct->lc_wcrtomb = NULL;
 126         lct->lc_wcsnrtombs = NULL;
 127         lct->lc_ctype_mask = rl->__runetype;
 128         lct->lc_trans_upper = rl->__mapupper;
 129         lct->lc_trans_lower = rl->__maplower;
 130 
 131         /* set up the function pointers */
 132         for (i = 0; encodings[i].e_name != NULL; i++) {
 133                 int l = strlen(encodings[i].e_name);
 134                 if ((strncmp(rl->__encoding, encodings[i].e_name, l) == 0) &&
 135                     (rl->__encoding[l] == '\0' || rl->__encoding[l] == '@')) {
 136                         encodings[i].e_init(lct);
 137                         break;
 138                 }
 139         }
 140         if (encodings[i].e_name == NULL) {
 141                 __locdata_free(ldata);
 142                 errno = EINVAL;
 143                 return (NULL);
 144         }
 145 
 146 
 147         return (ldata);
 148 }