diff options
author | Jelmer Vernooij <jelmer@samba.org> | 2009-03-02 04:12:57 +0100 |
---|---|---|
committer | Jelmer Vernooij <jelmer@samba.org> | 2009-03-02 04:12:57 +0100 |
commit | c7b9757b8ac3ac6baa478655a4d2f77dff8240a8 (patch) | |
tree | ccdbd06a49613d9d8cafd26ea95a829868cf2e0d /lib | |
parent | 9940c7690e2c1b225111d5d8e09cc735ebe296dd (diff) | |
download | samba-c7b9757b8ac3ac6baa478655a4d2f77dff8240a8.tar.gz samba-c7b9757b8ac3ac6baa478655a4d2f77dff8240a8.tar.bz2 samba-c7b9757b8ac3ac6baa478655a4d2f77dff8240a8.zip |
Import ISO-8859-1, 646 from Samba 3 iconv.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/util/charset/iconv.c | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/lib/util/charset/iconv.c b/lib/util/charset/iconv.c index 98284ce9bd..9825e4be01 100644 --- a/lib/util/charset/iconv.c +++ b/lib/util/charset/iconv.c @@ -50,6 +50,7 @@ static size_t ascii_pull (void *,const char **, size_t *, char **, size_t *); static size_t ascii_push (void *,const char **, size_t *, char **, size_t *); +static size_t latin1_push (void *,const char **, size_t *, char **, size_t *); static size_t utf8_pull (void *,const char **, size_t *, char **, size_t *); static size_t utf8_push (void *,const char **, size_t *, char **, size_t *); static size_t utf16_munged_pull(void *,const char **, size_t *, char **, size_t *); @@ -73,6 +74,8 @@ static const struct charset_functions builtin_functions[] = { {"UTF16_MUNGED", utf16_munged_pull, iconv_copy}, {"ASCII", ascii_pull, ascii_push}, + {"646", ascii_pull, ascii_push}, + {"ISO-8859-1", ascii_pull, latin1_push}, {"UCS2-HEX", ucs2hex_pull, ucs2hex_push} }; @@ -341,6 +344,32 @@ static size_t ascii_push(void *cd, const char **inbuf, size_t *inbytesleft, return ir_count; } +static size_t latin1_push(void *cd, const char **inbuf, size_t *inbytesleft, + char **outbuf, size_t *outbytesleft) +{ + int ir_count=0; + + while (*inbytesleft >= 2 && *outbytesleft >= 1) { + (*outbuf)[0] = (*inbuf)[0]; + if ((*inbuf)[1]) ir_count++; + (*inbytesleft) -= 2; + (*outbytesleft) -= 1; + (*inbuf) += 2; + (*outbuf) += 1; + } + + if (*inbytesleft == 1) { + errno = EINVAL; + return -1; + } + + if (*inbytesleft > 1) { + errno = E2BIG; + return -1; + } + + return ir_count; +} static size_t ucs2hex_pull(void *cd, const char **inbuf, size_t *inbytesleft, char **outbuf, size_t *outbytesleft) |