__private_extern__ int __numeric_load_locale(const char *name, locale_t loc) { int ret; struct __xlocale_st_numeric *xp; static struct __xlocale_st_numeric *cache = NULL; /* 'name' must be already checked. */ if (strcmp(name, "C") == 0 || strcmp(name, "POSIX") == 0) { if (!loc->_numeric_using_locale) return (_LDP_CACHE); loc->_numeric_using_locale = 0; XL_RELEASE(loc->__lc_numeric); loc->__lc_numeric = NULL; loc->__nlocale_changed = 1; return (_LDP_CACHE); } if (loc->_numeric_using_locale && strcmp(name, loc->__lc_numeric->_numeric_locale_buf) == 0) return (_LDP_CACHE); /* * If the locale name is the same as our cache, use the cache. */ if (cache && cache->_numeric_locale_buf && strcmp(name, cache->_numeric_locale_buf) == 0) { loc->_numeric_using_locale = 1; XL_RELEASE(loc->__lc_numeric); loc->__lc_numeric = cache; XL_RETAIN(loc->__lc_numeric); loc->__nlocale_changed = 1; return (_LDP_CACHE); } if ((xp = (struct __xlocale_st_numeric *)malloc(sizeof(*xp))) == NULL) return _LDP_ERROR; xp->__refcount = 1; xp->__free_extra = (__free_extra_t)__ldpart_free_extra; xp->_numeric_locale_buf = NULL; ret = __part_load_locale(name, &loc->_numeric_using_locale, &xp->_numeric_locale_buf, "LC_NUMERIC", LCNUMERIC_SIZE, LCNUMERIC_SIZE, (const char **)&xp->_numeric_locale); if (ret != _LDP_ERROR) loc->__nlocale_changed = 1; else free(xp); if (ret == _LDP_LOADED) { /* Can't be empty according to C99 */ if (*xp->_numeric_locale.decimal_point == '\0') xp->_numeric_locale.decimal_point = _C_numeric_locale.decimal_point; xp->_numeric_locale.grouping = __fix_locale_grouping_str(xp->_numeric_locale.grouping); XL_RELEASE(loc->__lc_numeric); loc->__lc_numeric = xp; XL_RELEASE(cache); cache = xp; XL_RETAIN(cache); } return (ret); }
int __time_load_locale(const char *name) { return (__part_load_locale(name, &_time_using_locale, &time_locale_buf, "LC_TIME", LCTIME_SIZE, LCTIME_SIZE, (const char **)&_time_locale)); }
int __time_load_locale(const char *name, void *f_wctomb, const char *charset) { int ret; #ifdef __CYGWIN__ extern int __set_lc_time_from_win (const char *, const struct lc_time_T *, struct lc_time_T *, char **, void *, const char *); int old_time_using_locale = _time_using_locale; _time_using_locale = 0; ret = __set_lc_time_from_win (name, &_C_time_locale, &_time_locale, &time_locale_buf, f_wctomb, charset); /* ret == -1: error, ret == 0: C/POSIX, ret > 0: valid */ if (ret < 0) _time_using_locale = old_time_using_locale; else { _time_using_locale = ret; ret = 0; } #else ret = __part_load_locale(name, &_time_using_locale, time_locale_buf, "LC_TIME", LCTIME_SIZE, LCTIME_SIZE, (const char **)&_time_locale); #endif return (ret); }
int __monetary_load_locale(const char *name) { int ret; __mlocale_changed = 1; ret = __part_load_locale(name, &_monetary_using_locale, _monetary_locale_buf, "LC_MONETARY", LCMONETARY_SIZE, LCMONETARY_SIZE, (const char **)&_monetary_locale); if (ret == 0 && _monetary_using_locale) { _monetary_locale.mon_grouping = __fix_locale_grouping_str(_monetary_locale.mon_grouping); #define M_ASSIGN_CHAR(NAME) (((char *)_monetary_locale.NAME)[0] = \ cnv(_monetary_locale.NAME)) M_ASSIGN_CHAR(int_frac_digits); M_ASSIGN_CHAR(frac_digits); M_ASSIGN_CHAR(p_cs_precedes); M_ASSIGN_CHAR(p_sep_by_space); M_ASSIGN_CHAR(n_cs_precedes); M_ASSIGN_CHAR(n_sep_by_space); M_ASSIGN_CHAR(p_sign_posn); M_ASSIGN_CHAR(n_sign_posn); } return ret; }
int __monetary_load_locale(const char *name) { int ret; ret = __part_load_locale(name, &_monetary_using_locale, _monetary_locale_buf, "LC_MONETARY", LCMONETARY_SIZE_FULL, LCMONETARY_SIZE_MIN, (const char **)&_monetary_locale); if (ret != _LDP_ERROR) __mlocale_changed = 1; if (ret == _LDP_LOADED) { _monetary_locale.mon_grouping = __fix_locale_grouping_str(_monetary_locale.mon_grouping); #define M_ASSIGN_CHAR(NAME) (((char *)_monetary_locale.NAME)[0] = \ cnv(_monetary_locale.NAME)) M_ASSIGN_CHAR(int_frac_digits); M_ASSIGN_CHAR(frac_digits); M_ASSIGN_CHAR(p_cs_precedes); M_ASSIGN_CHAR(p_sep_by_space); M_ASSIGN_CHAR(n_cs_precedes); M_ASSIGN_CHAR(n_sep_by_space); M_ASSIGN_CHAR(p_sign_posn); M_ASSIGN_CHAR(n_sign_posn); /* * The six additional C99 international monetary formatting * parameters default to the national parameters when * reading FreeBSD 4 LC_MONETARY data files. */ #define M_ASSIGN_ICHAR(NAME) \ do { \ if (_monetary_locale.int_##NAME == NULL) \ _monetary_locale.int_##NAME = \ _monetary_locale.NAME; \ else \ M_ASSIGN_CHAR(int_##NAME); \ } while (0) M_ASSIGN_ICHAR(p_cs_precedes); M_ASSIGN_ICHAR(n_cs_precedes); M_ASSIGN_ICHAR(p_sep_by_space); M_ASSIGN_ICHAR(n_sep_by_space); M_ASSIGN_ICHAR(p_sign_posn); M_ASSIGN_ICHAR(n_sign_posn); } return (ret); }
int __ctype_load_locale(const char *name, void *f_wctomb, const char *charset, int mb_cur_max) { int ret; #ifdef __CYGWIN__ extern int __set_lc_ctype_from_win (const char *, const struct lc_ctype_T *, struct lc_ctype_T *, char **, void *, const char *, int); int old_ctype_using_locale = _ctype_using_locale; _ctype_using_locale = 0; ret = __set_lc_ctype_from_win (name, &_C_ctype_locale, &_ctype_locale, &_ctype_locale_buf, f_wctomb, charset, mb_cur_max); /* ret == -1: error, ret == 0: C/POSIX, ret > 0: valid */ if (ret < 0) _ctype_using_locale = old_ctype_using_locale; else { _ctype_using_locale = ret; ret = 0; } #elif !defined (__HAVE_LOCALE_INFO_EXTENDED__) if (!strcmp (name, "C")) _ctype_using_locale = 0; else { char *mbc; _ctype_locale.codeset = strcpy (_ctype_locale_buf, charset); mbc = _ctype_locale_buf + _CTYPE_BUF_SIZE - 2; mbc[0] = mb_cur_max; mbc[1] = '\0'; _ctype_locale.mb_cur_max = mbc; _ctype_using_locale = 1; } ret = 0; #else ret = __part_load_locale(name, &_ctype_using_locale, _ctype_locale_buf, "LC_CTYPE", LCCTYPE_SIZE, LCCTYPE_SIZE, (const char **)&_ctype_locale); if (ret == 0 && _ctype_using_locale) _ctype_locale.grouping = __fix_locale_grouping_str(_ctype_locale.grouping); #endif return ret; }
int __numeric_load_locale(const char *name) { int ret; __nlocale_changed = 1; ret = __part_load_locale(name, &_numeric_using_locale, _numeric_locale_buf, "LC_NUMERIC", LCNUMERIC_SIZE, LCNUMERIC_SIZE, (const char **)&_numeric_locale); if (ret == 0 && _numeric_using_locale) _numeric_locale.grouping = __fix_locale_grouping_str(_numeric_locale.grouping); return ret; }
int __messages_load_locale(const char *name) { int ret; ret = __part_load_locale(name, &_messages_using_locale, &_messages_locale_buf, "LC_MESSAGES", LCMESSAGES_SIZE_FULL, LCMESSAGES_SIZE_MIN, (const char **)&_messages_locale); if (ret == _LDP_LOADED) { if (_messages_locale.yesstr == NULL) _messages_locale.yesstr = empty; if (_messages_locale.nostr == NULL) _messages_locale.nostr = empty; } return (ret); }
int __numeric_load_locale(const char *name) { int ret; ret = __part_load_locale(name, &_numeric_using_locale, &_numeric_locale_buf, "LC_NUMERIC", LCNUMERIC_SIZE, LCNUMERIC_SIZE, (const char **)&_numeric_locale); if (ret != _LDP_ERROR) __nlocale_changed = 1; if (ret == _LDP_LOADED) { /* Can't be empty according to C99 */ if (*_numeric_locale.decimal_point == '\0') _numeric_locale.decimal_point = _C_numeric_locale.decimal_point; _numeric_locale.grouping = __fix_locale_grouping_str(_numeric_locale.grouping); } return (ret); }
int __messages_load_locale (const char *name, void *f_wctomb, const char *charset) { #ifdef __CYGWIN__ extern int __set_lc_messages_from_win (const char *, const struct lc_messages_T *, struct lc_messages_T *, char **, void *, const char *); int ret; int old_messages_using_locale = _messages_using_locale; _messages_using_locale = 0; ret = __set_lc_messages_from_win (name, &_C_messages_locale, &_messages_locale, &_messages_locale_buf, f_wctomb, charset); /* ret == -1: error, ret == 0: C/POSIX, ret > 0: valid */ if (ret < 0) _messages_using_locale = old_messages_using_locale; else { _messages_using_locale = ret; ret = 0; } return ret; #else /* * Propose that we can have incomplete locale file (w/o "{yes,no}str"). * Initialize them before loading. In case of complete locale, they'll * be initialized to loaded value, otherwise they'll not be touched. */ _messages_locale.yesstr = empty; _messages_locale.nostr = empty; return __part_load_locale(name, &_messages_using_locale, _messages_locale_buf, "LC_MESSAGES", LCMESSAGES_SIZE_FULL, LCMESSAGES_SIZE_MIN, (const char **)&_messages_locale); #endif }
struct locdata * __lc_time_load(const char *name) { struct locdata *ldata; struct lc_time *ltime; int ret; if ((ldata = __locdata_alloc(name, sizeof (*ltime))) == NULL) { errno = EINVAL; return (NULL); } ltime = ldata->l_data[0]; ret = __part_load_locale(name, (char **)&ldata->l_data[1], "LC_TIME", LCTIME_SIZE, LCTIME_SIZE, (const char **)ltime); if (ret != _LDP_LOADED) { __locdata_free(ldata); errno = EINVAL; return (NULL); } return (ldata); }
int __numeric_load_locale(const char *name , void *f_wctomb, const char *charset) { int ret; #ifdef __CYGWIN__ extern int __set_lc_numeric_from_win (const char *, const struct lc_numeric_T *, struct lc_numeric_T *, char **, void *, const char *); int old_numeric_using_locale = _numeric_using_locale; _numeric_using_locale = 0; ret = __set_lc_numeric_from_win (name, &_C_numeric_locale, &_numeric_locale, &_numeric_locale_buf, f_wctomb, charset); /* ret == -1: error, ret == 0: C/POSIX, ret > 0: valid */ if (ret < 0) _numeric_using_locale = old_numeric_using_locale; else { _numeric_using_locale = ret; __nlocale_changed = 1; ret = 0; } #else __nlocale_changed = 1; ret = __part_load_locale(name, &_numeric_using_locale, _numeric_locale_buf, "LC_NUMERIC", LCNUMERIC_SIZE, LCNUMERIC_SIZE, (const char **)&_numeric_locale); if (ret == 0 && _numeric_using_locale) _numeric_locale.grouping = __fix_locale_grouping_str(_numeric_locale.grouping); #endif return ret; }
struct locdata * __lc_monetary_load(const char *name) { int ret; int clen; struct lc_monetary *lmon; struct locdata *ldata; if ((ldata = __locdata_alloc(name, sizeof (*lmon))) == NULL) { return (NULL); } lmon = ldata->l_data[0]; ret = __part_load_locale(name, (char **)&ldata->l_data[1], "LC_MONETARY", LCMONETARY_SIZE_FULL, LCMONETARY_SIZE_MIN, (const char **)lmon); if (ret != _LDP_LOADED) { __locdata_free(ldata); errno = EINVAL; return (NULL); } /* special storage for currency string */ clen = strlen(lmon->currency_symbol) + 2; ldata->l_data[2] = libc_malloc(clen); lmon->crncystr = ldata->l_data[2]; lmon->mon_grouping = __fix_locale_grouping_str(lmon->mon_grouping); #define M_ASSIGN_CHAR(NAME) \ (((char *)lmon->NAME)[0] = cnv(lmon->NAME)) M_ASSIGN_CHAR(int_frac_digits); M_ASSIGN_CHAR(frac_digits); M_ASSIGN_CHAR(p_cs_precedes); M_ASSIGN_CHAR(p_sep_by_space); M_ASSIGN_CHAR(n_cs_precedes); M_ASSIGN_CHAR(n_sep_by_space); M_ASSIGN_CHAR(p_sign_posn); M_ASSIGN_CHAR(n_sign_posn); /* * The six additional C99 international monetary formatting * parameters default to the national parameters when * reading FreeBSD LC_MONETARY data files. */ #define M_ASSIGN_ICHAR(NAME) \ if (lmon->int_##NAME == NULL) \ lmon->int_##NAME = lmon->NAME; \ else \ M_ASSIGN_CHAR(int_##NAME); M_ASSIGN_ICHAR(p_cs_precedes); M_ASSIGN_ICHAR(n_cs_precedes); M_ASSIGN_ICHAR(p_sep_by_space); M_ASSIGN_ICHAR(n_sep_by_space); M_ASSIGN_ICHAR(p_sign_posn); M_ASSIGN_ICHAR(n_sign_posn); /* * Now calculate the currency string (CRNCYSTR) for nl_langinfo. * This is a legacy SUSv2 interface. */ if ((lmon->p_cs_precedes[0] == lmon->n_cs_precedes[0]) && (lmon->currency_symbol[0] != '\0')) { char sign = '\0'; switch (lmon->p_cs_precedes[0]) { case 0: sign = '+'; break; case 1: sign = '-'; break; case CHAR_MAX: /* * Substitute currency string for radix character. * To the best of my knowledge, no locale uses this. */ if (strcmp(lmon->mon_decimal_point, lmon->currency_symbol) == 0) sign = '.'; break; } (void) snprintf(lmon->crncystr, clen, "%c%s", sign, lmon->currency_symbol); } return (ldata); }