Print this page
Thread safety fixes.


  56         empty,          /* negative_sign */
  57         numempty,       /* int_frac_digits */
  58         numempty,       /* frac_digits */
  59         numempty,       /* p_cs_precedes */
  60         numempty,       /* p_sep_by_space */
  61         numempty,       /* n_cs_precedes */
  62         numempty,       /* n_sep_by_space */
  63         numempty,       /* p_sign_posn */
  64         numempty,       /* n_sign_posn */
  65         numempty,       /* int_p_cs_precedes */
  66         numempty,       /* int_n_cs_precedes */
  67         numempty,       /* int_p_sep_by_space */
  68         numempty,       /* int_n_sep_by_space */
  69         numempty,       /* int_p_sign_posn */
  70         numempty,       /* int_n_sign_posn */
  71         empty           /* crncystr */
  72 };
  73 
  74 struct locdata __posix_monetary_locdata = {
  75         .l_lname = "C",
  76         .l_refcnt = (uint32_t)-1,
  77         .l_data = { &lc_monetary_posix }
  78 };
  79 
  80 static char
  81 cnv(const char *str)
  82 {
  83         int i = strtol(str, NULL, 10);
  84 
  85         if (i == -1)
  86                 i = CHAR_MAX;
  87         return ((char)i);
  88 }
  89 
  90 struct locdata *
  91 __lc_monetary_load(const char *name)
  92 {
  93         int ret;
  94         int clen;
  95         struct lc_monetary      *lmon;
  96         struct locdata          *ldata;
  97 
  98         if ((ldata = __locdata_alloc(name, sizeof (*lmon))) == NULL) {
  99                 return (NULL);
 100         }
 101         lmon = ldata->l_data[0];
 102 
 103         ret = __part_load_locale(name, (char **)&ldata->l_data[1],
 104             "LC_MONETARY", LCMONETARY_SIZE_FULL, LCMONETARY_SIZE_MIN,
 105             (const char **)lmon);
 106 
 107         if (ret != _LDP_LOADED) {
 108                 __locdata_release(ldata);
 109                 errno = EINVAL;
 110                 return (NULL);
 111         }
 112 
 113         /* special storage for currency string */
 114         clen = strlen(lmon->currency_symbol) + 2;
 115         ldata->l_data[2] = malloc(clen);
 116         lmon->crncystr = ldata->l_data[2];
 117         lmon->crncystr[0] = '\0';
 118 
 119         lmon->mon_grouping = __fix_locale_grouping_str(lmon->mon_grouping);
 120 
 121 #define M_ASSIGN_CHAR(NAME) \
 122         (((char *)lmon->NAME)[0] = cnv(lmon->NAME))
 123 
 124         M_ASSIGN_CHAR(int_frac_digits);
 125         M_ASSIGN_CHAR(frac_digits);
 126         M_ASSIGN_CHAR(p_cs_precedes);
 127         M_ASSIGN_CHAR(p_sep_by_space);
 128         M_ASSIGN_CHAR(n_cs_precedes);




  56         empty,          /* negative_sign */
  57         numempty,       /* int_frac_digits */
  58         numempty,       /* frac_digits */
  59         numempty,       /* p_cs_precedes */
  60         numempty,       /* p_sep_by_space */
  61         numempty,       /* n_cs_precedes */
  62         numempty,       /* n_sep_by_space */
  63         numempty,       /* p_sign_posn */
  64         numempty,       /* n_sign_posn */
  65         numempty,       /* int_p_cs_precedes */
  66         numempty,       /* int_n_cs_precedes */
  67         numempty,       /* int_p_sep_by_space */
  68         numempty,       /* int_n_sep_by_space */
  69         numempty,       /* int_p_sign_posn */
  70         numempty,       /* int_n_sign_posn */
  71         empty           /* crncystr */
  72 };
  73 
  74 struct locdata __posix_monetary_locdata = {
  75         .l_lname = "C",

  76         .l_data = { &lc_monetary_posix }
  77 };
  78 
  79 static char
  80 cnv(const char *str)
  81 {
  82         int i = strtol(str, NULL, 10);
  83 
  84         if (i == -1)
  85                 i = CHAR_MAX;
  86         return ((char)i);
  87 }
  88 
  89 struct locdata *
  90 __lc_monetary_load(const char *name)
  91 {
  92         int ret;
  93         int clen;
  94         struct lc_monetary      *lmon;
  95         struct locdata          *ldata;
  96 
  97         if ((ldata = __locdata_alloc(name, sizeof (*lmon))) == NULL) {
  98                 return (NULL);
  99         }
 100         lmon = ldata->l_data[0];
 101 
 102         ret = __part_load_locale(name, (char **)&ldata->l_data[1],
 103             "LC_MONETARY", LCMONETARY_SIZE_FULL, LCMONETARY_SIZE_MIN,
 104             (const char **)lmon);
 105 
 106         if (ret != _LDP_LOADED) {
 107                 __locdata_free(ldata);
 108                 errno = EINVAL;
 109                 return (NULL);
 110         }
 111 
 112         /* special storage for currency string */
 113         clen = strlen(lmon->currency_symbol) + 2;
 114         ldata->l_data[2] = malloc(clen);
 115         lmon->crncystr = ldata->l_data[2];
 116         lmon->crncystr[0] = '\0';
 117 
 118         lmon->mon_grouping = __fix_locale_grouping_str(lmon->mon_grouping);
 119 
 120 #define M_ASSIGN_CHAR(NAME) \
 121         (((char *)lmon->NAME)[0] = cnv(lmon->NAME))
 122 
 123         M_ASSIGN_CHAR(int_frac_digits);
 124         M_ASSIGN_CHAR(frac_digits);
 125         M_ASSIGN_CHAR(p_cs_precedes);
 126         M_ASSIGN_CHAR(p_sep_by_space);
 127         M_ASSIGN_CHAR(n_cs_precedes);