X-Git-Url: http://nsz.repo.hu/git/?a=blobdiff_plain;f=src%2Flocale%2Ficonv.c;h=1eeea94e0a38753691269b978f105b5e65ee33b8;hb=4cd8b4725907651f329e2f96d428c4e3521643f8;hp=a0b0232015a2be6d4a3f42ea081b1eae1d055c95;hpb=109bd65acf5180f0a48ea4c4e5f2bc6884be202d;p=musl diff --git a/src/locale/iconv.c b/src/locale/iconv.c index a0b02320..1eeea94e 100644 --- a/src/locale/iconv.c +++ b/src/locale/iconv.c @@ -5,6 +5,7 @@ #include #include #include +#include "locale_impl.h" #define UTF_32BE 0300 #define UTF_16LE 0301 @@ -23,19 +24,13 @@ #define BIG5 0340 #define EUC_KR 0350 -/* FIXME: these are not implemented yet - * EUC: A1-FE A1-FE - * GBK: 81-FE 40-7E,80-FE - * Big5: A1-FE 40-7E,A1-FE - */ - /* Definitions of charmaps. Each charmap consists of: * 1. Empty-string-terminated list of null-terminated aliases. * 2. Special type code or number of elided entries. * 3. Character table (size determined by field 2). */ static const unsigned char charmaps[] = -"utf8\0\0\310" +"utf8\0char\0\0\310" "wchart\0\0\306" "ucs2\0ucs2be\0\0\304" "ucs2le\0\0\305" @@ -90,6 +85,7 @@ static int fuzzycmp(const unsigned char *a, const unsigned char *b) static size_t find_charmap(const void *name) { const unsigned char *s; + if (!*(char *)name) name=charmaps; /* "utf8" */ for (s=charmaps; *s; ) { if (!fuzzycmp(name, s)) { for (; *s; s+=strlen((void *)s)+1); @@ -170,9 +166,12 @@ size_t iconv(iconv_t cd0, char **restrict in, size_t *restrict inb, char **restr int err; unsigned char type = map[-1]; unsigned char totype = tomap[-1]; + locale_t *ploc = &CURRENT_LOCALE, loc = *ploc; if (!in || !*in || !*inb) return 0; + *ploc = UTF8_LOCALE; + for (; *inb; *in+=l, *inb-=l) { c = *(unsigned char *)*in; l = 1; @@ -436,6 +435,7 @@ size_t iconv(iconv_t cd0, char **restrict in, size_t *restrict inb, char **restr break; } } + *ploc = loc; return x; ilseq: err = EILSEQ; @@ -450,5 +450,6 @@ starved: x = -1; end: errno = err; + *ploc = loc; return x; }