locale_t newlocale(int mask, const char *name, locale_t src) { struct _locale *dst; char head[_LOCALENAME_LEN_MAX * (_LC_LAST - 1)], *tail; const char *tokens[_LC_LAST - 1]; _locale_set_t l; int i, howmany, categories[_LC_LAST - 1]; if (name == NULL) name = _C_LOCALE; dst = malloc(sizeof(*dst)); if (dst == NULL) return (locale_t)NULL; if (src == NULL) src = _current_locale(); memcpy(dst, src, sizeof(*src)); strlcpy(&head[0], name, sizeof(head)); tokens[0] = (const char *)&head[0]; tail = strchr(tokens[0], '/'); if (tail == NULL) { for (i = 1; i < _LC_LAST; ++i) { if (mask & (1 << i)) { l = _find_category(i); _DIAGASSERT(l != NULL); (*l)(tokens[0], dst); } } } else { *tail++ = '\0'; howmany = 0; for (i = 1; i < _LC_LAST; ++i) { if (mask & (1 << i)) categories[howmany++] = i; } if (howmany-- > 0) { for (i = 1; i < howmany; ++i) { tokens[i] = (const char *)tail; tail = strchr(tokens[i], '/'); if (tail == NULL) { free(dst); return NULL; } } tokens[howmany] = tail; tail = strchr(tokens[howmany], '/'); if (tail != NULL) { free(dst); return NULL; } for (i = 0; i <= howmany; ++i) { l = _find_category(categories[i]); _DIAGASSERT(l != NULL); (*l)(tokens[i], dst); } } } return (locale_t)dst; }
struct lconv * localeconv() { struct _locale_impl_t *impl; impl = *_current_locale(); return &impl->cache.ldata; }
int strerror_r(int num, char *buf, size_t buflen) { #ifdef NLS return _strerror_lr(num, buf, buflen, _current_locale()); #else return _strerror_lr(num, buf, buflen, NULL); #endif }
char * __setlocale(int category, const char *name) { _locale_set_t sl; struct _locale *impl; sl = _find_category(category); if (sl == NULL) return NULL; impl = _current_locale(); return __UNCONST((*sl)(name, impl)); }
int wcsncasecmp(const wchar_t *s1, const wchar_t *s2, size_t n) { return wcsncasecmp_l(s1, s2, n, _current_locale()); }
/* * Compare strings according to LC_COLLATE category of current locale. */ int strcoll(const char *s1, const char *s2) { return strcoll_l(s1, s2, _current_locale()); }
/* * Convert date and time to a wide-character string. * * This is the wide-character counterpart of strftime(). So that we do not * have to duplicate the code of strftime(), we convert the format string to * multibyte, call strftime(), then convert the result back into wide * characters. * * This technique loses in the presence of stateful multibyte encoding if any * of the conversions in the format string change conversion state. When * stateful encoding is implemented, we will need to reset the state between * format specifications in the format string. */ size_t wcsftime(wchar_t *wcs, size_t maxsize, const wchar_t *format, const struct tm *timeptr) { return wcsftime_l(wcs, maxsize, format, timeptr, _current_locale()); }
int wcwidth(wchar_t wc) { return wcwidth_l(wc, _current_locale()); }
int iswctype(wint_t wc, wctype_t charclass) { return iswctype_l(wc, charclass, _current_locale()); }
wctrans_t wctrans(const char *charmap) { return wctrans_l(charmap, _current_locale()); }
wctype_t wctype(const char *charclass) { return wctype_l(charclass, _current_locale()); }
int wcscoll(const wchar_t *s1, const wchar_t *s2) { return wcscoll_l(s1, s2, _current_locale()); }