Print this page
locale stuff should use libc safe lmalloc.  Other fixes from tests.


  16  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
  17  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  18  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  19  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
  20  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  21  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  22  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  23  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  24  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  25  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  26  * SUCH DAMAGE.
  27  */
  28 
  29 #include "lint.h"
  30 #include <limits.h>
  31 #include <stddef.h>
  32 #include <stdlib.h>
  33 #include <stdio.h>
  34 #include <string.h>
  35 #include <errno.h>

  36 #include "ldpart.h"
  37 #include "lmonetary.h"
  38 #include "localeimpl.h"
  39 
  40 extern const char *__fix_locale_grouping_str(const char *);
  41 
  42 #define LCMONETARY_SIZE_FULL (sizeof (struct lc_monetary) / sizeof (char *))
  43 #define LCMONETARY_SIZE_MIN \
  44         (offsetof(struct lc_monetary, int_p_cs_precedes) / sizeof (char *))
  45 
  46 static char     empty[] = "";
  47 static char     numempty[] = { CHAR_MAX, '\0' };
  48 
  49 struct lc_monetary lc_monetary_posix = {
  50         empty,          /* int_curr_symbol */
  51         empty,          /* currency_symbol */
  52         empty,          /* mon_decimal_point */
  53         empty,          /* mon_thousands_sep */
  54         numempty,       /* mon_grouping */
  55         empty,          /* positive_sign */


  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);
 128         M_ASSIGN_CHAR(n_sep_by_space);
 129         M_ASSIGN_CHAR(p_sign_posn);
 130         M_ASSIGN_CHAR(n_sign_posn);
 131 
 132         /*
 133          * The six additional C99 international monetary formatting
 134          * parameters default to the national parameters when
 135          * reading FreeBSD LC_MONETARY data files.
 136          */




  16  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
  17  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  18  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  19  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
  20  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  21  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  22  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  23  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  24  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  25  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  26  * SUCH DAMAGE.
  27  */
  28 
  29 #include "lint.h"
  30 #include <limits.h>
  31 #include <stddef.h>
  32 #include <stdlib.h>
  33 #include <stdio.h>
  34 #include <string.h>
  35 #include <errno.h>
  36 #include "libc.h"
  37 #include "ldpart.h"
  38 #include "lmonetary.h"
  39 #include "localeimpl.h"
  40 
  41 extern const char *__fix_locale_grouping_str(const char *);
  42 
  43 #define LCMONETARY_SIZE_FULL (sizeof (struct lc_monetary) / sizeof (char *))
  44 #define LCMONETARY_SIZE_MIN \
  45         (offsetof(struct lc_monetary, int_p_cs_precedes) / sizeof (char *))
  46 
  47 static char     empty[] = "";
  48 static char     numempty[] = { CHAR_MAX, '\0' };
  49 
  50 struct lc_monetary lc_monetary_posix = {
  51         empty,          /* int_curr_symbol */
  52         empty,          /* currency_symbol */
  53         empty,          /* mon_decimal_point */
  54         empty,          /* mon_thousands_sep */
  55         numempty,       /* mon_grouping */
  56         empty,          /* positive_sign */


  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_free(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] = libc_malloc(clen);
 116         lmon->crncystr = ldata->l_data[2];

 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);
 128         M_ASSIGN_CHAR(n_sep_by_space);
 129         M_ASSIGN_CHAR(p_sign_posn);
 130         M_ASSIGN_CHAR(n_sign_posn);
 131 
 132         /*
 133          * The six additional C99 international monetary formatting
 134          * parameters default to the national parameters when
 135          * reading FreeBSD LC_MONETARY data files.
 136          */