diff options
author | Bruce Mitchener <bruce.mitchener@gmail.com> | 2013-09-14 15:59:03 +0700 |
---|---|---|
committer | Bruce Mitchener <bruce.mitchener@gmail.com> | 2013-09-26 06:46:48 +0700 |
commit | 7d58080e9354e6e34cb70568ea20cfa410c17cae (patch) | |
tree | 318f5fc83b3477ca1114b1fb1ed7ad0a5036521e /system/lib/libc | |
parent | 690f8c8f80661b0c6f9e731a3ff9da31fecfa7fa (diff) |
Add a lot of locale code.
Diffstat (limited to 'system/lib/libc')
25 files changed, 293 insertions, 0 deletions
diff --git a/system/lib/libc/musl/src/internal/locale_impl.h b/system/lib/libc/musl/src/internal/locale_impl.h new file mode 100644 index 00000000..c268124f --- /dev/null +++ b/system/lib/libc/musl/src/internal/locale_impl.h @@ -0,0 +1,5 @@ +#include <locale.h> + +struct __locale { + int dummy; +}; diff --git a/system/lib/libc/musl/src/locale/iswalnum_l.c b/system/lib/libc/musl/src/locale/iswalnum_l.c new file mode 100644 index 00000000..c888060c --- /dev/null +++ b/system/lib/libc/musl/src/locale/iswalnum_l.c @@ -0,0 +1,6 @@ +#include <wctype.h> + +int iswalnum_l(wint_t c, locale_t l) +{ + return iswalnum(c); +} diff --git a/system/lib/libc/musl/src/locale/iswalpha_l.c b/system/lib/libc/musl/src/locale/iswalpha_l.c new file mode 100644 index 00000000..cd2be91e --- /dev/null +++ b/system/lib/libc/musl/src/locale/iswalpha_l.c @@ -0,0 +1,6 @@ +#include <wctype.h> + +int iswalpha_l(wint_t c, locale_t l) +{ + return iswalpha(c); +} diff --git a/system/lib/libc/musl/src/locale/iswblank_l.c b/system/lib/libc/musl/src/locale/iswblank_l.c new file mode 100644 index 00000000..f3a2691f --- /dev/null +++ b/system/lib/libc/musl/src/locale/iswblank_l.c @@ -0,0 +1,6 @@ +#include <wctype.h> + +int iswblank_l(wint_t c, locale_t l) +{ + return iswblank(c); +} diff --git a/system/lib/libc/musl/src/locale/iswcntrl_l.c b/system/lib/libc/musl/src/locale/iswcntrl_l.c new file mode 100644 index 00000000..7681fe09 --- /dev/null +++ b/system/lib/libc/musl/src/locale/iswcntrl_l.c @@ -0,0 +1,6 @@ +#include <wctype.h> + +int iswcntrl_l(wint_t c, locale_t l) +{ + return iswcntrl(c); +} diff --git a/system/lib/libc/musl/src/locale/iswctype_l.c b/system/lib/libc/musl/src/locale/iswctype_l.c new file mode 100644 index 00000000..13dfb1ed --- /dev/null +++ b/system/lib/libc/musl/src/locale/iswctype_l.c @@ -0,0 +1,9 @@ +#include <wctype.h> +#include "libc.h" + +int iswctype_l(wint_t c, wctype_t t, locale_t l) +{ + return iswctype(c, t); +} + +weak_alias(iswctype_l, __iswctype_l); diff --git a/system/lib/libc/musl/src/locale/iswdigit_l.c b/system/lib/libc/musl/src/locale/iswdigit_l.c new file mode 100644 index 00000000..3de678c2 --- /dev/null +++ b/system/lib/libc/musl/src/locale/iswdigit_l.c @@ -0,0 +1,6 @@ +#include <wctype.h> + +int iswdigit_l(wint_t c, locale_t l) +{ + return iswdigit(c); +} diff --git a/system/lib/libc/musl/src/locale/iswgraph_l.c b/system/lib/libc/musl/src/locale/iswgraph_l.c new file mode 100644 index 00000000..34df64fc --- /dev/null +++ b/system/lib/libc/musl/src/locale/iswgraph_l.c @@ -0,0 +1,6 @@ +#include <wctype.h> + +int iswgraph_l(wint_t c, locale_t l) +{ + return iswgraph(c); +} diff --git a/system/lib/libc/musl/src/locale/iswlower_l.c b/system/lib/libc/musl/src/locale/iswlower_l.c new file mode 100644 index 00000000..c52421a0 --- /dev/null +++ b/system/lib/libc/musl/src/locale/iswlower_l.c @@ -0,0 +1,6 @@ +#include <wctype.h> + +int iswlower_l(wint_t c, locale_t l) +{ + return iswlower(c); +} diff --git a/system/lib/libc/musl/src/locale/iswprint_l.c b/system/lib/libc/musl/src/locale/iswprint_l.c new file mode 100644 index 00000000..73d83ab3 --- /dev/null +++ b/system/lib/libc/musl/src/locale/iswprint_l.c @@ -0,0 +1,6 @@ +#include <wctype.h> + +int iswprint_l(wint_t c, locale_t l) +{ + return iswprint(c); +} diff --git a/system/lib/libc/musl/src/locale/iswpunct_l.c b/system/lib/libc/musl/src/locale/iswpunct_l.c new file mode 100644 index 00000000..831e0e54 --- /dev/null +++ b/system/lib/libc/musl/src/locale/iswpunct_l.c @@ -0,0 +1,6 @@ +#include <wctype.h> + +int iswpunct_l(wint_t c, locale_t l) +{ + return iswpunct(c); +} diff --git a/system/lib/libc/musl/src/locale/iswspace_l.c b/system/lib/libc/musl/src/locale/iswspace_l.c new file mode 100644 index 00000000..b507e9e3 --- /dev/null +++ b/system/lib/libc/musl/src/locale/iswspace_l.c @@ -0,0 +1,6 @@ +#include <wctype.h> + +int iswspace_l(wint_t c, locale_t l) +{ + return iswspace(c); +} diff --git a/system/lib/libc/musl/src/locale/iswupper_l.c b/system/lib/libc/musl/src/locale/iswupper_l.c new file mode 100644 index 00000000..fc988ef1 --- /dev/null +++ b/system/lib/libc/musl/src/locale/iswupper_l.c @@ -0,0 +1,6 @@ +#include <wctype.h> + +int iswupper_l(wint_t c, locale_t l) +{ + return iswupper(c); +} diff --git a/system/lib/libc/musl/src/locale/iswxdigit_l.c b/system/lib/libc/musl/src/locale/iswxdigit_l.c new file mode 100644 index 00000000..9527cf3e --- /dev/null +++ b/system/lib/libc/musl/src/locale/iswxdigit_l.c @@ -0,0 +1,6 @@ +#include <wctype.h> + +int iswxdigit_l(wint_t c, locale_t l) +{ + return iswxdigit(c); +} diff --git a/system/lib/libc/musl/src/locale/strfmon.c b/system/lib/libc/musl/src/locale/strfmon.c new file mode 100644 index 00000000..f510d9a4 --- /dev/null +++ b/system/lib/libc/musl/src/locale/strfmon.c @@ -0,0 +1,101 @@ +#include <stdio.h> +#include <ctype.h> +#include <stdarg.h> +#include <monetary.h> +#include <errno.h> +#include <stdarg.h> + +static ssize_t vstrfmon_l(char *s, size_t n, locale_t loc, const char *fmt, va_list ap) +{ + size_t l; + double x; + int fill, nogrp, negpar, nosym, left, intl; + int lp, rp, w, fw; + char *s0=s; + for (; n && *fmt; ) { + if (*fmt != '%') { + literal: + *s++ = *fmt++; + n--; + continue; + } + fmt++; + if (*fmt == '%') goto literal; + + fill = ' '; + nogrp = 0; + negpar = 0; + nosym = 0; + left = 0; + for (; ; fmt++) { + switch (*fmt) { + case '=': + fill = *++fmt; + continue; + case '^': + nogrp = 1; + continue; + case '(': + negpar = 1; + case '+': + continue; + case '!': + nosym = 1; + continue; + case '-': + left = 1; + continue; + } + break; + } + + for (fw=0; isdigit(*fmt); fmt++) + fw = 10*fw + (*fmt-'0'); + lp = 0; + rp = 2; + if (*fmt=='#') for (lp=0, fmt++; isdigit(*fmt); fmt++) + lp = 10*lp + (*fmt-'0'); + if (*fmt=='.') for (rp=0, fmt++; isdigit(*fmt); fmt++) + rp = 10*rp + (*fmt-'0'); + + intl = *fmt++ == 'i'; + + w = lp + 1 + rp; + if (!left && fw>w) w = fw; + + x = va_arg(ap, double); + l = snprintf(s, n, "%*.*f", w, rp, x); + if (l >= n) { + errno = E2BIG; + return -1; + } + s += l; + n -= l; + } + return s-s0; +} + +ssize_t strfmon_l(char *restrict s, size_t n, locale_t loc, const char *restrict fmt, ...) +{ + va_list ap; + ssize_t ret; + + va_start(ap, fmt); + ret = vstrfmon_l(s, n, loc, fmt, ap); + va_end(ap); + + return ret; +} + + +ssize_t strfmon(char *restrict s, size_t n, const char *restrict fmt, ...) +{ + va_list ap; + ssize_t ret; + + va_start(ap, fmt); + ret = vstrfmon_l(s, n, 0, fmt, ap); + va_end(ap); + + return ret; +} diff --git a/system/lib/libc/musl/src/locale/strxfrm.c b/system/lib/libc/musl/src/locale/strxfrm.c new file mode 100644 index 00000000..32c46193 --- /dev/null +++ b/system/lib/libc/musl/src/locale/strxfrm.c @@ -0,0 +1,18 @@ +#include <string.h> +#include <locale.h> +#include "libc.h" + +/* collate only by code points */ +size_t __strxfrm_l(char *restrict dest, const char *restrict src, size_t n, locale_t loc) +{ + size_t l = strlen(src); + if (n > l) strcpy(dest, src); + return l; +} + +size_t strxfrm(char *restrict dest, const char *restrict src, size_t n) +{ + return __strxfrm_l(dest, src, n, 0); +} + +weak_alias(__strxfrm_l, strxfrm_l); diff --git a/system/lib/libc/musl/src/locale/towctrans_l.c b/system/lib/libc/musl/src/locale/towctrans_l.c new file mode 100644 index 00000000..6222058c --- /dev/null +++ b/system/lib/libc/musl/src/locale/towctrans_l.c @@ -0,0 +1,6 @@ +#include <wctype.h> + +wint_t towctrans_l(wint_t c, wctrans_t t, locale_t l) +{ + return towctrans(c, t); +} diff --git a/system/lib/libc/musl/src/locale/towlower_l.c b/system/lib/libc/musl/src/locale/towlower_l.c new file mode 100644 index 00000000..aaaea370 --- /dev/null +++ b/system/lib/libc/musl/src/locale/towlower_l.c @@ -0,0 +1,9 @@ +#include <wctype.h> +#include "libc.h" + +wint_t towlower_l(wint_t c, locale_t l) +{ + return towlower(c); +} + +weak_alias(towlower_l, __towlower_l); diff --git a/system/lib/libc/musl/src/locale/towupper_l.c b/system/lib/libc/musl/src/locale/towupper_l.c new file mode 100644 index 00000000..ad02a4be --- /dev/null +++ b/system/lib/libc/musl/src/locale/towupper_l.c @@ -0,0 +1,9 @@ +#include <wctype.h> +#include "libc.h" + +wint_t towupper_l(wint_t c, locale_t l) +{ + return towupper(c); +} + +weak_alias(towupper_l, __towupper_l); diff --git a/system/lib/libc/musl/src/locale/wcscoll.c b/system/lib/libc/musl/src/locale/wcscoll.c new file mode 100644 index 00000000..20a60900 --- /dev/null +++ b/system/lib/libc/musl/src/locale/wcscoll.c @@ -0,0 +1,16 @@ +#include <wchar.h> +#include <locale.h> +#include "libc.h" + +/* FIXME: stub */ +int __wcscoll_l(const wchar_t *l, const wchar_t *r, locale_t locale) +{ + return wcscmp(l, r); +} + +int wcscoll(const wchar_t *l, const wchar_t *r) +{ + return __wcscoll_l(l, r, 0); +} + +weak_alias(__wcscoll_l, wcscoll_l); diff --git a/system/lib/libc/musl/src/locale/wcscoll_l.c b/system/lib/libc/musl/src/locale/wcscoll_l.c new file mode 100644 index 00000000..f257ec8d --- /dev/null +++ b/system/lib/libc/musl/src/locale/wcscoll_l.c @@ -0,0 +1,6 @@ +#include <wchar.h> + +int wcscoll_l(const wchar_t *l, const wchar_t *r, locale_t locale) +{ + return wcscoll(l, r); +} diff --git a/system/lib/libc/musl/src/locale/wcsxfrm.c b/system/lib/libc/musl/src/locale/wcsxfrm.c new file mode 100644 index 00000000..cb79c97e --- /dev/null +++ b/system/lib/libc/musl/src/locale/wcsxfrm.c @@ -0,0 +1,21 @@ +#include <wchar.h> +#include <locale.h> +#include "libc.h" + +/* collate only by code points */ +size_t __wcsxfrm_l(wchar_t *restrict dest, const wchar_t *restrict src, size_t n, locale_t loc) +{ + size_t l = wcslen(src); + if (l >= n) { + wmemcpy(dest, src, n-1); + dest[n-1] = 0; + } else wcscpy(dest, src); + return l; +} + +size_t wcsxfrm(wchar_t *restrict dest, const wchar_t *restrict src, size_t n) +{ + return __wcsxfrm_l(dest, src, n, 0); +} + +weak_alias(__wcsxfrm_l, wcsxfrm_l); diff --git a/system/lib/libc/musl/src/locale/wcsxfrm_l.c b/system/lib/libc/musl/src/locale/wcsxfrm_l.c new file mode 100644 index 00000000..66a00193 --- /dev/null +++ b/system/lib/libc/musl/src/locale/wcsxfrm_l.c @@ -0,0 +1,6 @@ +#include <wchar.h> + +size_t wcsxfrm_l(wchar_t *restrict dest, const wchar_t *restrict src, size_t n, locale_t locale) +{ + return wcsxfrm(dest, src, n); +} diff --git a/system/lib/libc/musl/src/locale/wctrans_l.c b/system/lib/libc/musl/src/locale/wctrans_l.c new file mode 100644 index 00000000..dae3381e --- /dev/null +++ b/system/lib/libc/musl/src/locale/wctrans_l.c @@ -0,0 +1,6 @@ +#include <wctype.h> + +wctrans_t wctrans_l(const char *s, locale_t l) +{ + return wctrans(s); +} diff --git a/system/lib/libc/musl/src/locale/wctype_l.c b/system/lib/libc/musl/src/locale/wctype_l.c new file mode 100644 index 00000000..601bab37 --- /dev/null +++ b/system/lib/libc/musl/src/locale/wctype_l.c @@ -0,0 +1,9 @@ +#include <wctype.h> +#include "libc.h" + +wctype_t wctype_l(const char *s, locale_t l) +{ + return wctype(s); +} + +weak_alias(wctype_l, __wctype_l); |